[gtk+/wip/otte/rendernode: 76/100] snapshot: Convert Range, Scale, ColorScale



commit 8d0514c89888148ad197ddf1d40a85a2c917c5eb
Author: Benjamin Otte <otte redhat com>
Date:   Thu Dec 15 10:09:41 2016 +0100

    snapshot: Convert Range, Scale, ColorScale
    
    And of course Scrollbar, but that one does no drawing itself.

 gtk/gtkcolorscale.c        |   26 ++++++++--------
 gtk/gtkcolorscaleprivate.h |   12 ++++----
 gtk/gtkrange.c             |   38 +++++++++++------------
 gtk/gtkscale.c             |   70 ++++++++++++++++++++++---------------------
 4 files changed, 73 insertions(+), 73 deletions(-)
---
diff --git a/gtk/gtkcolorscale.c b/gtk/gtkcolorscale.c
index e1bf973..b6560a7 100644
--- a/gtk/gtkcolorscale.c
+++ b/gtk/gtkcolorscale.c
@@ -29,6 +29,7 @@
 #include "gtkprivate.h"
 #include "gtkintl.h"
 #include "gtkrenderprivate.h"
+#include "gtksnapshot.h"
 
 #include <math.h>
 
@@ -54,25 +55,24 @@ static void hold_action (GtkGestureLongPress *gesture,
 G_DEFINE_TYPE_WITH_PRIVATE (GtkColorScale, gtk_color_scale, GTK_TYPE_SCALE)
 
 void
-gtk_color_scale_draw_trough (GtkColorScale  *scale,
-                             cairo_t        *cr,
-                             int             x,
-                             int             y,
-                             int             width,
-                             int             height)
+gtk_color_scale_snapshot_trough (GtkColorScale  *scale,
+                                 GtkSnapshot    *snapshot,
+                                 int             x,
+                                 int             y,
+                                 int             width,
+                                 int             height)
 {
-  GtkWidget *widget;
+  GtkWidget *widget = GTK_WIDGET (scale);
+  cairo_t *cr;
 
   if (width <= 1 || height <= 1)
     return;
 
-  cairo_save (cr);
+  cr = gtk_snapshot_append_cairo_node (snapshot,
+                                       &GRAPHENE_RECT_INIT(x, y, width, height),
+                                       "ColorScaleTrough");
   cairo_translate (cr, x, y);
 
-  widget = GTK_WIDGET (scale);
-  cairo_rectangle (cr, 0, 0, width, height);
-  cairo_clip (cr);
-
   if (gtk_orientable_get_orientation (GTK_ORIENTABLE (widget)) == GTK_ORIENTATION_HORIZONTAL &&
       gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
     {
@@ -145,7 +145,7 @@ gtk_color_scale_draw_trough (GtkColorScale  *scale,
       cairo_pattern_destroy (pattern);
     }
 
-  cairo_restore (cr);
+  cairo_destroy (cr);
 }
 
 static void
diff --git a/gtk/gtkcolorscaleprivate.h b/gtk/gtkcolorscaleprivate.h
index 15b3324..e1a5425 100644
--- a/gtk/gtkcolorscaleprivate.h
+++ b/gtk/gtkcolorscaleprivate.h
@@ -64,12 +64,12 @@ GtkWidget * gtk_color_scale_new      (GtkAdjustment     *adjustment,
 void        gtk_color_scale_set_rgba (GtkColorScale     *scale,
                                       const GdkRGBA     *color);
 
-void        gtk_color_scale_draw_trough (GtkColorScale  *scale,
-                                         cairo_t        *cr,
-                                         int             x,
-                                         int             y,
-                                         int             width,
-                                         int             height);
+void        gtk_color_scale_snapshot_trough (GtkColorScale  *scale,
+                                             GtkSnapshot    *snapshot,
+                                             int             x,
+                                             int             y,
+                                             int             width,
+                                             int             height);
 
 G_END_DECLS
 
diff --git a/gtk/gtkrange.c b/gtk/gtkrange.c
index a7658e2..cfb4ff4 100644
--- a/gtk/gtkrange.c
+++ b/gtk/gtkrange.c
@@ -190,8 +190,8 @@ static void gtk_range_realize        (GtkWidget        *widget);
 static void gtk_range_unrealize      (GtkWidget        *widget);
 static void gtk_range_map            (GtkWidget        *widget);
 static void gtk_range_unmap          (GtkWidget        *widget);
-static gboolean gtk_range_draw       (GtkWidget        *widget,
-                                      cairo_t          *cr);
+static void gtk_range_snapshot       (GtkWidget        *widget,
+                                      GtkSnapshot      *snapshot);
 
 static void gtk_range_multipress_gesture_pressed  (GtkGestureMultiPress *gesture,
                                                    guint                 n_press,
@@ -273,7 +273,7 @@ static void          gtk_range_allocate_trough          (GtkCssGadget        *ga
                                                          GtkAllocation       *out_clip,
                                                          gpointer             data);
 static gboolean      gtk_range_render_trough            (GtkCssGadget *gadget,
-                                                         cairo_t      *cr,
+                                                         GtkSnapshot  *snapshot,
                                                          int           x,
                                                          int           y,
                                                          int           width,
@@ -293,7 +293,7 @@ static void          gtk_range_allocate                 (GtkCssGadget        *ga
                                                          GtkAllocation       *out_clip,
                                                          gpointer             data);
 static gboolean      gtk_range_render                   (GtkCssGadget *gadget,
-                                                         cairo_t      *cr,
+                                                         GtkSnapshot  *snapshot,
                                                          int           x,
                                                          int           y,
                                                          int           width,
@@ -328,7 +328,7 @@ gtk_range_class_init (GtkRangeClass *class)
   widget_class->unrealize = gtk_range_unrealize;
   widget_class->map = gtk_range_map;
   widget_class->unmap = gtk_range_unmap;
-  widget_class->draw = gtk_range_draw;
+  widget_class->snapshot = gtk_range_snapshot;
   widget_class->event = gtk_range_event;
   widget_class->scroll_event = gtk_range_scroll_event;
   widget_class->key_press_event = gtk_range_key_press;
@@ -667,8 +667,8 @@ gtk_range_init (GtkRange *range)
                                                      GTK_WIDGET (range),
                                                      gtk_range_measure,
                                                      gtk_range_allocate,
-                                                     gtk_range_render,
                                                      NULL,
+                                                     gtk_range_render,
                                                      NULL, NULL);
   priv->contents_gadget = gtk_box_gadget_new ("contents",
                                               GTK_WIDGET (range),
@@ -678,8 +678,8 @@ gtk_range_init (GtkRange *range)
                                                    NULL, NULL,
                                                    gtk_range_measure_trough,
                                                    gtk_range_allocate_trough,
-                                                   gtk_range_render_trough,
                                                    NULL,
+                                                   gtk_range_render_trough,
                                                    NULL, NULL);
   gtk_css_gadget_set_state (priv->trough_gadget,
                             gtk_css_node_get_state (widget_node));
@@ -2110,7 +2110,7 @@ gtk_range_state_flags_changed (GtkWidget     *widget,
 
 static gboolean
 gtk_range_render_trough (GtkCssGadget *gadget,
-                         cairo_t      *cr,
+                         GtkSnapshot  *snapshot,
                          int           x,
                          int           y,
                          int           width,
@@ -2125,22 +2125,22 @@ gtk_range_render_trough (GtkCssGadget *gadget,
    * so we let it...
    */
   if (GTK_IS_COLOR_SCALE (widget))
-    gtk_color_scale_draw_trough (GTK_COLOR_SCALE (widget), cr, x, y, width, height);
+    gtk_color_scale_snapshot_trough (GTK_COLOR_SCALE (widget), snapshot, x, y, width, height);
 
   if (priv->show_fill_level &&
       gtk_adjustment_get_upper (priv->adjustment) - gtk_adjustment_get_page_size (priv->adjustment) -
       gtk_adjustment_get_lower (priv->adjustment) != 0)
-    gtk_css_gadget_draw (priv->fill_gadget, cr);
+    gtk_css_gadget_snapshot (priv->fill_gadget, snapshot);
 
   if (priv->has_origin)
-    gtk_css_gadget_draw (priv->highlight_gadget, cr);
+    gtk_css_gadget_snapshot (priv->highlight_gadget, snapshot);
 
   return gtk_widget_has_visible_focus (widget);
 }
 
 static gboolean
 gtk_range_render (GtkCssGadget *gadget,
-                  cairo_t      *cr,
+                  GtkSnapshot  *snapshot,
                   int           x,
                   int           y,
                   int           width,
@@ -2151,24 +2151,22 @@ gtk_range_render (GtkCssGadget *gadget,
   GtkRange *range = GTK_RANGE (widget);
   GtkRangePrivate *priv = range->priv;
 
-  gtk_css_gadget_draw (priv->contents_gadget, cr);
+  gtk_css_gadget_snapshot (priv->contents_gadget, snapshot);
 
   /* Draw the slider last, so that e.g. the focus ring stays below it */
-  gtk_css_gadget_draw (priv->slider_gadget, cr);
+  gtk_css_gadget_snapshot (priv->slider_gadget, snapshot);
 
   return FALSE;
 }
 
-static gboolean
-gtk_range_draw (GtkWidget *widget,
-                cairo_t   *cr)
+static void
+gtk_range_snapshot (GtkWidget   *widget,
+                    GtkSnapshot *snapshot)
 {
   GtkRange *range = GTK_RANGE (widget);
   GtkRangePrivate *priv = range->priv;
 
-  gtk_css_gadget_draw (priv->gadget, cr);
-
-  return GDK_EVENT_PROPAGATE;
+  gtk_css_gadget_snapshot (priv->gadget, snapshot);
 }
 
 static void
diff --git a/gtk/gtkscale.c b/gtk/gtkscale.c
index 82edd96..e332019 100644
--- a/gtk/gtkscale.c
+++ b/gtk/gtkscale.c
@@ -209,8 +209,8 @@ static void     gtk_scale_value_style_changed     (GtkCssNode        *node,
                                                    GtkScale          *scale);
 static void     gtk_scale_screen_changed          (GtkWidget      *widget,
                                                    GdkScreen      *old_screen);
-static gboolean gtk_scale_draw                    (GtkWidget      *widget,
-                                                   cairo_t        *cr);
+static void     gtk_scale_snapshot                (GtkWidget      *widget,
+                                                   GtkSnapshot    *snapshot);
 static void     gtk_scale_real_get_layout_offsets (GtkScale       *scale,
                                                    gint           *x,
                                                    gint           *y);
@@ -717,7 +717,7 @@ gtk_scale_class_init (GtkScaleClass *class)
   gobject_class->finalize = gtk_scale_finalize;
 
   widget_class->screen_changed = gtk_scale_screen_changed;
-  widget_class->draw = gtk_scale_draw;
+  widget_class->snapshot = gtk_scale_snapshot;
   widget_class->size_allocate = gtk_scale_size_allocate;
   widget_class->measure = gtk_scale_measure;
 
@@ -1134,7 +1134,7 @@ gtk_scale_get_digits (GtkScale *scale)
 
 static gboolean
 gtk_scale_render_value (GtkCssGadget *gadget,
-                        cairo_t      *cr,
+                        GtkSnapshot  *snapshot,
                         int           x,
                         int           y,
                         int           width,
@@ -1150,7 +1150,7 @@ gtk_scale_render_value (GtkCssGadget *gadget,
   gtk_style_context_save_to_node (context, gtk_css_gadget_get_node (gadget));
 
   layout = gtk_scale_get_layout (scale);
-  gtk_render_layout (context, cr, x, y, layout);
+  gtk_snapshot_render_layout (snapshot, context, x, y, layout);
 
   gtk_style_context_restore (context);
 
@@ -1288,8 +1288,8 @@ gtk_scale_set_draw_value (GtkScale *scale,
                                                           widget, NULL, NULL,
                                                           gtk_scale_measure_value,
                                                           NULL,
-                                                          gtk_scale_render_value,
                                                           NULL,
+                                                          gtk_scale_render_value,
                                                           NULL, NULL);
           g_signal_connect (gtk_css_gadget_get_node (priv->value_gadget), "style-changed",
                             G_CALLBACK (gtk_scale_value_style_changed), scale);
@@ -1741,7 +1741,7 @@ gtk_scale_measure (GtkWidget      *widget,
 
 static gboolean
 gtk_scale_render_mark_indicator (GtkCssGadget *gadget,
-                                 cairo_t      *cr,
+                                 GtkSnapshot  *snapshot,
                                  int           x,
                                  int           y,
                                  int           width,
@@ -1751,19 +1751,23 @@ gtk_scale_render_mark_indicator (GtkCssGadget *gadget,
   GtkWidget *widget = gtk_css_gadget_get_owner (gadget);
   GtkStyleContext *context;
   GtkOrientation orientation;
+  GdkRGBA color;
 
   orientation = gtk_orientable_get_orientation (GTK_ORIENTABLE (widget));
   context = gtk_widget_get_style_context (widget);
   gtk_style_context_save_to_node (context, gtk_css_gadget_get_node (gadget));
 
+  gtk_style_context_get_color (context, &color);
   if (orientation == GTK_ORIENTATION_HORIZONTAL)
-    gtk_render_line (context, cr,
-                     x + width / 2, y,
-                     x + width / 2, y + height);
+    gtk_snapshot_append_color_node (snapshot,
+                                    &color, 
+                                    &GRAPHENE_RECT_INIT(x + width / 2, y, 1, height),
+                                    "ScaleMark");
   else
-    gtk_render_line (context, cr,
-                     x, y + height / 2,
-                     x + width, y + height / 2);
+    gtk_snapshot_append_color_node (snapshot,
+                                    &color, 
+                                    &GRAPHENE_RECT_INIT(x, y + height / 2, width, 1),
+                                    "ScaleMark");
 
   gtk_style_context_restore (context);
 
@@ -1772,7 +1776,7 @@ gtk_scale_render_mark_indicator (GtkCssGadget *gadget,
 
 static gboolean
 gtk_scale_render_mark_label (GtkCssGadget *gadget,
-                             cairo_t      *cr,
+                             GtkSnapshot  *snapshot,
                              int           x,
                              int           y,
                              int           width,
@@ -1787,7 +1791,7 @@ gtk_scale_render_mark_label (GtkCssGadget *gadget,
   gtk_style_context_save_to_node (context, gtk_css_gadget_get_node (gadget));
   gtk_css_node_update_layout_attributes (gtk_css_gadget_get_node (gadget), mark->layout);
 
-  gtk_render_layout (context, cr, x, y, mark->layout);
+  gtk_snapshot_render_layout (snapshot, context, x, y, mark->layout);
 
   gtk_style_context_restore (context);
 
@@ -1796,7 +1800,7 @@ gtk_scale_render_mark_label (GtkCssGadget *gadget,
 
 static gboolean
 gtk_scale_render_mark (GtkCssGadget *gadget,
-                       cairo_t      *cr,
+                       GtkSnapshot  *snapshot,
                        int           x,
                        int           y,
                        int           width,
@@ -1805,16 +1809,16 @@ gtk_scale_render_mark (GtkCssGadget *gadget,
 {
   GtkScaleMark *mark = user_data;
 
-  gtk_css_gadget_draw (mark->indicator_gadget, cr);
+  gtk_css_gadget_snapshot (mark->indicator_gadget, snapshot);
   if (mark->label_gadget)
-    gtk_css_gadget_draw (mark->label_gadget, cr);
+    gtk_css_gadget_snapshot (mark->label_gadget, snapshot);
 
   return FALSE;
 }
 
 static gboolean
 gtk_scale_render_marks (GtkCssGadget *gadget,
-                        cairo_t      *cr,
+                        GtkSnapshot  *snapshot,
                         int           x,
                         int           y,
                         int           width,
@@ -1834,30 +1838,28 @@ gtk_scale_render_marks (GtkCssGadget *gadget,
           (mark->position == GTK_POS_BOTTOM && gadget == priv->top_marks_gadget))
         continue;
 
-      gtk_css_gadget_draw (mark->gadget, cr);
+      gtk_css_gadget_snapshot (mark->gadget, snapshot);
     }
 
   return FALSE;
 }
 
-static gboolean
-gtk_scale_draw (GtkWidget *widget,
-                cairo_t   *cr)
+static void
+gtk_scale_snapshot (GtkWidget   *widget,
+                    GtkSnapshot *snapshot)
 {
   GtkScale *scale = GTK_SCALE (widget);
   GtkScalePrivate *priv = scale->priv;
 
   if (priv->top_marks_gadget)
-    gtk_css_gadget_draw (priv->top_marks_gadget, cr);
+    gtk_css_gadget_snapshot (priv->top_marks_gadget, snapshot);
   if (priv->bottom_marks_gadget)
-    gtk_css_gadget_draw (priv->bottom_marks_gadget, cr);
+    gtk_css_gadget_snapshot (priv->bottom_marks_gadget, snapshot);
 
-  GTK_WIDGET_CLASS (gtk_scale_parent_class)->draw (widget, cr);
+  GTK_WIDGET_CLASS (gtk_scale_parent_class)->snapshot (widget, snapshot);
 
   if (priv->value_gadget)
-    gtk_css_gadget_draw (priv->value_gadget, cr);
-
-  return FALSE;
+    gtk_css_gadget_snapshot (priv->value_gadget, snapshot);
 }
 
 static void
@@ -2165,8 +2167,8 @@ gtk_scale_add_mark (GtkScale        *scale,
                                        widget, NULL, NULL,
                                        gtk_scale_measure_marks,
                                        gtk_scale_allocate_marks,
-                                       gtk_scale_render_marks,
                                        NULL,
+                                       gtk_scale_render_marks,
                                        NULL, NULL);
           gtk_css_node_insert_after (widget_node,
                                      gtk_css_gadget_get_node (priv->top_marks_gadget),
@@ -2187,8 +2189,8 @@ gtk_scale_add_mark (GtkScale        *scale,
                                        widget, NULL, NULL,
                                        gtk_scale_measure_marks,
                                        gtk_scale_allocate_marks,
-                                       gtk_scale_render_marks,
                                        NULL,
+                                       gtk_scale_render_marks,
                                        NULL, NULL);
           gtk_css_node_insert_before (widget_node,
                                       gtk_css_gadget_get_node (priv->bottom_marks_gadget),
@@ -2206,8 +2208,8 @@ gtk_scale_add_mark (GtkScale        *scale,
                                widget, NULL, NULL,
                                gtk_scale_measure_mark,
                                gtk_scale_allocate_mark,
-                               gtk_scale_render_mark,
                                NULL,
+                               gtk_scale_render_mark,
                                mark, NULL);
   gtk_css_gadget_set_state (mark->gadget, gtk_css_node_get_state (marks_node));
 
@@ -2216,8 +2218,8 @@ gtk_scale_add_mark (GtkScale        *scale,
                                widget, mark->gadget, NULL,
                                NULL,
                                NULL,
-                               gtk_scale_render_mark_indicator,
                                NULL,
+                               gtk_scale_render_mark_indicator,
                                mark, NULL);
   if (mark->markup && *mark->markup)
     {
@@ -2228,8 +2230,8 @@ gtk_scale_add_mark (GtkScale        *scale,
                                    NULL : mark->indicator_gadget,
                                    gtk_scale_measure_mark_label,
                                    NULL,
-                                   gtk_scale_render_mark_label,
                                    NULL,
+                                   gtk_scale_render_mark_label,
                                    mark, NULL);
       g_signal_connect (gtk_css_gadget_get_node (mark->label_gadget), "style-changed",
                         G_CALLBACK (gtk_scale_mark_style_changed), mark);


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