summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2003-12-02 08:24:06 +0000
committerKeith Packard <keithp@keithp.com>2003-12-02 08:24:06 +0000
commit6a0cd3687a50c9ad02218afbc2c3376a89eedacc (patch)
tree61d812f217a6f6bbd5d4c489badc903940aa6fc6
parent5e917a62dda3db0f87371d7aff645e14ab132a68 (diff)
Add '-a' ratio to preserve 1-1 aspect ratio.
Make hands look more like physical clock.
-rw-r--r--ChangeLog9
-rw-r--r--fdclock.c38
-rw-r--r--fdhand.c68
3 files changed, 82 insertions, 33 deletions
diff --git a/ChangeLog b/ChangeLog
index e6df35e..97ad3c2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2003-12-02 Keith Packard <keithp@keithp.com>
+
+ * fdclock.c: (main_x), (main):
+ Add '-a' ratio to preserve 1-1 aspect ratio.
+
+ * fdhand.c: (draw_hour), (draw_minute), (draw_second), (draw_hand),
+ (draw_time):
+ Make hands look more like physical clock.
+
2003-12-01 Keith Packard <keithp@keithp.com>
* fdclock.c: (main_x):
diff --git a/fdclock.c b/fdclock.c
index 3bb2b5b..5b4a039 100644
--- a/fdclock.c
+++ b/fdclock.c
@@ -112,7 +112,7 @@ make_background (Display *dpy, Window root, int width, int height, int depth,
}
void
-main_x (char *dpy_name, char *geom, Bool seconds, Bool translucent)
+main_x (char *dpy_name, char *geom, Bool seconds, Bool translucent, Bool square)
{
Display *dpy;
int scr;
@@ -229,6 +229,7 @@ main_x (char *dpy_name, char *geom, Bool seconds, Bool translucent)
XFreePixmap (dpy, background);
background = None;
}
+ XClearArea (dpy, w, 0, 0, 0, 0, False);
paint = True;
}
break;
@@ -240,24 +241,36 @@ main_x (char *dpy_name, char *geom, Bool seconds, Bool translucent)
if (paint)
{
cairo_surface_t *buffer_surface;
+ int x_off = 0, y_off = 0;
+ int u_width = width, u_height = height;
+ if (square)
+ {
+ if (width < height)
+ u_width = u_height = width;
+ else
+ u_width = u_height = height;
+ x_off = (width - u_width) / 2;
+ y_off = (height - u_height) / 2;
+ }
/*
* Create a pixmap holding the background clock image
* so it doesn't have to be painted every tick
*/
if (!background)
- background = make_background (dpy, root, width, height, depth,
- visual, cmap);
+ background = make_background (dpy, root, u_width, u_height, depth,
+ visual, cmap);
buffer = XCreatePixmap (dpy, root,
- width, height, depth);
+ u_width, u_height, depth);
buffer_surface = cairo_xlib_surface_create (dpy, buffer,
visual, 0, cmap);
cairo_set_target_surface (cr, buffer_surface);
XCopyArea (dpy, background, buffer, gc,
- 0, 0, width, height, 0, 0);
- fdhand_draw_now (cr, width, height, seconds);
- XCopyArea (dpy, buffer, w, gc, 0, 0, width, height, 0, 0);
+ 0, 0, u_width, u_height, 0, 0);
+ fdhand_draw_now (cr, u_width, u_height, seconds);
+ XCopyArea (dpy, buffer, w, gc,
+ 0, 0, u_width, u_height, x_off, y_off);
cairo_surface_destroy (buffer_surface);
XFreePixmap (dpy, buffer);
paint = False;
@@ -273,10 +286,10 @@ main (int argc, char **argv)
{
char *dpy_name = 0;
char *geom = 0;
- Bool seconds = False, translucent = False;
+ Bool seconds = False, translucent = False, square = False;
int c;
- while ((c = getopt (argc, argv, "std:g:")) > 0)
+ while ((c = getopt (argc, argv, "stad:g:")) > 0)
{
switch (c) {
case 'd':
@@ -291,13 +304,16 @@ main (int argc, char **argv)
case 't':
translucent = True;
break;
+ case 'a':
+ square = True;
+ break;
default:
- fprintf (stderr, "usage: %s -st -d <dpy> -g <geom>\n", argv[0]);
+ fprintf (stderr, "usage: %s -sta -d <dpy> -g <geom>\n", argv[0]);
exit (1);
break;
}
}
- main_x (dpy_name, geom, seconds, translucent);
+ main_x (dpy_name, geom, seconds, translucent, square);
return 0;
}
diff --git a/fdhand.c b/fdhand.c
index 6751199..7b7247c 100644
--- a/fdhand.c
+++ b/fdhand.c
@@ -30,44 +30,65 @@
#define PI_6 (M_PI/6.0)
static void
-draw_hand_helper (cairo_t *cr, double width, double length, int draw_disc)
+draw_hour (cairo_t *cr, double width, double length)
{
double r = width / 2;
cairo_move_to (cr, length, -r);
- cairo_arc (cr, length, 0, r, -M_PI_2, M_PI_2);
- if (draw_disc)
- {
- cairo_line_to (cr, width * M_SQRT2, r);
- cairo_arc (cr, 0, 0, r*2, PI_6, M_PI - PI_6);
- }
- cairo_line_to (cr, -length / 10, r);
- cairo_arc (cr, -length / 10, 0, r, M_PI_2, -M_PI_2);
- if (draw_disc)
- {
- cairo_line_to (cr, -width * M_SQRT2, -r);
- cairo_arc (cr, 0, 0, r*2, M_PI + PI_6, -PI_6);
- }
+ cairo_arc (cr, length, 0, r, -M_PI_2, M_PI_2);
+ cairo_line_to (cr, width * M_SQRT2, r);
+ cairo_arc (cr, 0, 0, r*2, PI_6, - PI_6);
+ cairo_close_path (cr);
+}
+
+static void
+draw_minute (cairo_t *cr, double width, double length)
+{
+ double r = width / 2;
+ cairo_move_to (cr, length, -r);
+ cairo_arc (cr, length, 0, r, -M_PI_2, M_PI_2);
+ cairo_line_to (cr, 0, r);
+ cairo_line_to (cr, 0, -r);
+ cairo_close_path (cr);
+}
+
+static void
+draw_second (cairo_t *cr, double width, double length)
+{
+ double r = width / 2;
+ double thick = width;
+ double back = length / 3;
+ double back_thin = length / 10;
+
+ cairo_move_to (cr, length, -r);
+ cairo_arc (cr, length, 0, r, -M_PI_2, M_PI_2);
+ cairo_line_to (cr, -back_thin, r);
+ cairo_line_to (cr, -back_thin, thick);
+ cairo_line_to (cr, -back, thick);
+ cairo_line_to (cr, -back, -thick);
+ cairo_line_to (cr, -back_thin, -thick);
+ cairo_line_to (cr, -back_thin, -r);
cairo_close_path (cr);
}
static void
-draw_hand (cairo_t *cr, double angle, double width, double length, double alt, int draw_disc)
+draw_hand (cairo_t *cr, double angle, double width, double length, double alt,
+ void (*draw) (cairo_t *cr, double width, double length))
{
cairo_save (cr);
{
- cairo_translate (cr, alt, alt);
+ cairo_translate (cr, alt/2, alt);
cairo_rotate (cr, angle);
- draw_hand_helper (cr, width, length, draw_disc);
+ (*draw) (cr, width, length);
cairo_set_rgb_color (cr, 0, 0, 0);
- cairo_set_alpha (cr, 0.5);
+ cairo_set_alpha (cr, 0.3);
cairo_fill (cr);
}
cairo_restore (cr);
cairo_save (cr);
{
cairo_rotate (cr, angle);
+ (*draw) (cr, width, length);
cairo_set_rgb_color (cr, 0, 0, 0);
- draw_hand_helper (cr, width, length, draw_disc);
cairo_fill (cr);
}
cairo_restore (cr);
@@ -90,10 +111,13 @@ draw_time (cairo_t *cr, double width, double height, struct timeval *tv, int sec
{
cairo_scale (cr, width, height);
cairo_translate (cr, 0.5, 0.5);
- draw_hand (cr, hour_angle * M_PI / 180.0 - M_PI_2, 0.03, 0.25, 0.005, 1);
- draw_hand (cr, minute_angle * M_PI / 180.0 - M_PI_2, 0.02, 0.4, 0.010, 0);
+ draw_hand (cr, hour_angle * M_PI / 180.0 - M_PI_2,
+ 0.03, 0.25, 0.010, draw_hour);
+ draw_hand (cr, minute_angle * M_PI / 180.0 - M_PI_2,
+ 0.015, 0.39, 0.020, draw_minute);
if (seconds)
- draw_hand (cr, second_angle * M_PI / 180.0 - M_PI_2, 0.01, 0.3, 0.015, 0);
+ draw_hand (cr, second_angle * M_PI / 180.0 - M_PI_2,
+ 0.0075, 0.32, 0.026, draw_second);
}
cairo_restore (cr);
}