diff options
Diffstat (limited to 'clients')
-rw-r--r-- | clients/eyes.c | 42 |
1 files changed, 32 insertions, 10 deletions
diff --git a/clients/eyes.c b/clients/eyes.c index 69b2fe8..b8218af 100644 --- a/clients/eyes.c +++ b/clients/eyes.c @@ -1,4 +1,6 @@ /* + * 👀 + * * Copyright © 2008 Kristian Høgsberg * Copyright © 2012 Collabora Ltd. * @@ -40,15 +42,26 @@ struct eyes { int width, height; int32_t pointer_x, pointer_y; struct pointer_tracking *pointer_tracking; + + double iris_r, iris_g, iris_b; }; static void -draw_eyeball(cairo_t *cr, int x, int y, int width, int height, int pointer_x, int pointer_y) +pick_color(struct eyes *eyes) +{ + eyes->iris_r = (random() % 50) / 100.0; + eyes->iris_g = (random() % 50) / 100.0; + eyes->iris_b = (random() % 50) / 100.0; +} + +static void +draw_eyeball(struct eyes *eyes, cairo_t *cr, + int x, int y, int width, int height) { cairo_matrix_t transform; double transformed_x, transformed_y; double line_width = 9 * (2. / MAX(width, height)); - double radius = 0.6; + double radius = 0.5; /* Transform coordinate system so the eyeball appears to be a unit * circle centred at (0, 0) @@ -69,8 +82,8 @@ draw_eyeball(cairo_t *cr, int x, int y, int width, int height, int pointer_x, in cairo_stroke(cr); /* Pupil */ - transformed_x = pointer_x; - transformed_y = pointer_y; + transformed_x = eyes->pointer_x; + transformed_y = eyes->pointer_y; cairo_matrix_invert(&transform); cairo_matrix_transform_point (&transform, &transformed_x, &transformed_y); @@ -82,15 +95,19 @@ draw_eyeball(cairo_t *cr, int x, int y, int width, int height, int pointer_x, in transformed_y *= ratio; } - cairo_arc(cr, transformed_x, transformed_y, line_width, 0., 2 * M_PI); + cairo_arc(cr, transformed_x, transformed_y, line_width * 1.5, 0., 2 * M_PI); cairo_set_source_rgba(cr, 0., 0., 0., 1.0); - cairo_fill(cr); + cairo_fill_preserve(cr); + + /* Iris */ + cairo_set_source_rgb(cr, eyes->iris_r, eyes->iris_g, eyes->iris_b); + cairo_stroke(cr); cairo_restore(cr); } static void -draw_stuff(cairo_surface_t *surface, int width, int height, int pointer_x, int pointer_y) +draw_stuff(struct eyes *eyes, cairo_surface_t *surface, int width, int height) { cairo_t *cr; @@ -100,8 +117,8 @@ draw_stuff(cairo_surface_t *surface, int width, int height, int pointer_x, int p cairo_paint(cr); cairo_set_operator(cr, CAIRO_OPERATOR_OVER); - draw_eyeball(cr, 0, 0, width / 2, height, pointer_x, pointer_y); - draw_eyeball(cr, width / 2, 0, width / 2, height, pointer_x, pointer_y); + draw_eyeball(eyes, cr, 0, 0, width / 2, height); + draw_eyeball(eyes, cr, width / 2, 0, width / 2, height); cairo_destroy(cr); } @@ -129,7 +146,7 @@ redraw_handler(struct widget *widget, void *data) return; } - draw_stuff(surface, eyes->width, eyes->height, eyes->pointer_x, eyes->pointer_y); + draw_stuff(eyes, surface, eyes->width, eyes->height); cairo_surface_destroy(surface); } @@ -201,6 +218,10 @@ int main(int argc, char *argv[]) { struct eyes eyes; struct display *d; + struct timeval tv; + + gettimeofday(&tv, NULL); + srandom(tv.tv_usec); d = display_create(argc, argv); if (d == NULL) { @@ -213,6 +234,7 @@ int main(int argc, char *argv[]) eyes.display = d; eyes.window = window_create(d); eyes.widget = window_add_widget(eyes.window, &eyes); + pick_color(&eyes); widget_set_resize_handler(eyes.widget, resize_handler); widget_set_redraw_handler(eyes.widget, redraw_handler); |