[dia] ruler: style updates



commit 3275c1643f53ef54193a12c5f247ece41e899e99
Author: Zander Brown <zbrown gnome org>
Date:   Fri Mar 27 19:48:05 2020 +0000

    ruler: style updates

 app/ruler.c | 162 +++++++++++++++++++++++++++++-------------------------------
 1 file changed, 77 insertions(+), 85 deletions(-)
---
diff --git a/app/ruler.c b/app/ruler.c
index 1a1cb7b5..f56b332f 100644
--- a/app/ruler.c
+++ b/app/ruler.c
@@ -56,96 +56,88 @@ GType dia_ruler_get_type (void);
 
 G_DEFINE_TYPE (DiaRuler, dia_ruler, GTK_TYPE_DRAWING_AREA)
 
+
 static gboolean
 dia_ruler_draw (GtkWidget *widget,
-               cairo_t   *cr)
+                cairo_t   *cr)
 {
-  DiaRuler *ruler = DIA_RULER(widget);
+  DiaRuler *ruler = DIA_RULER (widget);
 
-  if (gtk_widget_is_drawable (widget))
-    {
-      GtkStyle *style = gtk_widget_get_style (widget);
-      PangoLayout *layout;
-      int x, y, dx, dy, width, height;
-      real pos;
-      GtkAllocation alloc;
-
-      layout = gtk_widget_create_pango_layout (widget, "012456789");
-
-      gtk_widget_get_allocation (widget, &alloc);
-      width = alloc.width;
-      height = alloc.height;
-
-      dx = (ruler->orientation == GTK_ORIENTATION_VERTICAL) ? width/3 : 0;
-      dy = (ruler->orientation == GTK_ORIENTATION_HORIZONTAL) ? height/3 : 0;
-
-      gdk_cairo_set_source_color (cr, &style->text[gtk_widget_get_state(widget)]);
-      cairo_set_line_width (cr, 1);
-
-      pos = ruler->lower;
-      for (x = 0, y = 0; x < width && y < height;)
-        {
-         gboolean is_major;
-         int n;
-
-         if (!grid_step (ruler->ddisp, ruler->orientation, &pos,
-                         (ruler->orientation == GTK_ORIENTATION_HORIZONTAL) ? &x : &y,
-                         &is_major))
-           break;
-
-         /* ticks */
-         n = (is_major ? 1 : 2);
-         /* + .5 for pixel aligned lines */
-         cairo_move_to (cr, x + 3*dx + .5, y + 3*dy + .5);
-         cairo_line_to (cr, x + n*dx + .5, y + n*dy + .5);
-         cairo_stroke (cr);
-
-         /* label */
-         if (is_major)
-           {
-             gchar text[G_ASCII_DTOSTR_BUF_SIZE*2];
-
-             g_snprintf (text, sizeof(text)-1, "<small>%g</small>", pos);
-             pango_layout_set_markup (layout, text, -1);
-             pango_layout_context_changed (layout);
-             cairo_save (cr);
-             if (ruler->orientation == GTK_ORIENTATION_VERTICAL)
-               {
-                 cairo_translate (cr, x, y);
-                 cairo_rotate (cr, -G_PI/2.0);
-                 cairo_move_to (cr, 2, 0);
-               }
-             else
-               {
-                 cairo_move_to (cr, x+2, 0);
-               }
-             pango_cairo_show_layout (cr, layout);
-             cairo_restore (cr);
-           }
-       }
-      g_object_unref (layout);
-      /* arrow */
-      if (ruler->position > ruler->lower && ruler->position < ruler->upper)
-       {
-         real pos = ruler->position;
-         if (ruler->orientation == GTK_ORIENTATION_VERTICAL)
-           {
-             ddisplay_transform_coords (ruler->ddisp, 0, pos, &x, &y);
-             cairo_move_to (cr, 3*dx, y);
-             cairo_line_to (cr, 2*dx, y - dx);
-             cairo_line_to (cr, 2*dx, y + dx);
-             cairo_fill (cr);
-           }
-         else
-           {
-             ddisplay_transform_coords (ruler->ddisp, pos, 0, &x, &y);
-             cairo_move_to (cr, x, 3*dy);
-             cairo_line_to (cr, x + dy, 2*dy);
-             cairo_line_to (cr, x - dy, 2*dy);
-             cairo_fill (cr);
-           }
-       }
+  if (gtk_widget_is_drawable (widget)) {
+    GtkStyle *style = gtk_widget_get_style (widget);
+    PangoLayout *layout;
+    int x, y, dx, dy, width, height;
+    real pos;
+    GtkAllocation alloc;
+
+    layout = gtk_widget_create_pango_layout (widget, "012456789");
+
+    gtk_widget_get_allocation (widget, &alloc);
+    width = alloc.width;
+    height = alloc.height;
+
+    dx = (ruler->orientation == GTK_ORIENTATION_VERTICAL) ? width/3 : 0;
+    dy = (ruler->orientation == GTK_ORIENTATION_HORIZONTAL) ? height/3 : 0;
+
+    gdk_cairo_set_source_color (cr, &style->text[gtk_widget_get_state(widget)]);
+    cairo_set_line_width (cr, 1);
+
+    pos = ruler->lower;
+    for (x = 0, y = 0; x < width && y < height;) {
+      gboolean is_major;
+      int n;
+
+      if (!grid_step (ruler->ddisp, ruler->orientation, &pos,
+                      (ruler->orientation == GTK_ORIENTATION_HORIZONTAL) ? &x : &y,
+          &is_major)) {
+        break;
+      }
+
+      /* ticks */
+      n = (is_major ? 1 : 2);
+      /* + .5 for pixel aligned lines */
+      cairo_move_to (cr, x + 3*dx + .5, y + 3*dy + .5);
+      cairo_line_to (cr, x + n*dx + .5, y + n*dy + .5);
+      cairo_stroke (cr);
+
+        /* label */
+      if (is_major) {
+        gchar text[G_ASCII_DTOSTR_BUF_SIZE*2];
+
+        g_snprintf (text, sizeof(text)-1, "<small>%g</small>", pos);
+        pango_layout_set_markup (layout, text, -1);
+        pango_layout_context_changed (layout);
+        cairo_save (cr);
+        if (ruler->orientation == GTK_ORIENTATION_VERTICAL) {
+          cairo_translate (cr, x, y);
+          cairo_rotate (cr, -G_PI/2.0);
+          cairo_move_to (cr, 2, 0);
+        } else {
+          cairo_move_to (cr, x+2, 0);
+        }
+        pango_cairo_show_layout (cr, layout);
+        cairo_restore (cr);
+      }
+    }
+    g_object_unref (layout);
+    /* arrow */
+    if (ruler->position > ruler->lower && ruler->position < ruler->upper) {
+      real r_pos = ruler->position;
+      if (ruler->orientation == GTK_ORIENTATION_VERTICAL) {
+        ddisplay_transform_coords (ruler->ddisp, 0, r_pos, &x, &y);
+        cairo_move_to (cr, 3*dx, y);
+        cairo_line_to (cr, 2*dx, y - dx);
+        cairo_line_to (cr, 2*dx, y + dx);
+        cairo_fill (cr);
+      } else {
+        ddisplay_transform_coords (ruler->ddisp, r_pos, 0, &x, &y);
+        cairo_move_to (cr, x, 3*dy);
+        cairo_line_to (cr, x + dy, 2*dy);
+        cairo_line_to (cr, x - dy, 2*dy);
+        cairo_fill (cr);
+      }
     }
+  }
   return FALSE;
 }
 


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