[gnome-games/wip/exalm/gtk4: 216/238] ui: Stop using 'draw' signal for GdkDrawingArea



commit e9b3398a76cd41e364944ffde7804ecc7a1de7d5
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date:   Sun Jul 29 13:06:34 2018 +0500

    ui: Stop using 'draw' signal for GdkDrawingArea
    
    Use gtk_drawing_area_set_draw_func() instead.

 data/ui/savestate-listbox-row.ui  |  1 -
 src/ui/game-thumbnail.vala        | 14 +++++++-------
 src/ui/gamepad-view.vala          | 12 ++++--------
 src/ui/savestate-listbox-row.vala | 19 +++++++------------
 4 files changed, 18 insertions(+), 28 deletions(-)
---
diff --git a/data/ui/savestate-listbox-row.ui b/data/ui/savestate-listbox-row.ui
index ddf66e45..d1df8ab7 100644
--- a/data/ui/savestate-listbox-row.ui
+++ b/data/ui/savestate-listbox-row.ui
@@ -22,7 +22,6 @@
                 <property name="width-request">66</property>
                 <property name="height-request">66</property>
                 <property name="margin">6</property>
-                <signal name="draw" handler="on_draw_image"/>
                 <style>
                   <class name="savestate-thumbnail"/>
                 </style>
diff --git a/src/ui/game-thumbnail.vala b/src/ui/game-thumbnail.vala
index 12009012..e6416fa4 100644
--- a/src/ui/game-thumbnail.vala
+++ b/src/ui/game-thumbnail.vala
@@ -78,21 +78,23 @@ private class Games.GameThumbnail : Gtk.DrawingArea {
                minimum_height = natural_height = width;
        }
 
-       public override bool draw (Cairo.Context cr) {
+       construct {
+               set_draw_func (draw);
+       }
+
+       public void draw (Gtk.DrawingArea area, Cairo.Context cr, int width, int height) {
                var style = get_style_context ();
                var state = get_state_flags ();
-               var width = get_allocated_width ();
-               var height = get_allocated_height ();
 
                DrawingContext context = {
                        cr, style, state, width, height
                };
 
                if (icon == null)
-                       return false;
+                       return;
 
                if (cover == null)
-                       return false;
+                       return;
 
                var drawn = false;
 
@@ -104,8 +106,6 @@ private class Games.GameThumbnail : Gtk.DrawingArea {
                // Draw the default thumbnail if no thumbnail have been drawn
                if (!drawn)
                        draw_default (context);
-
-               return true;
        }
 
        public bool draw_icon (DrawingContext context) {
diff --git a/src/ui/gamepad-view.vala b/src/ui/gamepad-view.vala
index f917f785..31647f24 100644
--- a/src/ui/gamepad-view.vala
+++ b/src/ui/gamepad-view.vala
@@ -37,6 +37,7 @@ private class Games.GamepadView : Gtk.DrawingArea {
                handle = new Rsvg.Handle ();
                configuration = { "", new GamepadInputPath[0] };
                input_highlights = {};
+               set_draw_func (draw);
        }
 
        public void reset () {
@@ -59,17 +60,15 @@ private class Games.GamepadView : Gtk.DrawingArea {
                return false;
        }
 
-       public override bool draw (Cairo.Context context) {
+       public void draw (Gtk.DrawingArea area, Cairo.Context context, int width, int height) {
                double x, y, scale;
-               calculate_image_dimensions (out x, out y, out scale);
+               calculate_image_dimensions (width, height, out x, out y, out scale);
 
                context.translate (x, y);
                context.scale (scale, scale);
 
                color_gamepad (context);
                highlight_gamepad (context);
-
-               return false;
        }
 
        private void color_gamepad (Cairo.Context context) {
@@ -97,10 +96,7 @@ private class Games.GamepadView : Gtk.DrawingArea {
                        }
        }
 
-       private void calculate_image_dimensions (out double x, out double y, out double scale) {
-               double w = get_allocated_width ();
-               double h = get_allocated_height ();
-
+       private void calculate_image_dimensions (double w, double h, out double x, out double y, out double 
scale) {
                scale = double.min (h / handle.height, w / handle.width);
 
                x = (w - handle.width * scale) / 2;
diff --git a/src/ui/savestate-listbox-row.vala b/src/ui/savestate-listbox-row.vala
index 56b17414..e933cfd9 100644
--- a/src/ui/savestate-listbox-row.vala
+++ b/src/ui/savestate-listbox-row.vala
@@ -38,6 +38,10 @@ private class Games.SavestateListBoxRow : Gtk.ListBoxRow {
 
        private Gdk.Pixbuf pixbuf;
 
+       construct {
+               image.set_draw_func (draw_image);
+       }
+
        public SavestateListBoxRow (Savestate savestate) {
                Object (savestate: savestate);
        }
@@ -106,11 +110,7 @@ private class Games.SavestateListBoxRow : Gtk.ListBoxRow {
                revealer.reveal_child = false;
        }
 
-       [GtkCallback]
-       private bool on_draw_image (Cairo.Context cr) {
-               var width = image.get_allocated_width ();
-               var height = image.get_allocated_height ();
-
+       public void draw_image (Gtk.DrawingArea area, Cairo.Context cr, int width, int height) {
                var style = image.get_style_context ();
                style.render_background (cr, 0.0, 0.0, width, height);
                style.render_frame (cr, 0.0, 0.0, width, height);
@@ -118,7 +118,7 @@ private class Games.SavestateListBoxRow : Gtk.ListBoxRow {
                cr.save ();
                cr.scale (1.0 / scale_factor, 1.0 / scale_factor);
 
-               var mask = get_mask ();
+               var mask = get_mask (width, height);
 
                var x_offset = (width * scale_factor - pixbuf.width) / 2;
                var y_offset = (height * scale_factor - pixbuf.height) / 2;
@@ -128,15 +128,10 @@ private class Games.SavestateListBoxRow : Gtk.ListBoxRow {
                cr.mask_surface (mask, 0, 0);
 
                cr.restore ();
-
-               return Gdk.EVENT_PROPAGATE;
        }
 
        // TODO: Share this with GameThumbnail
-       private Cairo.Surface get_mask () {
-               var width = image.get_allocated_width ();
-               var height = image.get_allocated_height ();
-
+       private Cairo.Surface get_mask (int width, int height) {
                var mask = new Cairo.ImageSurface (Cairo.Format.A8, width * scale_factor, height * 
scale_factor);
 
                var style = image.get_style_context ();


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