[gimp] app: make GimpCurveView's cursor label look pretty for 0..100 ranges



commit 262d312dfcf3ca6ddb1300d94a7f8cac8b0893d0
Author: Michael Natterer <mitch gimp org>
Date:   Thu Dec 26 16:33:59 2013 +0100

    app: make GimpCurveView's cursor label look pretty for 0..100 ranges
    
    and generally clean up the cursor label code a bit.

 app/widgets/gimpcurveview.c |  103 +++++++++++++++++++++----------------------
 1 files changed, 51 insertions(+), 52 deletions(-)
---
diff --git a/app/widgets/gimpcurveview.c b/app/widgets/gimpcurveview.c
index c72aed2..b0e5c21 100644
--- a/app/widgets/gimpcurveview.c
+++ b/app/widgets/gimpcurveview.c
@@ -645,14 +645,24 @@ gimp_curve_view_expose (GtkWidget      *widget,
                      border + height - 1);
       cairo_stroke (cr);
 
-      /*  stupid heuristic: special-case for 0..255  */
       if (view->range_x_max == 255.0)
         {
+          /*  stupid heuristic: special-case for 0..255  */
+
           g_snprintf (buf, sizeof (buf), "x:%3d",
                       (gint) (view->xpos *
                               (view->range_x_max - view->range_x_min) +
                               view->range_x_min));
         }
+      else if (view->range_x_max == 100.0)
+        {
+          /*  and for 0..100  */
+
+          g_snprintf (buf, sizeof (buf), "x:%0.2f",
+                      view->xpos *
+                      (view->range_x_max - view->range_x_min) +
+                      view->range_x_min);
+        }
       else
         {
           g_snprintf (buf, sizeof (buf), "x:%0.3f",
@@ -681,50 +691,17 @@ gimp_curve_view_expose (GtkWidget      *widget,
   if (view->cursor_x >= 0.0 && view->cursor_x <= 1.0 &&
       view->cursor_y >= 0.0 && view->cursor_y <= 1.0)
     {
-      gchar buf[32];
-      gint  w, h;
+      gchar  buf[32];
+      gint   w, h;
 
       if (! view->cursor_layout)
-        {
-          /*  stupid heuristic: special-case for 0..255  */
-          if (view->range_x_max == 255.0 &&
-              view->range_y_max == 255.0)
-            {
-              view->cursor_layout =
-                gtk_widget_create_pango_layout (widget, "x:888 y:888");
-            }
-          else
-            {
-              view->cursor_layout =
-                gtk_widget_create_pango_layout (widget, "x:0.888 y:0.888");
-            }
-
-          pango_layout_get_pixel_extents (view->cursor_layout,
-                                          NULL, &view->cursor_rect);
-        }
+        view->cursor_layout = gtk_widget_create_pango_layout (widget, NULL);
 
-      x = border * 2 + 3;
-      y = border * 2 + 3;
-      w = view->cursor_rect.width;
-      h = view->cursor_rect.height;
-
-      if (view->x_axis_label)
-        x += border + view->cursor_rect.height; /* coincidentially the right value */
-
-      cairo_push_group (cr);
-
-      gdk_cairo_set_source_color (cr, &style->text[GTK_STATE_NORMAL]);
-      cairo_rectangle (cr, x + 0.5, y + 0.5, w, h);
-      cairo_fill_preserve (cr);
-
-      cairo_set_line_width (cr, 6);
-      cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
-      cairo_stroke (cr);
-
-      /*  stupid heuristic: special-case for 0..255  */
       if (view->range_x_max == 255.0 &&
           view->range_y_max == 255.0)
         {
+          /*  stupid heuristic: special-case for 0..255  */
+
           g_snprintf (buf, sizeof (buf), "x:%3d y:%3d",
                       (gint) (view->cursor_x *
                               (view->range_x_max - view->range_x_min) +
@@ -733,6 +710,19 @@ gimp_curve_view_expose (GtkWidget      *widget,
                               (view->range_y_max - view->range_y_min) +
                               view->range_y_min));
         }
+      else if (view->range_x_max == 100.0 &&
+               view->range_y_max == 100.0)
+        {
+          /*  and for 0..100  */
+
+          g_snprintf (buf, sizeof (buf), "x:%0.2f y:%0.2f",
+                      view->cursor_x *
+                      (view->range_x_max - view->range_x_min) +
+                      view->range_x_min,
+                      (1.0 - view->cursor_y) *
+                      (view->range_y_max - view->range_y_min) +
+                      view->range_y_min);
+        }
       else
         {
           g_snprintf (buf, sizeof (buf), "x:%0.3f y:%0.3f",
@@ -745,9 +735,28 @@ gimp_curve_view_expose (GtkWidget      *widget,
         }
 
       pango_layout_set_text (view->cursor_layout, buf, -1);
+      pango_layout_get_pixel_extents (view->cursor_layout,
+                                      NULL, &view->cursor_rect);
 
-      gdk_cairo_set_source_color (cr, &style->base[GTK_STATE_NORMAL]);
+      x = border * 2 + 3;
+      y = border * 2 + 3;
+      w = view->cursor_rect.width;
+      h = view->cursor_rect.height;
+
+      if (view->x_axis_label)
+        x += border + view->cursor_rect.height; /* coincidentially the right value */
+
+      cairo_push_group (cr);
 
+      gdk_cairo_set_source_color (cr, &style->text[GTK_STATE_NORMAL]);
+      cairo_rectangle (cr, x + 0.5, y + 0.5, w, h);
+      cairo_fill_preserve (cr);
+
+      cairo_set_line_width (cr, 6);
+      cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
+      cairo_stroke (cr);
+
+      gdk_cairo_set_source_color (cr, &style->base[GTK_STATE_NORMAL]);
       cairo_move_to (cr, x, y);
       pango_cairo_show_layout (cr, view->cursor_layout);
 
@@ -1346,12 +1355,6 @@ gimp_curve_view_set_range_x (GimpCurveView *view,
   view->range_x_min = min;
   view->range_x_max = max;
 
-  if (view->cursor_layout)
-    {
-      g_object_unref (view->cursor_layout);
-      view->cursor_layout = NULL;
-    }
-
   gtk_widget_queue_draw (GTK_WIDGET (view));
 }
 
@@ -1365,12 +1368,6 @@ gimp_curve_view_set_range_y (GimpCurveView *view,
   view->range_y_min = min;
   view->range_y_max = max;
 
-  if (view->cursor_layout)
-    {
-      g_object_unref (view->cursor_layout);
-      view->cursor_layout = NULL;
-    }
-
   gtk_widget_queue_draw (GTK_WIDGET (view));
 }
 
@@ -1428,6 +1425,7 @@ gimp_curve_view_set_cursor (GimpCurveView *view,
   view->cursor_x = x;
   view->cursor_y = y;
 
+  /* TODO: only invalidate the cursor label area */
   gtk_widget_queue_draw (GTK_WIDGET (view));
 }
 
@@ -1437,5 +1435,6 @@ gimp_curve_view_unset_cursor (GimpCurveView *view)
   view->cursor_x = -1.0;
   view->cursor_y = -1.0;
 
+  /* TODO: only invalidate the cursor label area */
   gtk_widget_queue_draw (GTK_WIDGET (view));
 }


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