[gtk] colorplane: Convert crosshair rendering to snapshot



commit fe49f83982a79108cf28e1b14091654268c45e7e
Author: Timm Bäder <tbaeder redhat com>
Date:   Fri Nov 23 11:22:51 2018 +0100

    colorplane: Convert crosshair rendering to snapshot
    
    This is slightly different than the cairo version since the
    half-transparent lines now overlap but nobody can see that anyway.

 gtk/gtkcolorplane.c | 44 ++++++++++++++++++++++----------------------
 1 file changed, 22 insertions(+), 22 deletions(-)
---
diff --git a/gtk/gtkcolorplane.c b/gtk/gtkcolorplane.c
index 1eedf04f66..17f658c9ac 100644
--- a/gtk/gtkcolorplane.c
+++ b/gtk/gtkcolorplane.c
@@ -72,7 +72,6 @@ plane_snapshot (GtkWidget   *widget,
   GtkColorPlane *plane = GTK_COLOR_PLANE (widget);
   gint x, y;
   gint width, height;
-  cairo_t *cr;
 
   sv_to_xy (plane, &x, &y);
   width = gtk_widget_get_width (widget);
@@ -81,33 +80,34 @@ plane_snapshot (GtkWidget   *widget,
   gtk_snapshot_append_texture (snapshot,
                                plane->priv->texture,
                                &GRAPHENE_RECT_INIT (0, 0, width, height));
-  cr = gtk_snapshot_append_cairo (snapshot,
-                                  &GRAPHENE_RECT_INIT (0, 0, width, height));
-
-  cairo_move_to (cr, 0,     y + 0.5);
-  cairo_line_to (cr, width, y + 0.5);
-
-  cairo_move_to (cr, x + 0.5, 0);
-  cairo_line_to (cr, x + 0.5, height);
-
   if (gtk_widget_has_visible_focus (widget))
     {
-      cairo_set_line_width (cr, 3.0);
-      cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.6);
-      cairo_stroke_preserve (cr);
-
-      cairo_set_line_width (cr, 1.0);
-      cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 0.8);
-      cairo_stroke (cr);
+      const GdkRGBA c1 = { 1.0, 1.0, 1.0, 0.6 };
+      const GdkRGBA c2 = { 0.0, 0.0, 0.0, 0.8 };
+
+      /* Crosshair border */
+      gtk_snapshot_append_color (snapshot, &c1,
+                                 &GRAPHENE_RECT_INIT (0, y - 1.5, width, 3));
+      gtk_snapshot_append_color (snapshot, &c1,
+                                 &GRAPHENE_RECT_INIT (x - 1.5, 0, 3, height));
+
+      /* Actual crosshair */
+      gtk_snapshot_append_color (snapshot, &c2,
+                                 &GRAPHENE_RECT_INIT (0, y - 0.5, width, 1));
+      gtk_snapshot_append_color (snapshot, &c2,
+                                 &GRAPHENE_RECT_INIT (x - 0.5, 0, 1, height));
     }
   else
     {
-      cairo_set_line_width (cr, 1.0);
-      cairo_set_source_rgba (cr, 0.8, 0.8, 0.8, 0.8);
-      cairo_stroke (cr);
+      const GdkRGBA c = { 0.8, 0.8, 0.8, 0.8 };
+
+      /* Horizontal */
+      gtk_snapshot_append_color (snapshot, &c,
+                                 &GRAPHENE_RECT_INIT (0, y - 0.5, width, 1));
+      /* Vertical */
+      gtk_snapshot_append_color (snapshot, &c,
+                                 &GRAPHENE_RECT_INIT (x - 0.5, 0, 1, height));
     }
-
-  cairo_destroy (cr);
 }
 
 static void


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