diff options
author | Jon TURNEY <jon.turney@dronecode.org.uk> | 2012-11-04 00:46:41 +0000 |
---|---|---|
committer | Jon TURNEY <jon.turney@dronecode.org.uk> | 2012-11-04 00:46:41 +0000 |
commit | 3e9135051334624d157ffdbfb79d591859059a26 (patch) | |
tree | 17ee270e2b3fabe238d84fc4aa9804385685358f | |
parent | 21a4ce2d6c607ad6800fa4391fd1f63a02500e9b (diff) |
Add a range of alpha values
Fix redrawing when resized
-rw-r--r-- | alphademo.c | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/alphademo.c b/alphademo.c index 5e19429..49cc616 100644 --- a/alphademo.c +++ b/alphademo.c @@ -22,17 +22,17 @@ int main(int argc, char **argv) { /* boilerplate initialization code */ gtk_init(&argc, &argv); - + GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(window), "Alpha Demo"); g_signal_connect(G_OBJECT(window), "delete-event", gtk_main_quit, NULL); - /* Tell GTK+ that we want to draw the windows background ourself. * If we don't do this then GTK+ will clear the window to the * opaque theme default color, which isn't what we want. */ gtk_widget_set_app_paintable(window, TRUE); + gtk_widget_set_double_buffered(window, FALSE); /* We need to handle two events ourself: "expose-event" and "screen-changed". * @@ -48,6 +48,7 @@ int main(int argc, char **argv) * same features, so we need to check each time. */ + g_signal_connect(G_OBJECT(window), "check-resize", G_CALLBACK(expose), NULL); g_signal_connect(G_OBJECT(window), "expose-event", G_CALLBACK(expose), NULL); g_signal_connect(G_OBJECT(window), "screen-changed", G_CALLBACK(screen_changed), NULL); @@ -95,6 +96,8 @@ static void screen_changed(GtkWidget *widget, GdkScreen *old_screen, gpointer us /* This is called when we need to draw the windows contents */ static gboolean expose(GtkWidget *widget, GdkEventExpose *event, gpointer userdata) { + printf("Exposed\n"); + cairo_t *cr = gdk_cairo_create(widget->window); if (supports_alpha) @@ -106,21 +109,31 @@ static gboolean expose(GtkWidget *widget, GdkEventExpose *event, gpointer userda cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); cairo_paint (cr); - /* draw a circle */ int width, height; gtk_window_get_size(GTK_WINDOW(widget), &width, &height); - cairo_set_source_rgba(cr, 1, 0.2, 0.2, 0.6); - cairo_arc(cr, width / 2, height / 2, (width < height ? width : height) / 2 - 8 , 0, 2 * 3.14); + int radius = (width < height ? width : height); + + /* draw a circle */ + cairo_set_source_rgba(cr, 1, 0.2, 0.2, 0.5); + cairo_arc(cr, width / 2, height / 2, radius / 2 - 8 , 0, 2 * 3.14); cairo_fill(cr); - cairo_stroke(cr); - + + cairo_set_source_rgba(cr, 0.2, 1, 0.2, 0.75); + cairo_arc(cr, width / 2, height / 2, radius *3/8 - 8 , 0, 2 * 3.14); + cairo_fill(cr); + + cairo_set_source_rgba(cr, 0.2, 0.2, 1.0, 1.0); + cairo_arc(cr, width / 2, height / 2, radius / 4 - 8 , 0, 2 * 3.14); + cairo_fill(cr); + cairo_destroy(cr); return FALSE; } static void clicked(GtkWindow *win, GdkEventButton *event, gpointer user_data) { + printf("Toggling frame\n"); /* toggle window manager frames */ gtk_window_set_decorated(win, !gtk_window_get_decorated(win)); } |