summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSøren Sandmann <sandmann@redhat.com>2008-03-09 11:11:47 -0400
committerSøren Sandmann <sandmann@redhat.com>2008-03-09 11:11:47 -0400
commit239031074fe2cc2c41ac4ae4e1ed4b54a5d74c21 (patch)
tree3fba1a3674c8ff729f68ac169f29834fb4e62710
parentcf25cafdee8052777d26fd8bc9f23888529862e6 (diff)
Better zooming
-rw-r--r--siv.c44
-rw-r--r--siv.glade12
2 files changed, 27 insertions, 29 deletions
diff --git a/siv.c b/siv.c
index 85af15d..309187e 100644
--- a/siv.c
+++ b/siv.c
@@ -40,6 +40,8 @@ struct Application
GdkPixbuf * original;
GdkPixbuf * displayed;
+ int width;
+ int height;
int zoom_level;
gboolean first;
@@ -173,7 +175,7 @@ on_expose (GtkWidget *drawing_area, GdkEventExpose *expose, Application *app)
}
static void
-adjust_adjustment (GtkAdjustment *adj, int new_size)
+adjust_adjustment (GtkAdjustment *adj, int old_size, int new_size)
{
double half_page;
double value;
@@ -181,15 +183,8 @@ adjust_adjustment (GtkAdjustment *adj, int new_size)
if (!adj)
return;
- g_print ("old value: %f\n", adj->value);
- g_print ("old size: %f\n", adj->upper);
- g_print ("new size: %d\n", new_size);
-
half_page = adj->page_size / 2;
- value = new_size * ((adj->value + half_page) / adj->upper) - half_page;
-
- g_print ("new value: %f\n", value);
-
+ value = new_size * ((adj->value + half_page) / (double)old_size) - half_page;
gtk_adjustment_set_value (adj, value);
}
@@ -224,11 +219,15 @@ rebuild (Application *app)
if (app->zoom_level <= 0 && (w < 32 || h < 32))
can_zoom_out = FALSE;
+ gtk_widget_hide (GET_WIDGET (app, "scrolled_window"));
+
hadj = gtk_scrolled_window_get_hadjustment (GET_WIDGET (app, "scrolled_window"));
vadj = gtk_scrolled_window_get_vadjustment (GET_WIDGET (app, "scrolled_window"));
- /* Hide the scrolled window so prevent an ugly flash while we adjust the position */
- gtk_widget_hide (GET_WIDGET (app, "scrolled_window"));
+#if 0
+ gtk_viewport_set_hadjustment (GET_WIDGET (app, "viewport1"), NULL);
+ gtk_viewport_set_vadjustment (GET_WIDGET (app, "viewport1"), NULL);
+#endif
if (app->first)
{
@@ -239,13 +238,23 @@ rebuild (Application *app)
}
else
{
- adjust_adjustment (hadj, w);
- adjust_adjustment (vadj, h);
+ if (hadj->page_size < w)
+ adjust_adjustment (hadj, app->width, w);
+ if (vadj->page_size < h)
+ adjust_adjustment (vadj, app->height, h);
}
+ gtk_widget_set_size_request (GET_WIDGET (app, "drawing_area"), w, h);
+
gtk_widget_show (GET_WIDGET (app, "scrolled_window"));
- gtk_widget_set_size_request (GET_WIDGET (app, "drawing_area"), w, h);
+#if 0
+ gtk_viewport_set_hadjustment (GET_WIDGET (app, "viewport1"), hadj);
+ gtk_viewport_set_vadjustment (GET_WIDGET (app, "viewport1"), vadj);
+#endif
+
+ app->width = w;
+ app->height = h;
}
gtk_widget_set_sensitive (GET_WIDGET (app, "menu_zoom_out"), can_zoom_out);
@@ -298,8 +307,6 @@ on_various (GtkWidget *widget, Application *app)
static gboolean
on_scroll (GtkWidget *widget, GdkEventScroll *event, Application *app)
{
- g_print ("scroll\n");
-
if (event->state & GDK_CONTROL_MASK)
{
if (event->direction == GDK_SCROLL_UP)
@@ -307,7 +314,7 @@ on_scroll (GtkWidget *widget, GdkEventScroll *event, Application *app)
else if (event->direction == GDK_SCROLL_DOWN)
app->zoom_level -= 1;
else
- return;
+ return FALSE;
rebuild (app);
return TRUE;
@@ -372,9 +379,12 @@ on_size_allocate (GtkWidget *widget, GtkAllocation *allocation, gpointer data)
region = gdk_region_rectangle (&old);
+ g_print ("%d %d\n", dx, dy);
+
gdk_window_move_region (widget->window, region, dx, dy);
gdk_region_destroy (region);
+
}
app->allocation = *allocation;
diff --git a/siv.glade b/siv.glade
index 3c346b7..2c676ea 100644
--- a/siv.glade
+++ b/siv.glade
@@ -382,18 +382,6 @@
<property name="fill">True</property>
</packing>
</child>
-
- <child>
- <widget class="GtkStatusbar" id="statusbar1">
- <property name="visible">True</property>
- <property name="has_resize_grip">True</property>
- </widget>
- <packing>
- <property name="padding">0</property>
- <property name="expand">False</property>
- <property name="fill">False</property>
- </packing>
- </child>
</widget>
</child>
</widget>