[dia] grid: actually use hex_size, update prefrences to set it



commit 2823cd06645090d5096c4ee99bbb825d0c5c8413
Author: Zander Brown <zbrown gnome org>
Date:   Thu Oct 3 15:24:28 2019 +0100

    grid: actually use hex_size, update prefrences to set it
    
    Fix https://gitlab.gnome.org/GNOME/dia/issues/421

 app/diagram.c                |  3 +--
 app/diagrid.h                |  2 +-
 app/grid.c                   | 19 ++++++++++++++-----
 app/preferences.c            |  2 +-
 app/preferences.h            |  8 ++++----
 data/ui/properties-dialog.ui |  9 +++++----
 6 files changed, 26 insertions(+), 17 deletions(-)
---
diff --git a/app/diagram.c b/app/diagram.c
index 6515c8e8..44f3ccac 100644
--- a/app/diagram.c
+++ b/app/diagram.c
@@ -239,8 +239,7 @@ dia_diagram_init (Diagram *self)
 
   self->grid.width_x = prefs.grid.x;
   self->grid.width_y = prefs.grid.y;
-  self->grid.width_w = prefs.grid.w;
-  self->grid.hex_size = 1.0;
+  self->grid.hex_size = prefs.grid.hex_size;
   self->grid.colour = prefs.new_diagram.grid_color;
   self->grid.hex = prefs.grid.hex;
   self->grid.visible_x = prefs.grid.vis_x;
