From 755b158250b1e0cc3af9a9e10dc469ddd3099eca Mon Sep 17 00:00:00 2001 From: Niv Sardi Date: Sun, 24 Dec 2006 01:57:59 +0100 Subject: Pre hack --- Makefile | 6 ++-- cairo-test | Bin 19956 -> 23170 bytes cairo-test.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 96 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 4236499..a3576aa 100644 --- a/Makefile +++ b/Makefile @@ -2,10 +2,10 @@ APPS = \ cairo-test \ von-wait -CFLAGS = -g -Wall +CFLAGS = -ggdb -Wall -CFLAGS += `pkg-config gtk+-2.0 --cflags` -LDFLAGS += `pkg-config gtk+-2.0 --libs` +CFLAGS += `pkg-config gtk+-2.0 librsvg-2.0 --cflags ` +LDFLAGS += `pkg-config gtk+-2.0 librsvg-2.0 --libs` all: $(APPS) diff --git a/cairo-test b/cairo-test index 14c7555..3e7da3f 100755 Binary files a/cairo-test and b/cairo-test differ diff --git a/cairo-test.c b/cairo-test.c index f5b2272..b82b39d 100644 --- a/cairo-test.c +++ b/cairo-test.c @@ -2,6 +2,8 @@ #include #include #include +#include +#include #define SECOND_INTERVAL 1000 @@ -9,7 +11,17 @@ #define DEFAULT_HEIGHT 100 -gboolean on_key_press (GtkWidget *widget, GdkEventKey *key, gpointer p) { +typedef struct +{ + gboolean active; /* whether the selection is active or not */ + gdouble x, y; +} selection_t; + + + +gboolean on_key_press (GtkWidget *widget, + GdkEventKey *key, + gpointer p) { if (key->type == GDK_KEY_PRESS) { switch (key->keyval) @@ -23,7 +35,60 @@ gboolean on_key_press (GtkWidget *widget, GdkEventKey *key, gpointer p) { return FALSE; } -static void paint (GtkWidget *widget, GdkEventExpose *eev, gpointer p) { +gboolean on_mouse_press (GtkWidget *widget, + GdkEventButton *bev, + selection_t *sel) { + sel->active = TRUE; + + sel->x = bev->x; + sel->y = bev->y; + + gtk_widget_queue_draw (widget); + + return TRUE; +} + +gboolean on_mouse_release (GtkWidget *widget, + GdkEventButton *bev, + selection_t *sel) { + + sel->active = FALSE; + + sel->x = 0; + sel->y = 0; + + gtk_widget_queue_draw (widget); + + return TRUE; +} + +gboolean on_mouse_motion (GtkWidget *widget, + GdkEventButton *bev, + selection_t *sel) { + sel->x = bev->x; + sel->y = bev->y; + + gtk_widget_queue_draw (widget); + + return TRUE; +} + +static void paint_dot (cairo_t *cr, selection_t *sel) { + if (!sel->active) + return; + + cairo_save (cr); + cairo_arc (cr, sel->x, sel->y, 30., 0., 2 * M_PI); + cairo_set_source_rgba (cr, 0, 0, 0, 0.2); + cairo_fill_preserve (cr); + + cairo_set_source_rgba (cr, 0, 0, 0, 0.5); + cairo_stroke (cr); + cairo_restore (cr); + +} + +static void paint (GtkWidget *widget, GdkEventExpose *eev, selection_t *sel) { gint width, height, cache; cairo_t *cr; gint i; @@ -83,6 +148,8 @@ static void paint (GtkWidget *widget, GdkEventExpose *eev, gpointer p) { cairo_set_source_rgba (cr, 0.0f, 1.0f, 0.0f, 0.4f); cairo_stroke (cr); cairo_restore (cr); + + paint_dot (cr, sel); cairo_destroy (cr); } @@ -99,6 +166,7 @@ static void install_colormap (GtkWidget *w) { gint main (gint argc, gchar **argv) { GtkWidget *window; + selection_t sel = {FALSE, 0, 0,}; gtk_init(&argc, &argv); @@ -121,17 +189,34 @@ gint main (gint argc, gchar **argv) { install_colormap(window); - gtk_widget_add_events (window, GDK_BUTTON_PRESS_MASK); + gtk_widget_add_events (window, GDK_BUTTON_PRESS_MASK | + GDK_BUTTON_MOTION_MASK | + GDK_BUTTON_RELEASE_MASK); g_signal_connect (G_OBJECT (window), "expose-event", G_CALLBACK (paint), - NULL); + &sel); g_signal_connect (G_OBJECT (window), "key-press-event", G_CALLBACK (on_key_press), NULL); + /* connect our rubber banding callbacks, like the paint callback + * we pass the selection as userdata + */ + g_signal_connect (G_OBJECT (window), "button_press_event", + G_CALLBACK (on_mouse_press), + &sel); + + g_signal_connect (G_OBJECT (window), "button_release_event", + G_CALLBACK (on_mouse_release), + &sel); + + g_signal_connect (G_OBJECT (window), "motion_notify_event", + G_CALLBACK (on_mouse_motion), + &sel); + gtk_widget_show_all (window); gtk_main (); @@ -142,3 +227,7 @@ gint main (gint argc, gchar **argv) { + + + + -- cgit v1.2.3