Author: nick Date: 2008-08-10 13:50:58 +0000 (Sun, 10 Aug 2008) New Revision: 27442
Modified: xfce4-panel/trunk/plugins/clock/clock-lcd.c Log: * Fix drawing a of the lcd clock, improve rounding and some code improvements (readability). Modified: xfce4-panel/trunk/plugins/clock/clock-lcd.c =================================================================== --- xfce4-panel/trunk/plugins/clock/clock-lcd.c 2008-08-10 13:37:37 UTC (rev 27441) +++ xfce4-panel/trunk/plugins/clock/clock-lcd.c 2008-08-10 13:50:58 UTC (rev 27442) @@ -31,7 +31,9 @@ #include "clock.h" #include "clock-lcd.h" -#define RELATIVE_SPACE 0.10 +#define RELATIVE_SPACE (0.10) +#define RELATIVE_DIGIT (0.50) +#define RELATIVE_DOTS (3 * RELATIVE_SPACE) @@ -295,7 +297,7 @@ size = widget->allocation.height - widget->allocation.height % 10; /* make sure we also fit on small vertical panels */ - size = MIN (floor ((gdouble) widget->allocation.width / ratio), size); + size = MIN (rint ((gdouble) widget->allocation.width / ratio), size); /* begin offsets */ offset_x = rint ((widget->allocation.width - (size * ratio)) / 2.00); @@ -392,8 +394,8 @@ /* get the local time */ xfce_clock_util_get_localtime (&tm); - /* hour + minutes */ - ratio = (3 * 0.5 + 6 * RELATIVE_SPACE); + /* 8:88 */ + ratio = (3 * RELATIVE_DIGIT) + RELATIVE_DOTS + RELATIVE_SPACE; ticks = tm.tm_hour; @@ -401,13 +403,13 @@ ticks -= 12; if (ticks >= 10) - ratio += (0.5 + RELATIVE_SPACE); + ratio += RELATIVE_DIGIT + RELATIVE_SPACE; if (clock->show_seconds) - ratio += (2 * 0.5 + 4 * RELATIVE_SPACE); + ratio += (2 * RELATIVE_DIGIT) + RELATIVE_SPACE + RELATIVE_DOTS; if (clock->show_meridiem) - ratio += (0.5 + RELATIVE_SPACE); + ratio += RELATIVE_DIGIT + RELATIVE_SPACE; return ratio; } @@ -422,10 +424,20 @@ { gint i; - /* draw the dots */ - for (i = 1; i < 3; i++) - cairo_rectangle (cr, offset_x, offset_y + size * 0.30 * i, - size * 0.10, size * 0.10); + if (size >= 10) + { + /* draw the dots (with rounding) */ + for (i = 1; i < 3; i++) + cairo_rectangle (cr, rint (offset_x), rint (offset_y + size * RELATIVE_DOTS * i), + rint (size * RELATIVE_SPACE), rint (size * RELATIVE_SPACE)); + } + else + { + /* draw the dots */ + for (i = 1; i < 3; i++) + cairo_rectangle (cr, offset_x, offset_y + size * RELATIVE_DOTS * i, + size * RELATIVE_SPACE, size * RELATIVE_SPACE); + } /* fill the dots */ cairo_fill (cr); @@ -445,24 +457,32 @@ gint i, j; gint segment; gdouble x, y; + gdouble rel_x, rel_y; g_return_val_if_fail (number >= 0 || number <= 11, offset_x); + /* ##1## + * 6 2 + * ##7## + * 5 3 + * ##4## + */ + /* coordicates to draw for each segment */ - gdouble segments_x[][6] = { { 0.02, 0.48, 0.38, 0.12, -1.0, 0.00 }, - { 0.40, 0.50, 0.50, 0.40, -1.0, 0.00 }, - { 0.40, 0.50, 0.50, 0.40, -1.0, 0.00 }, - { 0.12, 0.38, 0.48, 0.02, -1.0, 0.00 }, - { 0.00, 0.10, 0.10, 0.00, -1.0, 0.00 }, - { 0.00, 0.10, 0.10, 0.00, -1.0, 0.00 }, - { 0.00, 0.10, 0.40, 0.50, 0.40, 0.10 } }; - gdouble segments_y[][6] = { { 0.00, 0.00, 0.10, 0.10, -1.0, 0.00 }, - { 0.12, 0.02, 0.48, 0.43, -1.0, 0.00 }, - { 0.57, 0.52, 0.98, 0.88, -1.0, 0.00 }, - { 0.90, 0.90, 1.00, 1.00, -1.0, 0.00 }, - { 0.52, 0.57, 0.88, 0.98, -1.0, 0.00 }, - { 0.02, 0.12, 0.43, 0.48, -1.0, 0.00 }, - { 0.50, 0.45, 0.45, 0.50, 0.55, 0.55 } }; + gdouble segments_x[][6] = { { 0.02, 0.48, 0.38, 0.12, -1.0, 0.00 }, /* 1x */ + { 0.40, 0.505, 0.505, 0.40, -1.0, 0.00 }, /* 2x */ + { 0.40, 0.505, 0.505, 0.40, -1.0, 0.00 }, /* 3x */ + { 0.12, 0.38, 0.48, 0.02, -1.0, 0.00 }, /* 4x */ + { 0.00, 0.105, 0.105, 0.00, -1.0, 0.00 }, /* 5x */ + { 0.00, 0.105, 0.105, 0.00, -1.0, 0.00 }, /* 6x */ + { 0.00, 0.10, 0.40, 0.50, 0.40, 0.10 } }; /* 7x */ + gdouble segments_y[][6] = { { 0.00, 0.00, 0.105, 0.105, -1.0, 0.00 }, /* 1y */ + { 0.12, 0.02, 0.48, 0.43, -1.0, 0.00 }, /* 2y */ + { 0.57, 0.52, 0.98, 0.88, -1.0, 0.00 }, /* 3y */ + { 0.90, 0.90, 1.00, 1.00, -1.0, 0.00 }, /* 4y */ + { 0.52, 0.57, 0.88, 0.98, -1.0, 0.00 }, /* 5y */ + { 0.02, 0.12, 0.43, 0.48, -1.0, 0.00 }, /* 6y */ + { 0.50, 0.445, 0.445, 0.50, 0.55, 0.55 } }; /* 7y */ /* segment to draw for each number: 0, 1, ..., 9, A, P */ gint numbers[][8] = { { 0, 1, 2, 3, 4, 5, -1 }, @@ -490,21 +510,25 @@ /* walk through the coordinate points */ for (j = 0; j < 6; j++) { + /* get the relative sizes */ + rel_x = segments_x[segment][j]; + rel_y = segments_y[segment][j]; + + /* leave when there are no valid coordinates */ + if (rel_x == -1.00 || rel_y == -1.00) + break; + /* get x and y coordinates for this point */ - x = segments_x[segment][j] * size + offset_x; - y = segments_y[segment][j] * size + offset_y; + x = rel_x * size + offset_x; + y = rel_y * size + offset_y; /* when 0.01 * size is larger then 1, round the numbers */ if (size >= 10) { - x = floor (x); - y = floor (y); + x = rint (x); + y = rint (y); } - /* leave when there are no valid coordinates */ - if (x < offset_x || y < offset_y) - break; - if (G_UNLIKELY (j == 0)) cairo_move_to (cr, x, y); else @@ -518,7 +542,7 @@ /* fill the segments */ cairo_fill (cr); - return (offset_x + size * (0.50 + RELATIVE_SPACE)); + return (offset_x + size * (RELATIVE_DIGIT + RELATIVE_SPACE)); } _______________________________________________ Xfce4-commits mailing list Xfce4-commits@xfce.org http://foo-projects.org/mailman/listinfo/xfce4-commits