diff --git a/app/diagrid.h b/app/diagrid.h
index 3239d71e..0f3edbcc 100644
--- a/app/diagrid.h
+++ b/app/diagrid.h
@@ -5,7 +5,7 @@ typedef struct _DiaGrid DiaGrid;
 
 struct _DiaGrid  {
   /* grid line intervals */
-  real width_x, width_y, width_w;
+  real width_x, width_y;
   /* the interval between visible grid lines */
   guint visible_x, visible_y;
   /* the interval between major lines (non-stippled).
diff --git a/app/grid.c b/app/grid.c
index 9bc2c121..49648347 100644
--- a/app/grid.c
+++ b/app/grid.c
@@ -181,6 +181,16 @@ grid_draw_hex (DDisplay *ddisp, DiaRectangle *update, real length)
   int to_x, to_y, x, y;
   DiaRenderer *renderer = ddisp->renderer;
 
+  /*
+   * Let's not lock up the app trying to draw a invisible grid
+   *
+   * Assumption: We don't support increments smaller than 0.1 thus < 0.1 is 0
+   * whilst allowing for floating point quirks
+   */
+  if (length < 0.1) {
+    return;
+  }
+
   /* First horizontal lines: */
   vert_pos = ceil( update->top / (length * sqrt(3)) ) * length * sqrt(3);
   while (vert_pos <= update->bottom) {
@@ -293,20 +303,19 @@ grid_draw (DDisplay *ddisp, DiaRectangle *update)
     /* distance between visible grid lines */
     real width_x = ddisp->diagram->grid.width_x;
     real width_y = ddisp->diagram->grid.width_y;
-    real width_w = ddisp->diagram->grid.width_w;
     if (ddisp->diagram->grid.dynamic) {
       calculate_dynamic_grid(ddisp, &width_x, &width_y);
     } else {
       width_x = ddisp->diagram->grid.width_x *
-       ddisp->diagram->grid.visible_x;
+                ddisp->diagram->grid.visible_x;
       width_y = ddisp->diagram->grid.width_y *
-       ddisp->diagram->grid.visible_y;
+                ddisp->diagram->grid.visible_y;
     }
 
     dia_renderer_set_linewidth (renderer, 0.0);
 
     if (ddisp->diagram->grid.hex) {
-      grid_draw_hex (ddisp, update, width_w);
+      grid_draw_hex (ddisp, update, ddisp->diagram->grid.hex_size);
     } else {
       if (ddisplay_transform_length (ddisp, width_y) >= 2.0 &&
           ddisplay_transform_length (ddisp, width_x) >= 2.0) {
@@ -373,7 +382,7 @@ snap_to_grid (DDisplay *ddisp, coord *x, coord *y)
 {
   if (ddisp->grid.snap) {
     if (ddisp->diagram->grid.hex) {
-      real width_x = ddisp->diagram->grid.width_w;
+      real width_x = ddisp->diagram->grid.hex_size;
       real x_mod = (*x - 1 * width_x) - floor ((*x - 1 * width_x) / (3 * width_x)) * 3 * width_x;
       real y_mod = (*y - 0.25 * sqrt (3) * width_x) -
         floor ((*y - 0.25 * sqrt (3) * width_x) / (sqrt (3) * width_x)) * sqrt (3) * width_x;
diff --git a/app/preferences.c b/app/preferences.c
index e22042cb..34183447 100644
--- a/app/preferences.c
+++ b/app/preferences.c
@@ -241,7 +241,7 @@ DiaPrefData prefs_data[] =
   { "grid_colour", PREF_COLOUR, PREF_OFFSET(new_diagram.grid_color), &default_colour, GRID_TAB, N_("Color:") 
},
   { "grid_major", PREF_UINT, PREF_OFFSET(grid.major_lines), &default_major_lines, GRID_TAB, N_("Lines per 
major line") },
   { "grid_hex", PREF_BOOLEAN, PREF_OFFSET(grid.hex), &default_false, GRID_TAB, N_("Hex grid") },
-  { "grid_w", PREF_UREAL, PREF_OFFSET(grid.w), &default_real_one, GRID_TAB, N_("Hex Size:") },
+  { "grid_hex_size", PREF_UREAL, PREF_OFFSET(grid.hex_size), &default_real_one, GRID_TAB, N_("Hex Size:") },
   /*  { "grid_solid", PREF_BOOLEAN, PREF_OFFSET(grid.solid), &default_true, 3, N_("Solid lines:") },  */
 
   { "fixed_icon_size", PREF_BOOLEAN,PREF_OFFSET(fixed_icon_size),
diff --git a/app/preferences.h b/app/preferences.h
index 8665f08b..663a208c 100644
--- a/app/preferences.h
+++ b/app/preferences.h
@@ -35,9 +35,9 @@ struct DiaPreferences {
     int vis_y;
     int major_lines;
     int hex;
-    real w;
+    real hex_size;
   } grid;
-  
+
   struct {
     int width;
     int height;
@@ -58,7 +58,7 @@ struct DiaPreferences {
 
   gchar* length_unit;
   gchar* fontsize_unit;
-  
+
   struct {
     int visible;
     int solid;
@@ -69,7 +69,7 @@ struct DiaPreferences {
   int toolbox_on_top;
 
   int use_integrated_ui;
-  
+
   /* a dedicated filter name or NULL */
   struct {
     char *png;
diff --git a/data/ui/properties-dialog.ui b/data/ui/properties-dialog.ui
index ebc8b5a8..2b31becd 100644
--- a/data/ui/properties-dialog.ui
+++ b/data/ui/properties-dialog.ui
@@ -3,21 +3,21 @@
   <requires lib="gtk+" version="2.24"/>
   <!-- interface-naming-policy project-wide -->
   <object class="GtkAdjustment" id="hex_size">
-    <property name="upper">100</property>
+    <property name="upper">10</property>
     <property name="value">1</property>
-    <property name="step_increment">1</property>
+    <property name="step_increment">0.1</property>
     <property name="page_increment">10</property>
   </object>
   <object class="GtkAdjustment" id="spacing_x">
     <property name="upper">10</property>
     <property name="value">1</property>
-    <property name="step_increment">0.10000000000000001</property>
+    <property name="step_increment">0.1</property>
     <property name="page_increment">10</property>
   </object>
   <object class="GtkAdjustment" id="spacing_y">
     <property name="upper">10</property>
     <property name="value">1</property>
-    <property name="step_increment">0.10000000000000001</property>
+    <property name="step_increment">0.1</property>
     <property name="page_increment">10</property>
   </object>
   <object class="GtkAdjustment" id="vis_spacing_x">
@@ -277,6 +277,7 @@
             <property name="primary_icon_sensitive">True</property>
             <property name="secondary_icon_sensitive">True</property>
             <property name="adjustment">hex_size</property>
+            <property name="digits">1</property>
             <property name="numeric">True</property>
           </object>
           <packing>


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