[gnome-games] display-bin: Apply offsets when drawing, not allocating



commit 2274a0676fc471472f5e4e614372aeac7a483230
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Sat Sep 21 16:23:32 2019 +0500

    display-bin: Apply offsets when drawing, not allocating
    
    While this means pointer input won't work properly when an offset is
    applied, the game is paused anyway in those moments. However, we avoid
    fighting between allocations triggered by setting offsets and "normal"
    allocations, prevending a glitchy state when animations are disabled.

 src/ui/display-bin.vala | 26 +++++++++-----------------
 src/ui/display-box.vala | 13 +------------
 2 files changed, 10 insertions(+), 29 deletions(-)
---
diff --git a/src/ui/display-bin.vala b/src/ui/display-bin.vala
index e9ad67b1..e43c1d26 100644
--- a/src/ui/display-bin.vala
+++ b/src/ui/display-bin.vala
@@ -9,7 +9,7 @@ public class Games.DisplayBin : Gtk.Bin {
                                return;
 
                        _horizontal_offset = value;
-                       queue_allocate ();
+                       queue_draw ();
                }
        }
 
@@ -21,26 +21,18 @@ public class Games.DisplayBin : Gtk.Bin {
                                return;
 
                        _vertical_offset = value;
-                       queue_allocate ();
+                       queue_draw ();
                }
        }
 
-       public override void size_allocate (Gtk.Allocation allocation) {
-               set_allocation (allocation);
+       public override bool draw (Cairo.Context cr) {
+               if (get_direction () == Gtk.TextDirection.RTL)
+                       cr.translate (-horizontal_offset, vertical_offset);
+               else
+                       cr.translate (horizontal_offset, vertical_offset);
 
-               var child = get_child ();
-               if (child != null && child.visible) {
-                       Gtk.Allocation child_allocation = {};
+               base.draw (cr);
 
-                       if (get_direction () == Gtk.TextDirection.RTL)
-                               child_allocation.x = allocation.x - horizontal_offset;
-                       else
-                               child_allocation.x = allocation.x + horizontal_offset;
-                       child_allocation.y = allocation.y + vertical_offset;
-                       child_allocation.width = allocation.width;
-                       child_allocation.height = allocation.height;
-
-                       child.size_allocate (child_allocation);
-               }
+               return true;
        }
 }
diff --git a/src/ui/display-box.vala b/src/ui/display-box.vala
index 8de6f4d2..412002bd 100644
--- a/src/ui/display-box.vala
+++ b/src/ui/display-box.vala
@@ -138,17 +138,6 @@ private class Games.DisplayBox : Gtk.Bin {
 
        [GtkCallback]
        private void on_savestates_list_size_allocate (Gtk.Allocation allocation) {
-               update_margin ();
-       }
-
-       public override void size_allocate (Gtk.Allocation allocation) {
-               update_margin ();
-               base.size_allocate (allocation);
-       }
-
-       private void update_margin () {
-               var width = savestates_list.get_allocated_width ();
-
-               display_bin.horizontal_offset = -width / 2;
+               display_bin.horizontal_offset = -allocation.width / 2;
        }
 }


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