gimp r26718 - in trunk: . libgimpwidgets



Author: neo
Date: Fri Aug 22 21:30:33 2008
New Revision: 26718
URL: http://svn.gnome.org/viewvc/gimp?rev=26718&view=rev

Log:
2008-08-22  Sven Neumann  <sven gimp org>

	* libgimpwidgets/gimpscrolledpreview.[ch]: draw the navigation
	popup using Cairo, just as we do it in the core now.



Modified:
   trunk/ChangeLog
   trunk/libgimpwidgets/gimpscrolledpreview.c
   trunk/libgimpwidgets/gimpscrolledpreview.h

Modified: trunk/libgimpwidgets/gimpscrolledpreview.c
==============================================================================
--- trunk/libgimpwidgets/gimpscrolledpreview.c	(original)
+++ trunk/libgimpwidgets/gimpscrolledpreview.c	Fri Aug 22 21:30:33 2008
@@ -33,7 +33,6 @@
 
 
 #define POPUP_SIZE  100
-#define PEN_WIDTH     3
 
 
 typedef struct
@@ -76,16 +75,13 @@
                                                             GdkEventButton           *event,
                                                             GimpScrolledPreview      *preview);
 
-static void      gimp_scrolled_preview_nav_popup_realize   (GtkWidget                *widget,
-                                                            GimpScrolledPreview      *preview);
-static void      gimp_scrolled_preview_nav_popup_unrealize (GtkWidget                *widget,
-                                                            GimpScrolledPreview      *preview);
 static gboolean  gimp_scrolled_preview_nav_popup_event     (GtkWidget                *widget,
                                                             GdkEvent                 *event,
                                                             GimpScrolledPreview      *preview);
 static gboolean  gimp_scrolled_preview_nav_popup_expose    (GtkWidget                *widget,
                                                             GdkEventExpose           *event,
                                                             GimpScrolledPreview      *preview);
+
 static void      gimp_scrolled_preview_set_cursor          (GimpPreview              *preview);
 
 
@@ -595,12 +591,6 @@
 
       gtk_container_add (GTK_CONTAINER (inner), area);
 
-      g_signal_connect (area, "realize",
-                        G_CALLBACK (gimp_scrolled_preview_nav_popup_realize),
-                        preview);
-      g_signal_connect (area, "unrealize",
-                        G_CALLBACK (gimp_scrolled_preview_nav_popup_unrealize),
-                        preview);
       g_signal_connect (area, "event",
                         G_CALLBACK (gimp_scrolled_preview_nav_popup_event),
                         preview);
@@ -649,32 +639,6 @@
   return TRUE;
 }
 
-static void
-gimp_scrolled_preview_nav_popup_realize (GtkWidget           *widget,
-                                         GimpScrolledPreview *preview)
-{
-  if (! preview->nav_gc)
-    {
-      preview->nav_gc = gdk_gc_new (widget->window);
-
-      gdk_gc_set_function (preview->nav_gc, GDK_INVERT);
-      gdk_gc_set_line_attributes (preview->nav_gc,
-                                  PEN_WIDTH,
-                                  GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_ROUND);
-    }
-}
-
-static void
-gimp_scrolled_preview_nav_popup_unrealize (GtkWidget           *widget,
-                                           GimpScrolledPreview *preview)
-{
-  if (preview->nav_gc)
-    {
-      g_object_unref (preview->nav_gc);
-      preview->nav_gc = NULL;
-    }
-}
-
 static gboolean
 gimp_scrolled_preview_nav_popup_event (GtkWidget           *widget,
                                        GdkEvent            *event,
@@ -744,10 +708,12 @@
                                         GimpScrolledPreview *preview)
 {
   GtkAdjustment *adj;
+  GdkColor      *color;
+  cairo_t       *cr;
   gdouble        x, y;
   gdouble        w, h;
 
-  adj = gtk_range_get_adjustment (GTK_RANGE (preview->hscr));
+  adj   = gtk_range_get_adjustment (GTK_RANGE (preview->hscr));
 
   x = adj->value / (adj->upper - adj->lower);
   w = adj->page_size / (adj->upper - adj->lower);
@@ -760,16 +726,38 @@
   if (w >= 1.0 && h >= 1.0)
     return FALSE;
 
-  gdk_gc_set_clip_rectangle (preview->nav_gc, &event->area);
+  x = floor (x * (gdouble) widget->allocation.width);
+  y = floor (y * (gdouble) widget->allocation.height);
+  w = MAX (1, ceil (w * (gdouble) widget->allocation.width));
+  h = MAX (1, ceil (h * (gdouble) widget->allocation.height));
+
+  cr = gdk_cairo_create (widget->window);
+
+  gdk_cairo_region (cr, event->region);
+  cairo_clip (cr);
+
+  cairo_rectangle (cr,
+                   0, 0, widget->allocation.width, widget->allocation.height);
+
+  cairo_rectangle (cr, x, y, w, h);
+
+  color = &widget->style->fg[widget->state];
+  cairo_set_source_rgba (cr,
+                         color->red   / 65535.,
+                         color->green / 65535.,
+                         color->blue  / 65535., 0.5);
+
+  cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
+  cairo_fill (cr);
+
+  cairo_rectangle (cr, x, y, w, h);
+
+  gdk_cairo_set_source_color  (cr, &widget->style->bg[widget->state]);
+
+  cairo_set_line_width (cr, 2);
+  cairo_stroke (cr);
 
-  gdk_draw_rectangle (widget->window, preview->nav_gc,
-                      FALSE,
-                      x * (gdouble) widget->allocation.width  + PEN_WIDTH / 2,
-                      y * (gdouble) widget->allocation.height + PEN_WIDTH / 2,
-                      MAX (1,
-                           ceil (w * widget->allocation.width)  - PEN_WIDTH),
-                      MAX (1,
-                           ceil (h * widget->allocation.height) - PEN_WIDTH));
+  cairo_destroy (cr);
 
   return FALSE;
 }

Modified: trunk/libgimpwidgets/gimpscrolledpreview.h
==============================================================================
--- trunk/libgimpwidgets/gimpscrolledpreview.h	(original)
+++ trunk/libgimpwidgets/gimpscrolledpreview.h	Fri Aug 22 21:30:33 2008
@@ -50,7 +50,7 @@
   GtkWidget    *nav_icon;
   GtkWidget    *nav_popup;
   GdkCursor    *cursor_move;
-  GdkGC        *nav_gc;
+  GdkGC        *nav_gc; /* unused */
 
   /*< private >*/
   gpointer      priv;



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