[PATCH 5/9] clock: binary: no need to calculate offset

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


It's easy from the rows and cols.

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

diff --git a/plugins/clock/clock-binary.c b/plugins/clock/clock-binary.c
index d41debd5..5852ec34 100644
--- a/plugins/clock/clock-binary.c
+++ b/plugins/clock/clock-binary.c
@@ -265,7 +265,6 @@ xfce_clock_binary_draw_true_binary (XfceClockBinary *binary,
   gint              row, rows;
   static gint       binary_table[] = { 32, 16, 8, 4, 2, 1 };
   gint              col, cols;
-  gint              offset_x, offset_y;
   gint              w, h;
   gint              ticks;
   GtkStyleContext  *ctx;
@@ -285,10 +284,7 @@ xfce_clock_binary_draw_true_binary (XfceClockBinary *binary,
   w = alloc->width / cols;
   h = alloc->height / rows;
 
-  /* init sizes */
-  offset_y = alloc->y;
-
-  for (row = 0; row < rows; row++, offset_y += h)
+  for (row = 0; row < rows; row++)
     {
       /* get the time this row represents */
       if (row == 0)
@@ -298,10 +294,7 @@ xfce_clock_binary_draw_true_binary (XfceClockBinary *binary,
       else
         ticks = g_date_time_get_second (time);
 
-      /* reset sizes */
-      offset_x = alloc->x;
-
-      for (col = 0; col < cols; col++, offset_x += w)
+      for (col = 0; col < cols; col++)
         {
           if (ticks >= binary_table[col])
             {
@@ -318,7 +311,7 @@ xfce_clock_binary_draw_true_binary (XfceClockBinary *binary,
             }
 
           /* draw the dot */
-          cairo_rectangle (cr, offset_x, offset_y, w - 1, h - 1);
+          cairo_rectangle (cr, alloc->x + col * w, alloc->y + row * h, w - 1, h - 1);
           cairo_fill (cr);
         }
     }
@@ -338,7 +331,6 @@ xfce_clock_binary_draw_binary (XfceClockBinary *binary,
   gint              row, rows;
   gint              col, cols;
   gint              digit;
-  gint              offset_x, offset_y;
   gint              w, h;
   gint              ticks = 0;
   GtkStyleContext  *ctx;
@@ -359,9 +351,7 @@ xfce_clock_binary_draw_binary (XfceClockBinary *binary,
   w = alloc->width / cols;
   h = alloc->height / rows;
 
-  offset_x = alloc->x;
-
-  for (col = 0; col < cols; col++, offset_x += w)
+  for (col = 0; col < cols; col++)
     {
       /* get the time this row represents */
       if (col == 0)
@@ -371,10 +361,7 @@ xfce_clock_binary_draw_binary (XfceClockBinary *binary,
       else if (col == 4)
         ticks = g_date_time_get_second (time);
 
-      /* reset sizes */
-      offset_y = alloc->y;
-
-      for (row = 0; row < rows; row++, offset_y += h)
+      for (row = 0; row < rows; row++)
         {
           digit = row + (4 * (col % 2));
           if (ticks >= binary_table[digit])
@@ -392,7 +379,7 @@ xfce_clock_binary_draw_binary (XfceClockBinary *binary,
             }
 
           /* draw the dot */
-          cairo_rectangle (cr, offset_x, offset_y, w - 1, h - 1);
+          cairo_rectangle (cr, alloc->x + col * w, alloc->y + row * h, w - 1, h - 1);
           cairo_fill (cr);
         }
     }
-- 
2.22.0.rc2.dirty



More information about the Xfce4-dev mailing list