diff options
author | Søren Sandmann <sandmann@redhat.com> | 2008-04-28 00:47:28 -0400 |
---|---|---|
committer | Søren Sandmann <sandmann@redhat.com> | 2008-04-28 00:47:28 -0400 |
commit | c2d0b81c9a94d79a6a9474d20dab311d70b1737d (patch) | |
tree | db22084a83774fe50c69ed8caab932332a927168 | |
parent | 4a8f74188c269092b29ce2a764e0339546da6711 (diff) |
Make drawing even faster (in most cases)
-rw-r--r-- | window.c | 37 |
1 files changed, 29 insertions, 8 deletions
@@ -62,6 +62,20 @@ compute_size (Window *window, int *w, int *h) } static void +initialize_bg (GtkWidget *drawing_area, GdkRegion *region) +{ + GdkWindowObject *private = (GdkWindowObject *)drawing_area->window; + GdkGC *gc = gdk_gc_new (drawing_area->window); + + gdk_gc_set_rgb_fg_color (gc, &(private->bg_color)); + gdk_gc_set_clip_region (gc, region); + + gdk_draw_rectangle (drawing_area->window, gc, TRUE, 0, 0, -1, -1); + + g_object_unref (gc); +} + +static void paint_rect (GtkWidget *drawing_area, GdkRectangle *area, Window *window) { GdkPixbuf *tmp; @@ -70,6 +84,7 @@ paint_rect (GtkWidget *drawing_area, GdkRectangle *area, Window *window) int window_width, window_height; GdkRectangle image; guint32 color1, color2; + GdkRegion *bg_reg, *image_reg; gdk_window_get_size (drawing_area->window, &window_width, &window_height); @@ -81,6 +96,16 @@ paint_rect (GtkWidget *drawing_area, GdkRectangle *area, Window *window) if (image.height < window_height) image.y = (window_height - image.height) / 2; + + bg_reg = gdk_region_rectangle (area); + image_reg = gdk_region_rectangle (&image); + + gdk_region_subtract (bg_reg, image_reg); + + initialize_bg (drawing_area, bg_reg); + + gdk_region_destroy (bg_reg); + gdk_region_destroy (image_reg); if (!gdk_rectangle_intersect (area, &image, &dest)) return; @@ -131,6 +156,7 @@ static gboolean on_expose (GtkWidget *drawing_area, GdkEventExpose *expose, Window *window) { GdkRectangle *rects; + GdkGC *gc; int n_rects; int i; @@ -141,19 +167,11 @@ on_expose (GtkWidget *drawing_area, GdkEventExpose *expose, Window *window) return; gdk_region_get_rectangles (expose->region, &rects, &n_rects); - -#if 0 - g_print ("painting %d rectangles\n", n_rects); -#endif for (i = 0; i < n_rects; ++i) paint_rect (drawing_area, &(rects[i]), window); g_free (rects); -#if 0 - - g_print ("done painting\n"); -#endif return TRUE; } @@ -908,6 +926,9 @@ window_new (App *app) gtk_widget_add_events (get_widget (window, "drawing_area"), GDK_SCROLL_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK); + + gtk_widget_set_double_buffered (get_widget (window, "drawing_area"), FALSE); + gtk_widget_set_redraw_on_allocate (get_widget (window, "drawing_area"), FALSE); gtk_widget_realize (get_widget (window, "main_window")); |