[gimp] libgimpwidgets: ports GimpColorSelect marker drawing to cairo



commit 1770615125e489e7477ad50f748892eef8fc8494
Author: Michael Natterer <mitch gimp org>
Date:   Sat Sep 11 22:24:08 2010 +0200

    libgimpwidgets: ports GimpColorSelect marker drawing to cairo

 libgimpwidgets/gimpcolorselect.c |  183 +++++++++++---------------------------
 1 files changed, 53 insertions(+), 130 deletions(-)
---
diff --git a/libgimpwidgets/gimpcolorselect.c b/libgimpwidgets/gimpcolorselect.c
index fa23bdd..b516a1a 100644
--- a/libgimpwidgets/gimpcolorselect.c
+++ b/libgimpwidgets/gimpcolorselect.c
@@ -116,7 +116,6 @@ struct _GimpColorSelect
 
   ColorSelectFillType  z_color_fill;
   ColorSelectFillType  xy_color_fill;
-  GdkGC               *gc;
 
   ColorSelectDragMode  drag_mode;
 };
@@ -144,8 +143,6 @@ struct _ColorSelectFill
 };
 
 
-static void   gimp_color_select_unrealize       (GtkWidget          *widget);
-
 static void   gimp_color_select_togg_visible    (GimpColorSelector  *selector,
                                                  gboolean            visible);
 static void   gimp_color_select_togg_sensitive  (GimpColorSelector  *selector,
@@ -196,11 +193,6 @@ static void   gimp_color_select_image_fill      (GtkWidget          *widget,
                                                  const GimpHSV      *hsv,
                                                  const GimpRGB      *rgb);
 
-static void   gimp_color_select_draw_z_marker   (GimpColorSelect    *select,
-                                                 GdkRectangle       *clip);
-static void   gimp_color_select_draw_xy_marker  (GimpColorSelect    *select,
-                                                 GdkRectangle       *clip);
-
 static void   color_select_update_red              (ColorSelectFill *csf);
 static void   color_select_update_green            (ColorSelectFill *csf);
 static void   color_select_update_blue             (ColorSelectFill *csf);
@@ -240,11 +232,8 @@ static const ColorSelectFillUpdateProc update_procs[] =
 static void
 gimp_color_select_class_init (GimpColorSelectClass *klass)
 {
-  GtkWidgetClass         *widget_class   = GTK_WIDGET_CLASS (klass);
   GimpColorSelectorClass *selector_class = GIMP_COLOR_SELECTOR_CLASS (klass);
 
-  widget_class->unrealize               = gimp_color_select_unrealize;
-
   selector_class->name                  = "GIMP";
   selector_class->help_id               = "gimp-colorselector-gimp";
   selector_class->stock_id              = GIMP_STOCK_WILBER;
@@ -262,7 +251,6 @@ gimp_color_select_init (GimpColorSelect *select)
 
   select->z_color_fill  = COLOR_SELECT_HUE;
   select->xy_color_fill = COLOR_SELECT_SATURATION_VALUE;
-  select->gc            = NULL;
   select->drag_mode     = DRAG_NONE;
 
   hbox = gtk_hbox_new (FALSE, 4);
@@ -368,20 +356,6 @@ gimp_color_select_init (GimpColorSelect *select)
 }
 
 static void
-gimp_color_select_unrealize (GtkWidget *widget)
-{
-  GimpColorSelect *select = GIMP_COLOR_SELECT (widget);
-
-  if (select->gc)
-    {
-      g_object_unref (select->gc);
-      select->gc = NULL;
-    }
-
-  GTK_WIDGET_CLASS (parent_class)->unrealize (widget);
-}
-
-static void
 gimp_color_select_togg_visible (GimpColorSelector *selector,
                                 gboolean           visible)
 {
@@ -644,10 +618,34 @@ gimp_color_select_xy_expose (GtkWidget       *widget,
                              GdkEventExpose  *event,
                              GimpColorSelect *select)
 {
-  if (! select->gc)
-    select->gc = gdk_gc_new (gtk_widget_get_window (widget));
+  GtkAllocation  allocation;
+  cairo_t       *cr;
+  gint           x, y;
+
+  gtk_widget_get_allocation (select->xy_color, &allocation);
+
+  cr = gdk_cairo_create (gtk_widget_get_window (widget));
+  gdk_cairo_region (cr, event->region);
+  cairo_clip (cr);
+
+  x = ((allocation.width - 1) * select->pos[0]) / 255;
+  y = (allocation.height - 1) - ((allocation.height - 1) * select->pos[1]) / 255;
+
+  cairo_move_to (cr, 0,                y + 0.5);
+  cairo_line_to (cr, allocation.width, y + 0.5);
+
+  cairo_move_to (cr, x + 0.5, 0);
+  cairo_line_to (cr, x + 0.5, allocation.height);
 
-  gimp_color_select_draw_xy_marker (select, &event->area);
+  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);
+
+  cairo_destroy (cr);
 
   return TRUE;
 }
@@ -713,8 +711,6 @@ gimp_color_select_xy_events (GtkWidget       *widget,
       return FALSE;
     }
 
-  gimp_color_select_draw_xy_marker (select, NULL);
-
   gtk_widget_get_allocation (select->xy_color, &allocation);
 
   if (allocation.width > 1 && allocation.height > 1)
@@ -726,7 +722,7 @@ gimp_color_select_xy_events (GtkWidget       *widget,
   select->pos[0] = CLAMP (select->pos[0], 0, 255);
   select->pos[1] = CLAMP (select->pos[1], 0, 255);
 
-  gimp_color_select_draw_xy_marker (select, NULL);
+  gtk_widget_queue_draw (select->xy_color);
 
   gimp_color_select_update (select, UPDATE_VALUES | UPDATE_CALLER);
 
@@ -749,10 +745,30 @@ gimp_color_select_z_expose (GtkWidget       *widget,
                             GdkEventExpose  *event,
                             GimpColorSelect *select)
 {
-  if (! select->gc)
-    select->gc = gdk_gc_new (gtk_widget_get_window (widget));
+  GtkAllocation  allocation;
+  cairo_t       *cr;
+  gint           y;
+
+  gtk_widget_get_allocation (widget, &allocation);
+
+  cr = gdk_cairo_create (gtk_widget_get_window (widget));
+  gdk_cairo_region (cr, event->region);
+  cairo_clip (cr);
+
+  y = (allocation.height - 1) - ((allocation.height - 1) * select->pos[2]) / 255;
+
+  cairo_move_to (cr, 0,                y + 0.5);
+  cairo_line_to (cr, allocation.width, y + 0.5);
+
+  cairo_set_line_width (cr, 3.0);
+  cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.6);
+  cairo_stroke_preserve (cr);
 
-  gimp_color_select_draw_z_marker (select, &event->area);
+  cairo_set_line_width (cr, 1.0);
+  cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 0.8);
+  cairo_stroke (cr);
+
+  cairo_destroy (cr);
 
   return TRUE;
 }
