From a0e43a027e6d918ae566e3c438695717f4ed9bba Mon Sep 17 00:00:00 2001 From: Niv Sardi Date: Fri, 8 Jun 2007 16:01:54 +0200 Subject: fix makefile --- cairo-test.c | 170 +++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 118 insertions(+), 52 deletions(-) (limited to 'cairo-test.c') diff --git a/cairo-test.c b/cairo-test.c index b82b39d..7b0d507 100644 --- a/cairo-test.c +++ b/cairo-test.c @@ -2,8 +2,9 @@ #include #include #include -#include -#include + +#include +#include #define SECOND_INTERVAL 1000 @@ -13,11 +14,31 @@ typedef struct { - gboolean active; /* whether the selection is active or not */ - gdouble x, y; + gboolean active; /* whether the selection is active or not */ + gdouble x, y; } selection_t; +typedef struct +{ + float r; + float g; + float b; + float a; +} color_t; + +static gboolean time_handler (GtkWidget* w) +{ + if (GTK_IS_WIDGET(w)) { + gdk_window_scroll (w->window, -20, 0); + printf("Moving.\n"); + gtk_widget_queue_draw (w); + return TRUE; + } else { + _exit(-1); + return FALSE; + } +} gboolean on_key_press (GtkWidget *widget, GdkEventKey *key, @@ -88,72 +109,115 @@ static void paint_dot (cairo_t *cr, selection_t *sel) { } +void paint_rounded_box (cairo_t *cr, float x, float y, + float w, float h, + color_t *o, color_t *f, + float c) +{ + gint t, i; + + cairo_save (cr); + cairo_translate (cr, x, y); + if (f) cairo_set_source_rgba (cr, f->r, f->g, f->b, f->a); + cairo_move_to (cr, - w/2, - h/2 + c); + + for ( i = 0; i < 4; i++ ) { + cairo_translate (cr, -w/2.0, -h/2.0); + + cairo_curve_to (cr, 0.0, c, 0.0, 0.0, c, 0.0); + cairo_line_to (cr, w - c, 0.0); + + cairo_translate (cr, w/2.0, h/2.0); + cairo_rotate (cr, M_PI/2.0); + t = w; w = h; h = t; + } + + if (f) cairo_fill_preserve (cr); + cairo_set_source_rgba (cr, o->r, o->g, o->b, o->a); + cairo_stroke (cr); + cairo_restore (cr); +} + +void paint_rect (cairo_t *cr, float x, float y, + float w, float h, + color_t *o, color_t *f) +{ + cairo_save (cr); + cairo_translate (cr, x, y); + if (f) cairo_set_source_rgba (cr, f->r, f->g, f->b, f->a); + cairo_rectangle (cr, -w/2, -h/2, w, h); + if (f) cairo_fill_preserve (cr); + cairo_set_source_rgba (cr, o->r, o->g, o->b, o->a); + cairo_stroke (cr); + cairo_restore (cr); +} + + +void paint_clock_dot (cairo_t *cr, float x, float y, + float w, float h, + color_t *c) +{ + color_t back_o = { 0.0f, 0.0f, 0.0f, 1.0f }; + + /* paint_rounded_box (cr, x, y, w, h, &back_o, c, 5);*/ + paint_rect (cr, x, y, w, h, &back_o, c); +} + static void paint (GtkWidget *widget, GdkEventExpose *eev, selection_t *sel) { - gint width, height, cache; + gint width, height; cairo_t *cr; - gint i; - gchar d[2] = {'0','\0'}; - gfloat colors[6][3] = {{0.0f, 0.0f, 1.0f}, - {0.0f, 1.0f, 0.0f}, - {1.0f, 0.0f, 0.0f}, - {1.0f, 1.0f, 0.0f}, - {1.0f, 0.0f, 1.0f}, - {0.0f, 1.0f, 1.1f}}; - + cairo_surface_t *surface; + gint i, j; + + time_t now; + struct tm *tm; + + int timet[3]; + + color_t color[] = {{ 1.0f, 0.0f, 0.0f, 0.6f }, + { 0.0f, 1.0f, 0.0f, 0.6f }, + { 0.0f, 0.0f, 1.0f, 0.6f }}; + + now = time(NULL); + tm = localtime(&now); + + timet[0] = tm->tm_hour; + timet[1] = tm->tm_min; + timet[2] = tm->tm_sec; + width = widget->allocation.width; height = widget->allocation.height; cr = gdk_cairo_create (widget->window); + + surface = cairo_get_target (cr); cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); cairo_set_source_rgba (cr, 1.0f, 1.0f, 1.0f, 0.4f); cairo_paint (cr); - cairo_select_font_face (cr, "Sans", CAIRO_FONT_SLANT_NORMAL, - CAIRO_FONT_WEIGHT_BOLD); - - for (i = 0; i < 6; i++) { - cairo_save (cr); - cairo_set_font_size (cr, 10); - cairo_set_source_rgba (cr, colors[i][0], - colors[i][1], - colors[i][2], - 1.0f); - cairo_move_to (cr, 10*i, 10); - d[0] = '0' + i; - cairo_show_text (cr, d); - cairo_restore (cr); - } - - - cairo_save (cr); - cairo_set_source_rgba (cr, 1.0f, 1.0f, 0.0f, 1.0f); - cairo_move_to (cr, 10, 20); - cairo_translate (cr, width/2, height/2); - - - for ( i = 0; i < 4; i++ ) { - cairo_translate (cr, -width/2, -height/2); - - cairo_curve_to (cr, 10, 20, 10, 10, 20, 10); - cairo_line_to (cr, width - 20, 10); - - cairo_translate (cr, width/2, height/2); - cairo_rotate (cr, M_PI/2.0); - cache = width; width = height; height = cache; + for (i = 0; i < 3; i++) { + for (j = 0; j < 6; j++) { + paint_clock_dot (cr, (width/7)*(6-j) , (height/4)*(i+1), + (width/8), (height/5), + (((timet[i])>>j)&0x1)?&color[i]:NULL); + } } - cairo_fill_preserve (cr); - cairo_set_source_rgba (cr, 0.0f, 1.0f, 0.0f, 0.4f); - cairo_stroke (cr); - cairo_restore (cr); - + /* + cairo_set_source_surface (cr, surface, 0, -5); + cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); + cairo_rectangle (cr, 0, 0, width, height -5); + cairo_fill (cr); + */ + paint_dot (cr, sel); - cairo_destroy (cr); + /* cairo_destroy (cr); */ } + static void install_colormap (GtkWidget *w) { GdkScreen* screen = gtk_widget_get_screen (w); GdkColormap* colormap = gdk_screen_get_rgba_colormap (screen); @@ -217,6 +281,8 @@ gint main (gint argc, gchar **argv) { G_CALLBACK (on_mouse_motion), &sel); + g_timeout_add (SECOND_INTERVAL/4, (GtkFunction) time_handler, window); + gtk_widget_show_all (window); gtk_main (); -- cgit v1.2.3