gimp r25248 - in trunk: . app/display app/widgets



Author: neo
Date: Wed Mar 26 19:25:55 2008
New Revision: 25248
URL: http://svn.gnome.org/viewvc/gimp?rev=25248&view=rev

Log:
2008-03-26  Sven Neumann  <sven gimp org>

	* app/widgets/gimpcairo-wilber.[ch]: 
	* app/display/gimpcanvas.c (gimp_canvas_draw_drop_zone): hide 
ugly
	details behind a sane API.



Modified:
   trunk/ChangeLog
   trunk/app/display/gimpcanvas.c
   trunk/app/widgets/gimpcairo-wilber.c
   trunk/app/widgets/gimpcairo-wilber.h

Modified: trunk/app/display/gimpcanvas.c
==============================================================================
--- trunk/app/display/gimpcanvas.c	(original)
+++ trunk/app/display/gimpcanvas.c	Wed Mar 26 19:25:55 2008
@@ -828,61 +828,40 @@
 gimp_canvas_draw_drop_zone (GimpCanvas *canvas,
                             cairo_t    *cr)
 {
-  static gint wilber_x      = 0;
-  static gint wilber_y      = 0;
-  static gint wilber_width  = 0;
-  static gint wilber_height = 0;
-
   GtkWidget *widget = GTK_WIDGET (canvas);
-  gint       width;
-  gint       height;
-  gint       side;
+  gdouble    wilber_width;
+  gdouble    wilber_height;
+  gdouble    width;
+  gdouble    height;
+  gdouble    side;
   gdouble    factor;
 
-  /* first get the extents */
-  if (! wilber_width)
-    {
-      cairo_t *foo = gdk_cairo_create (widget->window);
-      gdouble  x1, y1;
-      gdouble  x2, y2;
-
-      gimp_cairo_wilber (foo);
-      cairo_fill_extents (foo, &x1, &y1, &x2, &y2);
-      cairo_destroy (foo);
-
-      wilber_x      = x1;
-      wilber_y      = y1;
-      wilber_width  = (x2 - x1) / 2;
-      wilber_height = (y2 - y1) / 2;
-    }
+  gimp_cairo_wilber_get_size (cr, &wilber_width, &wilber_height);
 
-  side = MIN (MIN (widget->allocation.width,
-                   widget->allocation.height),
-              MAX (widget->allocation.width,
-                   widget->allocation.height) / 2);
+  wilber_width  /= 2;
+  wilber_height /= 2;
+
+  side = MIN (MIN (widget->allocation.width, widget->allocation.height),
+              MAX (widget->allocation.width, widget->allocation.height) / 2);
 
   width  = MAX (wilber_width,  side);
   height = MAX (wilber_height, side);
 
-  factor = MIN ((gdouble) width  / wilber_width,
-                (gdouble) height / wilber_height);
+  factor = MIN (width / wilber_width, height / wilber_height);
 
   cairo_scale (cr, factor, factor);
 
   /*  magic factors depend on the image used, everything else is generic
    */
-  cairo_translate (cr,
-                   - wilber_width * 0.6 - wilber_x,
-                   widget->allocation.height / factor
-                   - wilber_height * 1.1 - wilber_y);
-
-  gimp_cairo_wilber (cr);
+  gimp_cairo_wilber (cr,
+                     - wilber_width * 0.6,
+                     widget->allocation.height / factor - wilber_height * 1.1);
 
   cairo_set_source_rgba (cr,
                          widget->style->fg[widget->state].red   / 65535.0,
                          widget->style->fg[widget->state].green / 65535.0,
                          widget->style->fg[widget->state].blue  / 65535.0,
-                         0.2);
+                         0.15);
   cairo_fill (cr);
 }
 

Modified: trunk/app/widgets/gimpcairo-wilber.c
==============================================================================
--- trunk/app/widgets/gimpcairo-wilber.c	(original)
+++ trunk/app/widgets/gimpcairo-wilber.c	Wed Mar 26 19:25:55 2008
@@ -33,20 +33,75 @@
 #include <gimpcairo-wilber.h>
 
 
