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



commit 9e5828ce2806e25924545fba1b3de03fb84e2d1e
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.

 src/ui/game-thumbnail.vala | 14 +++++++-------
 src/ui/gamepad-view.vala   | 12 ++++--------
 2 files changed, 11 insertions(+), 15 deletions(-)
---
diff --git a/src/ui/game-thumbnail.vala b/src/ui/game-thumbnail.vala
index bd4c12a1..61added3 100644
--- a/src/ui/game-thumbnail.vala
+++ b/src/ui/game-thumbnail.vala
@@ -79,22 +79,24 @@ 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 surface = get_surface ();
                var style = get_style_context ();
                var state = get_state_flags ();
-               var width = get_allocated_width ();
-               var height = get_allocated_height ();
 
                DrawingContext context = {
                        cr, surface, style, state, width, height
                };
 
                if (icon == null)
-                       return false;
+                       return;
 
                if (cover == null)
-                       return false;
+                       return;
 
                var drawn = false;
 
@@ -106,8 +108,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 98a3817b..aa9833c2 100644
--- a/src/ui/gamepad-view.vala
+++ b/src/ui/gamepad-view.vala
@@ -9,6 +9,7 @@ private class Games.GamepadView : Gtk.DrawingArea {
                handle = new Rsvg.Handle ();
                configuration = { "", new GamepadInputPath[0] };
                input_highlights = {};
+               set_draw_func (draw);
        }
 
        public void set_configuration (GamepadViewConfiguration configuration) throws Error {
@@ -43,17 +44,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) {
@@ -81,10 +80,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 (int w, int 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;


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