[shotwell/wip/gtk4: 17/88] Drag selection works, kind of




commit faf265f08522a1cea2ef329ef7e494a27b6beab8
Author: Jens Georg <mail jensge org>
Date:   Sun Apr 3 23:20:39 2022 +0200

    Drag selection works, kind of
    
    Rubberband does not seem to be drawn correctly, its all black

 src/CheckerboardLayout.vala |  6 ------
 src/CheckerboardPage.vala   | 10 +++++-----
 src/Page.vala               | 36 +++++++++++++++++-------------------
 3 files changed, 22 insertions(+), 30 deletions(-)
---
diff --git a/src/CheckerboardLayout.vala b/src/CheckerboardLayout.vala
index 4d9a9e25..744319ab 100644
--- a/src/CheckerboardLayout.vala
+++ b/src/CheckerboardLayout.vala
@@ -618,14 +618,8 @@ public class CheckerboardLayout : Gtk.DrawingArea {
         selection_band = Box.from_points(drag_origin, drag_endpoint).get_rectangle();
         
         // force repaint of the union of the old and new, which covers the band reducing in size
-        #if 0
-        if (get_window() != null) {
             Gdk.Rectangle union;
             selection_band.union(old_selection_band, out union);
-            
-            queue_draw_area(union.x, union.y, union.width, union.height);
-        }
-        #endif
         queue_draw();
     }
     
diff --git a/src/CheckerboardPage.vala b/src/CheckerboardPage.vala
index 15893ef4..a1750580 100644
--- a/src/CheckerboardPage.vala
+++ b/src/CheckerboardPage.vala
@@ -517,6 +517,7 @@ public abstract class CheckerboardPage : Page {
         Gtk.Menu context_menu = get_context_menu();
         return popup_context_menu(context_menu, event);
     }
+    #endif
 
     protected virtual bool on_mouse_over(CheckerboardItem? item, int x, int y, Gdk.ModifierType mask) {
         if (item != null)
@@ -544,9 +545,9 @@ public abstract class CheckerboardPage : Page {
         return true;
     }
 
-    protected override bool on_motion(Gdk.EventMotion event, int x, int y, Gdk.ModifierType mask) {
+    protected override bool on_motion(Gtk.EventControllerMotion event, double x, double y, Gdk.ModifierType 
mask) {
         // report what item the mouse is hovering over
-        if (!on_mouse_over(get_item_at_pixel(x, y), x, y, mask))
+        if (!on_mouse_over(get_item_at_pixel(x, y), (int)x, (int)y, mask))
             return false;
 
         // go no further if not drag-selecting
@@ -554,13 +555,13 @@ public abstract class CheckerboardPage : Page {
             return false;
 
         // set the new endpoint of the drag selection
-        layout.set_drag_select_endpoint(x, y);
+        layout.set_drag_select_endpoint((int)x, (int)y);
 
         updated_selection_band();
 
         // if out of bounds, schedule a check to auto-scroll the viewport
         if (!autoscroll_scheduled 
-            && get_adjustment_relation(get_vadjustment(), y) != AdjustmentRelation.IN_RANGE) {
+            && get_adjustment_relation(scrolled.get_vadjustment(), (int)y) != AdjustmentRelation.IN_RANGE) {
             Timeout.add(AUTOSCROLL_TICKS_MSEC, selection_autoscroll);
             autoscroll_scheduled = true;
         }
@@ -568,7 +569,6 @@ public abstract class CheckerboardPage : Page {
         // return true to stop a potential drag-and-drop operation
         return true;
     }
-    #endif
 
     private void updated_selection_band() {
         assert(layout.is_drag_select_active());
diff --git a/src/Page.vala b/src/Page.vala
index dbaf42a4..e781b08e 100644
--- a/src/Page.vala
+++ b/src/Page.vala
@@ -89,6 +89,7 @@ public abstract class Page : Gtk.Box {
 
     // Event controllers
     private Gtk.GestureClick clicks;
+    private Gtk.EventControllerMotion motion;
     
     protected Page(string page_name) {
         Object (orientation: Gtk.Orientation.HORIZONTAL);
@@ -186,6 +187,12 @@ public abstract class Page : Gtk.Box {
         clicks.set_exclusive (true); // TODO: Need to be true or false?
         event_source.add_controller (clicks);
 
+        motion = new Gtk.EventControllerMotion ();
+        motion.set_name ("CheckerboardPage motion source");
+        motion.motion.connect(on_motion_internal);
+        motion.leave.connect(on_leave_notify_event);
+        event_source.add_controller (motion);
+
         clicks.pressed.connect (on_button_pressed_internal);
         clicks.released.connect (on_button_released_internal);
 
@@ -210,6 +217,8 @@ public abstract class Page : Gtk.Box {
 
         event_source.remove_controller (clicks);
         clicks = null;
+        event_source.remove_controller (motion);
+        motion = null;
         
     #if 0
         event_source.button_press_event.disconnect(on_button_pressed_internal);
@@ -1006,33 +1015,22 @@ public abstract class Page : Gtk.Box {
         return false;
     }
     
-    #if 0
-    protected virtual bool on_motion(Gdk.EventMotion event, int x, int y, Gdk.ModifierType mask) {
+    protected virtual bool on_motion(Gtk.EventControllerMotion event, double x, double y, Gdk.ModifierType 
mask) {
         check_cursor_hiding();
 
         return false;
     }
-    #endif
     
-    protected virtual bool on_leave_notify_event() {
-        return false;
+    protected virtual void on_leave_notify_event(Gtk.EventControllerMotion controller) {
+        // Do nothing
     }
-    
-    #if 0
-    private bool on_motion_internal(Gdk.EventMotion event) {
-        int x, y;
-        Gdk.ModifierType mask;
-        if (event.is_hint == 1) {
-            get_event_source_pointer(out x, out y, out mask);
-        } else {
-            x = (int) event.x;
-            y = (int) event.y;
-            mask = event.state;
-        }
-        
-        return on_motion(event, x, y, mask);
+
+    private void on_motion_internal(Gtk.EventControllerMotion controller, double x, double y) {
+        bool result = on_motion(controller, x, y, controller.get_current_event_state());
+        // todo: stop propagation?
     }
 
+    #if 0
     private bool on_mousewheel_internal(Gdk.EventScroll event) {
         switch (event.direction) {
             case Gdk.ScrollDirection.UP:


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