diff --git a/01_git/astime_x.c b/01_git/astime_x.c index 632742e3bb2422b4ba49ab3d7b1c45f6c867a5d1..465c1b0c7950e91358d06ff52c8e31aef85c870b 100644 --- a/01_git/astime_x.c +++ b/01_git/astime_x.c @@ -135,8 +135,54 @@ void initialize(int argc, char **argv, int iconic, int pushed_in, int no_border); +int DrawCenteredArc(Display *display, + Drawable d, + GC gc, + int x, + int y, + unsigned int width, + unsigned int height, + int angle1, + int angle2); +int FillCenteredArc(Display *display, + Drawable d, + GC gc, + int x, + int y, + unsigned int width, + unsigned int height, + int angle1, + int angle2); /* functions */ +int DrawCenteredArc(Display *display, + Drawable d, + GC gc, + int x, + int y, + unsigned int width, + unsigned int height, + int angle1, + int angle2) +{ + return XDrawArc(display, d, gc, + x - width, y - height, 2 * width, 2 * height, angle1, angle2); +} +int FillCenteredArc(Display *display, + Drawable d, + GC gc, + int x, + int y, + unsigned int width, + unsigned int height, + int angle1, + int angle2) +{ + return XFillArc(display, d, gc, + x - width, y - height, 2 * width, 2 * height, angle1, angle2); +} + + void draw_sunriset(Window win, struct tm *local_time, double lon, @@ -154,16 +200,17 @@ void draw_sunriset(Window win, || type == ASTRO_TWILIGHT || type == SUNRISESET || type == DARKNESS); XSetForeground(mainDisplay, mainGC, color); - x = center.x - (watch_size.x * size); - y = center.y - (watch_size.y * size); - width = watch_size.x * size * 2; - height = watch_size.y * size * 2; + x = center.x; + y = center.y; + width = watch_size.x * size; + height = watch_size.y * size; if (CIVIL_TWILIGHT == type) { int ret; ret = civil_twilight(local_time->tm_year, local_time->tm_mon, local_time->tm_mday, lat, lon, &start, &end); if (1 == ret) { - XFillArc(mainDisplay, win, mainGC, x, x, width, height, 0 * 64, 359 * 64); + FillCenteredArc(mainDisplay, win, mainGC, + x, y, width, height, 0 * 64, 359 * 64); return; } else if (-1 == ret) { return; @@ -173,7 +220,8 @@ void draw_sunriset(Window win, ret = nautical_twilight(local_time->tm_year, local_time->tm_mon, local_time->tm_mday, lat, lon, &start, &end); if (1 == ret) { - XFillArc(mainDisplay, win, mainGC, x, x, width, height, 0 * 64, 359 * 64); + FillCenteredArc(mainDisplay, win, mainGC, + x, y, width, height, 0 * 64, 359 * 64); return; } else if (-1 == ret) { return; @@ -183,7 +231,8 @@ void draw_sunriset(Window win, ret = astronomical_twilight(local_time->tm_year, local_time->tm_mon, local_time->tm_mday, lat, lon, &start, &end); if (1 == ret) { - XFillArc(mainDisplay, win, mainGC, x, x, width, height, 0 * 64, 359 * 64); + FillCenteredArc(mainDisplay, win, mainGC, + x, y, width, height, 0 * 64, 359 * 64); return; } else if (-1 == ret) { return; @@ -193,13 +242,15 @@ void draw_sunriset(Window win, ret = sun_rise_set(local_time->tm_year, local_time->tm_mon, local_time->tm_mday, lat, lon, &start, &end); if (1 == ret) { - XFillArc(mainDisplay, win, mainGC, x, x, width, height, 0 * 64, 359 * 64); + FillCenteredArc(mainDisplay, win, mainGC, + x, y, width, height, 0 * 64, 359 * 64); return; } else if (-1 == ret) { return; } } else if (DARKNESS == type) { - XFillArc(mainDisplay, win, mainGC, x, x, width, height, 0 * 64, 359 * 64); + FillCenteredArc(mainDisplay, win, mainGC, + x, y, width, height, 0 * 64, 359 * 64); return; } angle1 = (int) round(start * 15.0); @@ -210,7 +261,7 @@ void draw_sunriset(Window win, angle1 = (360 - angle1) % 360; angle2 *= -1; } - XFillArc(mainDisplay, win, mainGC, x, x, width, height, + FillCenteredArc(mainDisplay, win, mainGC, x, y, width, height, (360 - angle1 - 90) * 64, -angle2 * 64); }