[gtk] snapshot: Add gtk_snapshot_append_border()



commit e1570e9ebc1e8b7600514958355550cd804abca6
Author: Benjamin Otte <otte redhat com>
Date:   Thu Feb 21 02:11:13 2019 +0100

    snapshot: Add gtk_snapshot_append_border()
    
    This is adding functions for the remaining render nodes.

 docs/reference/gtk/gtk4-sections.txt |  3 +++
 gsk/gskrendernodeimpl.c              |  7 ++++---
 gtk/gtkrenderborder.c                | 12 +-----------
 gtk/gtksnapshot.c                    | 36 ++++++++++++++++++++++++++++++++++++
 gtk/gtksnapshot.h                    |  5 +++++
 5 files changed, 49 insertions(+), 14 deletions(-)
---
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index bbe287b7d4..bb39c8f935 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -4409,6 +4409,9 @@ gtk_snapshot_append_cairo
 gtk_snapshot_append_texture
 gtk_snapshot_append_color
 gtk_snapshot_append_layout
+gtk_snapshot_append_linear_gradient
+gtk_snapshot_append_repeating_linear_gradient
+gtk_snapshot_append_border
 gtk_snapshot_render_background
 gtk_snapshot_render_frame
 gtk_snapshot_render_focus
diff --git a/gsk/gskrendernodeimpl.c b/gsk/gskrendernodeimpl.c
index 65c8e33332..aa72646065 100644
--- a/gsk/gskrendernodeimpl.c
+++ b/gsk/gskrendernodeimpl.c
@@ -712,9 +712,10 @@ gsk_border_node_peek_colors (GskRenderNode *node)
 /**
  * gsk_border_node_new:
  * @outline: a #GskRoundedRect describing the outline of the border
- * @border_width: the stroke width of the border on the top, right, bottom and
- *     left side respectively.
- * @border_color: the color used on the top, right, bottom and left side.
+ * @border_width: (array fixed-size=4): the stroke width of the border on
+ *     the top, right, bottom and left side respectively.
+ * @border_color: (array fixed-size=4): the color used on the top, right,
+ *     bottom and left side.
  *
  * Creates a #GskRenderNode that will stroke a border rectangle inside the
  * given @outline. The 4 sides of the border can have different widths and
diff --git a/gtk/gtkrenderborder.c b/gtk/gtkrenderborder.c
index 08a05f692f..d39c736ff8 100644
--- a/gtk/gtkrenderborder.c
+++ b/gtk/gtkrenderborder.c
@@ -342,10 +342,6 @@ snapshot_frame_fill (GtkSnapshot          *snapshot,
                      const GdkRGBA         colors[4],
                      guint                 hidden_side)
 {
-  GskRoundedRect offset_outline;
-  GskRenderNode *node;
-  int off_x, off_y;
-
   if (hidden_side)
     {
       GdkRGBA real_colors[4];
@@ -363,13 +359,7 @@ snapshot_frame_fill (GtkSnapshot          *snapshot,
       return;
     }
 
-  gtk_snapshot_get_offset (snapshot, &off_x, &off_y);
-  gsk_rounded_rect_init_copy (&offset_outline, outline);
-  gsk_rounded_rect_offset (&offset_outline, off_x, off_y);
-  
-  node = gsk_border_node_new (&offset_outline, border_width, colors);
-  gtk_snapshot_append_node_internal (snapshot, node);
-  gsk_render_node_unref (node);
+  gtk_snapshot_append_border (snapshot, outline, border_width, colors);
 }
 
 static void
diff --git a/gtk/gtksnapshot.c b/gtk/gtksnapshot.c
index b862e5a7a6..1be41ad138 100644
--- a/gtk/gtksnapshot.c
+++ b/gtk/gtksnapshot.c
@@ -1558,3 +1558,39 @@ gtk_snapshot_append_repeating_linear_gradient (GtkSnapshot            *snapshot,
   gtk_snapshot_append_node_internal (snapshot, node);
   gsk_render_node_unref (node);
 }
+
+/**
+ * gtk_snapshot_append_border:
+ * @snapshot: a #GtkSnapshot
+ * @outline: a #GskRoundedRect describing the outline of the border
+ * @border_width: (array fixed-size=4): the stroke width of the border on
+ *     the top, right, bottom and left side respectively.
+ * @border_color: (array fixed-size=4): the color used on the top, right,
+ *     bottom and left side.
+ *
+ * Appends a stroked border rectangle inside the given @outline. The
+ * 4 sides of the border can have different widths and colors.
+ **/
+void
+gtk_snapshot_append_border (GtkSnapshot          *snapshot,
+                            const GskRoundedRect *outline,
+                            const float           border_width[4],
+                            const GdkRGBA         border_color[4])
+{
+  GskRenderNode *node;
+  GskRoundedRect real_outline;
+  float scale_x, scale_y, dx, dy;
+
+  g_return_if_fail (snapshot != NULL);
+  g_return_if_fail (outline != NULL);
+  g_return_if_fail (border_width != NULL);
+  g_return_if_fail (border_color != NULL);
+
+  gtk_snapshot_ensure_affine (snapshot, &scale_x, &scale_y, &dx, &dy);
+  gtk_rounded_rect_scale_affine (&real_outline, outline, scale_x, scale_y, dx, dy);
+
+  node = gsk_border_node_new (&real_outline, border_width, border_color);
+
+  gtk_snapshot_append_node_internal (snapshot, node);
+  gsk_render_node_unref (node);
+}
diff --git a/gtk/gtksnapshot.h b/gtk/gtksnapshot.h
index 1ee801a71b..1f61d7a214 100644
--- a/gtk/gtksnapshot.h
+++ b/gtk/gtksnapshot.h
@@ -141,6 +141,11 @@ void            gtk_snapshot_append_repeating_linear_gradient (GtkSnapshot
                                                                const graphene_point_t *end_point,
                                                                const GskColorStop     *stops,
                                                                gsize                   n_stops);
+GDK_AVAILABLE_IN_ALL
+void            gtk_snapshot_append_border              (GtkSnapshot            *snapshot,
+                                                         const GskRoundedRect   *outline,
+                                                         const float             border_width[4],
+                                                         const GdkRGBA           border_color[4]);
 /* next function implemented in gskpango.c */
 GDK_AVAILABLE_IN_ALL
 void            gtk_snapshot_append_layout              (GtkSnapshot            *snapshot,


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