[shotwell/wip/gtk4: 2/2] Fix tool drawing and cursors




commit 99698f33c7cc6bd582aec3cd6bca92bde8d9f8f2
Author: Jens Georg <mail jensge org>
Date:   Mon Apr 18 11:35:55 2022 +0200

    Fix tool drawing and cursors

 src/Page.vala                                  |  8 ++--
 src/PageWindow.vala                            |  4 +-
 src/PhotoPage.vala                             | 58 ++++++++------------------
 src/SinglePhotoPage.vala                       |  1 +
 src/editing_tools/CropTool.vala                |  4 +-
 src/editing_tools/PhotoCanvas.vala             |  4 +-
 src/editing_tools/RGBHistogramManipulator.vala |  1 -
 src/editing_tools/RedeyeTool.vala              |  2 +-
 src/editing_tools/StraightenTool.vala          |  6 +--
 9 files changed, 32 insertions(+), 56 deletions(-)
---
diff --git a/src/Page.vala b/src/Page.vala
index ab7aacd6..9c292699 100644
--- a/src/Page.vala
+++ b/src/Page.vala
@@ -79,7 +79,7 @@ public abstract class Page : Gtk.Box {
     private bool alt_pressed = false;
     private bool shift_pressed = false;
     private bool super_pressed = false;
-    private string last_cursor = "default";
+    private string? last_cursor = null;
     private bool cursor_hidden = false;
     private int cursor_hide_msec = 0;
     private uint last_timeout_id = 0;
@@ -1155,11 +1155,11 @@ public abstract class Page : Gtk.Box {
     }
 
     // Use this method to set the cursor for a page, NOT window.set_cursor(...)
-    protected virtual void set_page_cursor(string cursor_type) {
+    protected virtual void set_page_cursor(string? cursor_type) {
         last_cursor = cursor_type;
 
         if (!cursor_hidden && event_source != null) {
-            event_source.set_cursor (new Gdk.Cursor.from_name (cursor_type, null));
+            event_source.set_cursor_from_name (cursor_type);
         }
     }
 
@@ -1180,7 +1180,7 @@ public abstract class Page : Gtk.Box {
         cursor_hidden = true;
 
         if (event_source != null) {
-            event_source.set_cursor (new Gdk.Cursor.from_name ("none", null));
+            event_source.set_cursor_from_name ("none");
         }
 
         // We remove the timeout so reset the id
diff --git a/src/PageWindow.vala b/src/PageWindow.vala
index 1e69051a..2c587f88 100644
--- a/src/PageWindow.vala
+++ b/src/PageWindow.vala
@@ -119,7 +119,7 @@ public abstract class PageWindow : Gtk.ApplicationWindow {
         if (busy_counter++ > 0)
             return;
 
-        set_cursor(new Gdk.Cursor.from_name("wait", null));
+        set_cursor_from_name("wait");
     }
 
     public void set_normal_cursor() {
@@ -130,6 +130,6 @@ public abstract class PageWindow : Gtk.ApplicationWindow {
             return;
         }
 
-        set_cursor(new Gdk.Cursor.from_name("default", null));
+        set_cursor_from_name("default");
     }
 }
diff --git a/src/PhotoPage.vala b/src/PhotoPage.vala
index 1f3697d7..bdeeb86c 100644
--- a/src/PhotoPage.vala
+++ b/src/PhotoPage.vala
@@ -382,7 +382,7 @@ public abstract class EditingHostPage : SinglePhotoPage {
             this.host_page = host_page;
         }
         
-        public override  void repaint() {
+        public override void repaint() {
             host_page.repaint();
         }
     }
@@ -968,7 +968,6 @@ public abstract class EditingHostPage : SinglePhotoPage {
             // if no tool, use the pixbuf directly, otherwise, let the tool decide what should be
             // displayed
             Dimensions max_dim = photo.get_dimensions();
-            #if 0
             if (current_tool != null) {
                 try {
                     Dimensions tool_pixbuf_dim;
@@ -986,7 +985,6 @@ public abstract class EditingHostPage : SinglePhotoPage {
                     return;
                 }
             }
-            #endif
             
             set_pixbuf(pixbuf, max_dim);
             pixbuf_dirty = false;
@@ -1239,7 +1237,7 @@ public abstract class EditingHostPage : SinglePhotoPage {
         // was possible; the null guards are required because zoom can be cancelled at
         // any time
         if (canvas != null /*&& canvas.get_window() != null*/)
-            set_page_cursor("default");
+            set_page_cursor(null);
         
         repaint();
     }
@@ -1286,8 +1284,8 @@ public abstract class EditingHostPage : SinglePhotoPage {
         
         try {
             Dimensions tool_pixbuf_dim = {0};
-            //if (current_tool != null)
-            //    pixbuf = current_tool.get_display_pixbuf(get_canvas_scaling(), photo, out tool_pixbuf_dim);
+            if (current_tool != null)
+                pixbuf = current_tool.get_display_pixbuf(get_canvas_scaling(), photo, out tool_pixbuf_dim);
                 
             if (pixbuf != null)
                 max_dim = tool_pixbuf_dim;                
@@ -1554,18 +1552,13 @@ public abstract class EditingHostPage : SinglePhotoPage {
     // Return true to block the DnD handler from activating a drag
     protected override bool on_left_click(Gtk.EventController event, int press, double x, double y) {
         // report double-click if no tool is active, otherwise all double-clicks are eaten
-        #if 0
-        if (event.type == Gdk.EventType.2BUTTON_PRESS)
-            return (current_tool == null) ? on_double_click(event) : false;
-        #else
-            if (press == 2) {
-                on_double_click (event, x, y);
-            }
-        #endif
-        
+        if (press == 2) {
+            return (current_tool == null) ? on_double_click (event, x, y) : false;
+        }
+
         // if no editing tool, then determine whether we should start a pan operation over the
         // zoomed photo or fall through to the default DnD behavior if we're not zoomed
-        if (/*(current_tool == null) && */(zoom_slider.get_value() != 0.0)) {
+        if ((current_tool == null) && (zoom_slider.get_value() != 0.0)) {
             zoom_pan_start_point.x = (int) x;
             zoom_pan_start_point.y = (int) y;
             is_pan_in_progress = true;
@@ -1574,7 +1567,6 @@ public abstract class EditingHostPage : SinglePhotoPage {
             return true;
         }
 
-#if 0
         // default behavior when photo isn't zoomed -- return false to start DnD operation
         if (current_tool == null) {
             return false;
@@ -1582,16 +1574,13 @@ public abstract class EditingHostPage : SinglePhotoPage {
 
         // only concerned about mouse-downs on the pixbuf ... return true prevents DnD when the
         // user drags outside the displayed photo
-        if (!is_inside_pixbuf(x, y))
+        if (!is_inside_pixbuf((int)x, (int)y))
             return true;
 
-        current_tool.on_left_click(x, y);
+        current_tool.on_left_click((int)x, (int)y);
         
         // block DnD handlers if tool is enabled
         return true;
-#else
-        return false;
-#endif
     }
     
     protected override bool on_left_released(Gtk.EventController event, int press, double x, double y) {
@@ -1610,17 +1599,15 @@ public abstract class EditingHostPage : SinglePhotoPage {
             restore_cursor_hiding();
         }
 
-#if 0
         // report all releases, as it's possible the user click and dragged from inside the
         // pixbuf to the gutters
         if (current_tool == null)
             return false;
         
-        current_tool.on_left_released((int) event.x, (int) event.y);
+        current_tool.on_left_released((int) x, (int) y);
 
         if (current_tool.get_tool_window() != null)
             current_tool.get_tool_window().present();
-#endif
         
         return false;
     }
@@ -1675,21 +1662,16 @@ public abstract class EditingHostPage : SinglePhotoPage {
         if (is_panning_possible())
             set_page_cursor("move");
         else
-            set_page_cursor("default");
+            set_page_cursor(null);
     }
     
     // Return true to block the DnD handler from activating a drag
     protected override bool on_motion(Gtk.EventControllerMotion event, double x, double y, Gdk.ModifierType 
mask) {
-        #if 0
         if (current_tool != null) {
-            current_tool.on_motion(x, y, mask);
-
-            // this requests more events after "hints"
-            Gdk.Event.request_motions(event);
+            current_tool.on_motion((int)x, (int)y, mask);
 
             return true;
         }
-        #endif
         
         update_cursor_for_zoom_context();
         
@@ -1711,10 +1693,8 @@ public abstract class EditingHostPage : SinglePhotoPage {
     }
     
     protected override void on_leave_notify_event(Gtk.EventControllerMotion event) {
-        #if 0
         if (current_tool != null)
-            return current_tool.on_leave_notify_event();
-            #endif
+            current_tool.on_leave_notify_event();
         
         base.on_leave_notify_event(event);
     }
@@ -1816,20 +1796,18 @@ public abstract class EditingHostPage : SinglePhotoPage {
     
     protected override void new_surface(Cairo.Context default_ctx, Dimensions dim) {
         // if tool is open, update its canvas object
-        //if (current_tool != null)
-        //    current_tool.canvas.set_surface(default_ctx, dim);
+        if (current_tool != null)
+            current_tool.canvas.set_surface(default_ctx, dim);
     }
     
     protected override void updated_pixbuf(Gdk.Pixbuf pixbuf, SinglePhotoPage.UpdateReason reason, 
         Dimensions old_dim) {
         // only purpose here is to inform editing tool of change and drop the cancelled
         // pixbuf, which is now sized incorrectly
-        #if 0
         if (current_tool != null && reason != SinglePhotoPage.UpdateReason.QUALITY_IMPROVEMENT) {
             current_tool.canvas.resized_pixbuf(old_dim, pixbuf, get_scaled_pixbuf_position());
             cancel_editing_pixbuf = null;
         }
-        #endif
     }
     
     protected virtual Gdk.Pixbuf? get_bottom_left_trinket(int scale) {
@@ -2344,7 +2322,7 @@ public abstract class EditingHostPage : SinglePhotoPage {
     }
 
     public bool has_current_tool() {
-        return false; //(current_tool != null);
+        return (current_tool != null);
     }
     
     protected void unset_view_collection() {
diff --git a/src/SinglePhotoPage.vala b/src/SinglePhotoPage.vala
index d2cb072c..798879bc 100644
--- a/src/SinglePhotoPage.vala
+++ b/src/SinglePhotoPage.vala
@@ -57,6 +57,7 @@ public abstract class SinglePhotoPage : Page {
 
         canvas.resize.connect(on_viewport_resize);
         canvas.set_draw_func(on_canvas_exposed);
+        canvas.set_name ("SinglePhoto drawing");
         set_event_source(canvas);
         Config.Facade.get_instance().colors_changed.connect(on_colors_changed);
     }
diff --git a/src/editing_tools/CropTool.vala b/src/editing_tools/CropTool.vala
index 1d5b2c34..80cd8440 100644
--- a/src/editing_tools/CropTool.vala
+++ b/src/editing_tools/CropTool.vala
@@ -661,7 +661,7 @@ public class EditingTools.CropTool : EditingTool {
 
         // make sure the cursor isn't set to a modify indicator
         if (canvas != null) {
-            canvas.set_cursor ("default");
+            canvas.set_cursor (null);
         }
 
         crop_surface = null;
@@ -812,7 +812,7 @@ public class EditingTools.CropTool : EditingTool {
         Gdk.Rectangle scaled_pos = canvas.get_scaled_pixbuf_position();
         Box offset_scaled_crop = scaled_crop.get_offset(scaled_pos.x, scaled_pos.y);
 
-        string cursor_type = "default";
+        string? cursor_type = null;
         switch (offset_scaled_crop.approx_location(x, y)) {
             case BoxLocation.LEFT_SIDE:
                 cursor_type = "w-resize";
diff --git a/src/editing_tools/PhotoCanvas.vala b/src/editing_tools/PhotoCanvas.vala
index 43318b20..be34f289 100644
--- a/src/editing_tools/PhotoCanvas.vala
+++ b/src/editing_tools/PhotoCanvas.vala
@@ -335,8 +335,8 @@ public abstract class EditingTools.PhotoCanvas {
         //drawing_window.invalidate_rect(rect, false);
     }
 
-    public void set_cursor(string cursor_type) {
-        get_drawing_window().set_cursor(new Gdk.Cursor.from_name(cursor_type, null));
+    public void set_cursor(string? cursor_type) {
+        get_container().set_cursor_from_name(cursor_type);
     }
 
     private Cairo.Surface pixbuf_to_surface(Cairo.Context default_ctx, Gdk.Pixbuf pixbuf,
diff --git a/src/editing_tools/RGBHistogramManipulator.vala b/src/editing_tools/RGBHistogramManipulator.vala
index dc82475e..ccfdb479 100644
--- a/src/editing_tools/RGBHistogramManipulator.vala
+++ b/src/editing_tools/RGBHistogramManipulator.vala
@@ -171,7 +171,6 @@ public class RGBHistogramManipulator : Gtk.DrawingArea {
     }
 
     public bool on_key_pressed(Gtk.EventControllerKey event, uint keyval, uint keycode, Gdk.ModifierType 
modifiers) {
-
         int delta = 0;
 
         if (keyval == Gdk.Key.Left || keyval == Gdk.Key.Up) {
diff --git a/src/editing_tools/RedeyeTool.vala b/src/editing_tools/RedeyeTool.vala
index 1b8c60b2..b1394e1e 100644
--- a/src/editing_tools/RedeyeTool.vala
+++ b/src/editing_tools/RedeyeTool.vala
@@ -346,7 +346,7 @@ public class EditingTools.RedeyeTool : EditingTool {
             if (coord_in_rectangle(x, y, bounds)) {
                 canvas.set_cursor("move");
             } else {
-                canvas.set_cursor("default");
+                canvas.set_cursor(null);
             }
         }
     }
diff --git a/src/editing_tools/StraightenTool.vala b/src/editing_tools/StraightenTool.vala
index 6d3cc2e3..abf69970 100644
--- a/src/editing_tools/StraightenTool.vala
+++ b/src/editing_tools/StraightenTool.vala
@@ -358,9 +358,7 @@ public class StraightenTool : EditingTool {
         prepare_image();
 
         // set crosshair cursor
-        var drawing_window = canvas.get_drawing_window ();
-        var cursor = new Gdk.Cursor.from_name ("crosshair", null);
-        drawing_window.set_cursor (cursor);
+        canvas.set_cursor("crosshair");
 
         window = new StraightenToolWindow(canvas.get_container());
         bind_window_handlers();
@@ -390,7 +388,7 @@ public class StraightenTool : EditingTool {
 
         if (canvas != null) {
             unbind_canvas_handlers(canvas);
-            canvas.get_drawing_window().set_cursor(null);
+            canvas.get_container().set_cursor(null);
         }
 
         base.deactivate();


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]