summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSøren Sandmann <sandmann@redhat.com>2008-03-08 21:33:05 -0500
committerSøren Sandmann <sandmann@redhat.com>2008-03-08 21:33:05 -0500
commitcf25cafdee8052777d26fd8bc9f23888529862e6 (patch)
tree32bf0cc832e8e23a3bf556a200a4c6075fe5d678
parentef179174f0bf2febb89b4afb0bcb4bb413acded7 (diff)
Faster resizing
-rw-r--r--siv.c79
1 files changed, 75 insertions, 4 deletions
diff --git a/siv.c b/siv.c
index 39fcb96..85af15d 100644
--- a/siv.c
+++ b/siv.c
@@ -42,6 +42,8 @@ struct Application
int zoom_level;
gboolean first;
+
+ GtkAllocation allocation;
};
#define GET_WIDGET(app,name) \
@@ -104,7 +106,6 @@ on_expose (GtkWidget *drawing_area, GdkEventExpose *expose, Application *app)
int win_x, win_y;
int window_width, window_height;
GdkRectangle image;
- gboolean no_background;
guint32 color1, color2;
if (!app->original)
@@ -162,7 +163,7 @@ on_expose (GtkWidget *drawing_area, GdkEventExpose *expose, Application *app)
interp, 0xff,
dest.x - image.x, dest.y - image.y,
16, color1, color2);
-
+
gdk_draw_pixbuf (drawing_area->window, NULL,
tmp, 0, 0, dest.x, dest.y, dest.width, dest.height, GDK_RGB_DITHER_NONE, 0, 0);
@@ -294,7 +295,7 @@ on_various (GtkWidget *widget, Application *app)
rebuild (app);
}
-static void
+static gboolean
on_scroll (GtkWidget *widget, GdkEventScroll *event, Application *app)
{
g_print ("scroll\n");
@@ -309,7 +310,74 @@ on_scroll (GtkWidget *widget, GdkEventScroll *event, Application *app)
return;
rebuild (app);
+ return TRUE;
}
+
+ return FALSE;
+}
+
+static void
+on_size_allocate (GtkWidget *widget, GtkAllocation *allocation, gpointer data)
+{
+ Application *app = data;
+
+ if (app->allocation.width == 0 || app->allocation.height == 0)
+ {
+ gtk_widget_queue_draw (widget);
+ }
+ else
+ {
+ int w, h;
+ GdkRectangle old;
+ GdkRectangle new;
+ GdkRegion *region;
+ int dx, dy;
+ int old_x, new_x;
+ int old_y, new_y;
+
+ if (!app->original)
+ return;
+
+ compute_size (app, &old.width, &old.height);
+ old.x = (app->allocation.width - old.width) / 2;
+ old.y = (app->allocation.height - old.height) / 2;
+
+ new = old;
+ new.x = (allocation->width - old.width) / 2;
+ new.y = (allocation->height - old.height) / 2;
+
+ if (old.width < allocation->width && old.width < app->allocation.width)
+ {
+ dx = new.x - old.x;
+ }
+ else
+ {
+ dx = 0;
+
+ if (old.width < allocation->width || old.width < app->allocation.width)
+ gtk_widget_queue_draw (widget);
+ }
+
+ if (old.height < allocation->height && old.height < app->allocation.height)
+ {
+ dy = new.y - old.y;
+ }
+ else
+ {
+ dy = 0;
+
+ if (old.height < allocation->height || old.height < app->allocation.height)
+ gtk_widget_queue_draw (widget);
+ }
+
+ region = gdk_region_rectangle (&old);
+
+ gdk_window_move_region (widget->window, region, dx, dy);
+
+ gdk_region_destroy (region);
+ }
+
+ app->allocation = *allocation;
}
static void
@@ -347,6 +415,7 @@ connect_signals (Application *app)
{ "menu_checkerboard", "activate", G_CALLBACK (on_various) },
{ "drawing_area", "expose_event", G_CALLBACK (on_expose) },
{ "drawing_area", "scroll_event", G_CALLBACK (on_scroll) },
+ { "drawing_area", "size_allocate", G_CALLBACK (on_size_allocate) },
};
for (i = 0; i < G_N_ELEMENTS (connections); ++i)
@@ -385,7 +454,9 @@ build_gui (Application *app)
app->xml = glade_xml_new (GLADE_FILE, NULL, NULL);
gtk_widget_add_events (GET_WIDGET (app, "drawing_area"), GDK_SCROLL_MASK);
-
+ gtk_widget_set_redraw_on_allocate (
+ GET_WIDGET (app, "drawing_area"), FALSE);
+
/* Connect signals */
connect_signals (app);