@@ -815,8 +831,6 @@ gimp_color_select_z_events (GtkWidget       *widget,
       return FALSE;
     }
 
-  gimp_color_select_draw_z_marker (select, NULL);
-
   gtk_widget_get_allocation (select->z_color, &allocation);
 
   if (allocation.height > 1)
@@ -824,7 +838,8 @@ gimp_color_select_z_events (GtkWidget       *widget,
 
   select->pos[2] = CLAMP (select->pos[2], 0, 255);
 
-  gimp_color_select_draw_z_marker (select, NULL);
+  gtk_widget_queue_draw (select->z_color);
+
   gimp_color_select_update (select,
                             UPDATE_VALUES | UPDATE_XY_COLOR | UPDATE_CALLER);
 
@@ -869,98 +884,6 @@ gimp_color_select_image_fill (GtkWidget           *preview,
 }
 
 static void
-gimp_color_select_draw_z_marker (GimpColorSelect *select,
-                                 GdkRectangle    *clip)
-{
-  GtkAllocation allocation;
-  gint          width;
-  gint          height;
-  gint          y;
-  gint          minx;
-  gint          miny;
-
-  if (! select->gc)
-    return;
-
-  gtk_widget_get_allocation (select->z_color, &allocation);
-
-  width  = allocation.width;
-  height = allocation.height;
-
-  if (width < 1 || height < 1)
-    return;
-
-  y = (height - 1) - ((height - 1) * select->pos[2]) / 255;
-
-  minx = 0;
-  miny = 0;
-
-  if (clip)
-    {
-      width  = MIN (width,  clip->x + clip->width);
-      height = MIN (height, clip->y + clip->height);
-      minx   = MAX (0, clip->x);
-      miny   = MAX (0, clip->y);
-    }
-
-  if (y >= miny && y < height)
-    {
-      gdk_gc_set_function (select->gc, GDK_INVERT);
-      gdk_draw_line (gtk_widget_get_window (select->z_color),
-                     select->gc, minx, y, width - 1, y);
-      gdk_gc_set_function (select->gc, GDK_COPY);
-    }
-}
-
-static void
-gimp_color_select_draw_xy_marker (GimpColorSelect *select,
-                                  GdkRectangle    *clip)
-{
-  GtkAllocation allocation;
-  gint          width;
-  gint          height;
-  gint          x, y;
-  gint          minx, miny;
-
-  if (! select->gc)
-    return;
-
-  gtk_widget_get_allocation (select->xy_color, &allocation);
-
-  width  = allocation.width;
-  height = allocation.height;
-
-  if (width < 1 || height < 1)
-    return;
-
-  x = ((width - 1) * select->pos[0]) / 255;
-  y = (height - 1) - ((height - 1) * select->pos[1]) / 255;
-
-  minx = 0;
-  miny = 0;
-
-  gdk_gc_set_function (select->gc, GDK_INVERT);
-
-  if (clip)
-    {
-      width  = MIN (width,  clip->x + clip->width);
-      height = MIN (height, clip->y + clip->height);
-      minx   = MAX (0, clip->x);
-      miny   = MAX (0, clip->y);
-    }
-
-  if (y >= miny && y < height)
-    gdk_draw_line (gtk_widget_get_window (select->xy_color),
-                   select->gc, minx, y, width - 1, y);
-
-  if (x >= minx && x < width)
-    gdk_draw_line (gtk_widget_get_window (select->xy_color),
-                   select->gc, x, miny, x, height - 1);
-
-  gdk_gc_set_function (select->gc, GDK_COPY);
-}
-
-static void
 color_select_update_red (ColorSelectFill *csf)
 {
   guchar *p;



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