+/* This string is a path description as found in SVG files.  You can
+ * use Inkscape to create the SVG file, then copy the path from it.
+ * It works best if you combine all paths into one. Inkscape has a
+ * function to do that.
+ */
 static const gchar wilber_path[] =
   "M 509.72445,438.68864 C 501.47706,469.77945 464.95038,491.54566 431.85915,497.74874 C 438.5216,503.01688 442.87782,511.227 442.87782,520.37375 C 442.87783,536.24746 429.95607,549.0223 414.08235,549.0223 C 398.20863,549.0223 385.28688,536.24746 385.28688,520.37375 C 385.28688,511.52403 389.27666,503.61286 395.57098,498.3364 C 359.36952,495.90384 343.70976,463.95812 343.70975,463.95814 L 342.68134,509.64891 C 342.68134,514.35021 342.08391,519.96098 340.18378,528.3072 C 339.84664,527.80364 339.51399,527.33515 339.15537,526.83804 C 330.25511,514.5011 317.25269,507.81431 306.39317,508.76741 C 302.77334,509.08511 299.47017,510.33348 296.54982,512.4403 C 284.86847,520.86757 284.97665,540.94721 296.84366,557.3965 C 306.96274,571.42287 322.32232,578.25612 333.8664,574.73254 C 391.94635,615.17624 532.16931,642.41915 509.72445,438.68864 z M 363.24953,501.1278 C 373.83202,501.12778 382.49549,509.79127 382.49549,520.37375 C 382.49549,530.95624 373.83201,539.47279 363.24953,539.47279 C
  352.66706,539.47279 344.1505,530.95624 344.1505,520.37375 C 344.15049,509.79129 352.66706,501.1278 363.24953,501.1278 z M 305.80551,516.1132 C 311.68466,516.11318 316.38344,521.83985 316.38344,528.89486 C 316.38345,535.94982 311.68467,541.67652 305.80551,541.67652 C 299.92636,541.67652 295.08067,535.94987 295.08067,528.89486 C 295.08065,521.83985 299.92636,516.1132 305.80551,516.1132 z M 440.821,552.54828 C 440.821,552.54828 448.7504,554.02388 453.8965,559.45332 C 457.41881,563.16951 457.75208,569.15506 456.98172,577.37703 C 456.21143,573.8833 454.89571,571.76659 453.8965,569.29666 C 443.01388,582.47662 413.42981,583.08929 376.0312,569.88433 C 416.63248,578.00493 437.38806,570.56014 449.48903,561.2163 C 446.29383,557.08917 440.821,552.54828 440.821,552.54828 z M 434.64723,524.59684 C 434.64723,532.23974 428.44429,538.44268 420.80139,538.44268 C 413.15849,538.44268 406.95555,532.23974 406.95555,524.59684 C 406.95555,516.95394 413.15849,510.751 420.80139,510.751 C 428.44429,5
 10.751 434.64723,516.95394 434.64723,524.59684 z M 378.00043,522.99931 C 378.00043,527.70264 374.18324,531.51984 369.47991,531.51984 C 364.77658,531.51984 360.95939,527.70264 360.95939,522.99931 C 360.95939,518.29599 364.77658,514.47879 369.47991,514.47879 C 374.18324,514.47879 378.00043,518.29599 378.00043,522.99931 z ";
 
-static void  parse_path_data (cairo_t     *cr,
-                              const gchar *data);
+static gboolean wilber_extents_known = FALSE;
+static gdouble  wilber_x1, wilber_y1;
+static gdouble  wilber_x2, wilber_y2;
+
+
+static void  wilber_parse_path_data (cairo_t     *cr,
+                                     const gchar *data);
+static void  wilber_get_extents     (cairo_t     *cr);
+
+
+/**
+ * gimp_cairo_wilber:
+ * @cr: Cairo context
+ *
+ * Draw a Wilber path at position @x, @y.
+ */
+void
+gimp_cairo_wilber (cairo_t *cr,
+                   gdouble  x,
+                   gdouble  y)
+{
+  wilber_get_extents (cr);
+
+  cairo_save (cr);
+
+  cairo_translate (cr, x - wilber_x1, y - wilber_y1);
+  wilber_parse_path_data (cr, wilber_path);
 
+  cairo_restore (cr);
+}
 
 void
-gimp_cairo_wilber (cairo_t *cr)
+gimp_cairo_wilber_get_size (cairo_t *cr,
+                            gdouble *width,
+                            gdouble *height)
 {
-  parse_path_data (cr, wilber_path);
+  wilber_get_extents (cr);
+
+  *width  = wilber_x2 - wilber_x1;
+  *height = wilber_y2 - wilber_y1;
 }
 
 
+static void
+wilber_get_extents (cairo_t *cr)
+{
+  if (! wilber_extents_known)
+    {
+      cairo_save (cr);
+
+      wilber_parse_path_data (cr, wilber_path);
+
+      cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
+      cairo_fill_extents (cr, &wilber_x1, &wilber_y1, &wilber_x2, &wilber_y2);
+
+      cairo_restore (cr);
+
+      wilber_extents_known = TRUE;
+    }
+}
+
 /**********************************************************/
 /*  Below is the code that parses the actual path data.   */
 /*                                                        */
@@ -73,8 +128,8 @@
 
 
 static void
-parse_path_data (cairo_t     *cr,
-                 const gchar *data)
+wilber_parse_path_data (cairo_t     *cr,
+                        const gchar *data)
 {
   ParsePathContext ctx;
 

Modified: trunk/app/widgets/gimpcairo-wilber.h
==============================================================================
--- trunk/app/widgets/gimpcairo-wilber.h	(original)
+++ trunk/app/widgets/gimpcairo-wilber.h	Wed Mar 26 19:25:55 2008
@@ -26,7 +26,12 @@
 #define __GIMP_CAIRO_WILBER_H__
 
 
-void gimp_cairo_wilber (cairo_t *cr);
+void  gimp_cairo_wilber          (cairo_t *cr,
+                                  gdouble  x,
+                                  gdouble  y);
+void  gimp_cairo_wilber_get_size (cairo_t *cr,
+                                  gdouble *width,
+                                  gdouble *height);
 
 
 #endif /* __GIMP_CAIRO_WILBER_H__ */



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