[PATCH 6/9] clock: binary: cleanup grid draw

Felipe Contreras felipe.contreras at gmail.com
Fri Jun 14 02:40:41 CEST 2019


No need to recalculate everything.

Signed-off-by: Felipe Contreras <felipe.contreras at gmail.com>
---
 plugins/clock/clock-binary.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/plugins/clock/clock-binary.c b/plugins/clock/clock-binary.c
index 5852ec34..6f785013 100644
--- a/plugins/clock/clock-binary.c
+++ b/plugins/clock/clock-binary.c
@@ -397,8 +397,7 @@ xfce_clock_binary_draw (GtkWidget *widget,
   gint              col, cols;
   gint              row, rows;
   GtkAllocation     alloc;
-  gdouble           remain_w, x;
-  gdouble           remain_h, y;
+  gdouble           x, y;
   gint              w, h;
   gint              pad_x, pad_y;
   gint              diff;
@@ -441,28 +440,25 @@ xfce_clock_binary_draw (GtkWidget *widget,
       gdk_cairo_set_source_rgba (cr, &grid_rgba);
       cairo_set_line_width (cr, 1);
 
-      remain_w = alloc.width;
-      remain_h = alloc.height;
+      w = alloc.width / cols;
+      h = alloc.height / rows;
+
       x = alloc.x - 0.5;
       y = alloc.y - 0.5;
 
       cairo_rectangle (cr, x, y, alloc.width, alloc.height);
       cairo_stroke (cr);
 
-      for (col = 0; col < cols - 1; col++)
+      for (col = 1; col < cols; col++)
         {
-          w = remain_w / (cols - col);
-          x += w; remain_w -= w;
-          cairo_move_to (cr, x, alloc.y);
+          cairo_move_to (cr, x + col * w, alloc.y);
           cairo_rel_line_to (cr, 0, alloc.height);
           cairo_stroke (cr);
         }
 
-      for (row = 0; row < rows - 1; row++)
+      for (row = 1; row < rows; row++)
         {
-          h = remain_h / (rows - row);
-          y += h; remain_h -= h;
-          cairo_move_to (cr, alloc.x, y);
+          cairo_move_to (cr, alloc.x, y + row * h);
           cairo_rel_line_to (cr, alloc.width, 0);
           cairo_stroke (cr);
         }
-- 
2.22.0.rc2.dirty



More information about the Xfce4-dev mailing list