summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSøren Sandmann <sandmann@redhat.com>2008-06-06 01:12:59 -0400
committerSøren Sandmann <sandmann@redhat.com>2008-06-06 01:12:59 -0400
commit169e9bc9f16488726241233e8f4a31bc1177c88e (patch)
tree06c4ba14d336f0593e70eef4c8c59b9df5e3909f
parent6b90e189d35af19e9cfdcdc54314bfbdaf633951 (diff)
Better resizing
-rw-r--r--main.c51
-rw-r--r--scrollarea.c29
2 files changed, 24 insertions, 56 deletions
diff --git a/main.c b/main.c
index 03c1cd1..3f00fc2 100644
--- a/main.c
+++ b/main.c
@@ -71,8 +71,6 @@ on_main_paint (FooScrollArea *scroll_area,
cairo_stroke (cr);
}
-
- g_print ("paint %d %d %d %d\n", extents->x, extents->y, extents->width, extents->height);
}
static void
@@ -80,44 +78,28 @@ on_viewport_size_changed (FooScrollArea *scroll_area,
GdkRectangle *viewport,
GdkRectangle *old_viewport)
{
-#if 0
- double ratio;
- int th;
-
- g_print ("new slide height: %d, new y: %d\n", slide_height, viewport->y);
-
- /* FIXME: We can recurse infinitely here when the area gets
- * narrow enough that the scrollbar disappears causing the area
- * to widen a little causing the scrollbar to appear causing
- * the arrow to narrow causing ...
- *
- * For now we work around by have POLICY_ALWAYS on the scrollbar,
- * it needs to be thought through and fixed in the scroll area
- */
-
- ratio = (double)viewport->width / old_viewport->width;
-
-#if 0
- g_print ("ratio: %f (%d %d)\n", ratio, old_viewport->y, (int)(old_viewport->y * ratio));
-
- g_print ("old, new: %f %f\n", slide_n, MARGIN + slide_n * (MARGIN + (double)slide_height));
-#endif
-
- foo_scroll_area_set_size_fixed_y (scroll_area, viewport->width, th,
- slide_n,
- MARGIN + slide_n * (MARGIN + slide_height));
-#endif
+ int total_height;
+ int nth_slide;
+ double old_y;
+ double new_y;
+
+ /* Compute the y-coordinate of the first visible top edge of a slide */
- int th;
- double slide_n;
+ nth_slide =
+ (old_viewport->y - MARGIN) / (MARGIN + (double)slide_height) + 1;
+
+ old_y = nth_slide * (MARGIN + (double)slide_height) + MARGIN;
slide_width = viewport->width - 2 * MARGIN;
slide_height = slide_width / RATIO;
- th = N_SLIDES * slide_height + (N_SLIDES + 1) * MARGIN;
- foo_scroll_area_set_size (scroll_area, viewport->width, th);
+ new_y = nth_slide * (MARGIN + (double)slide_height) + MARGIN;
+
+ total_height = N_SLIDES * slide_height + (N_SLIDES + 1) * MARGIN;
- g_print ("size changed - set size %d %d\n", viewport->width, th);
+ foo_scroll_area_set_size_fixed_y (scroll_area, viewport->width,
+ total_height,
+ old_y + 0.5, new_y + 0.5);
foo_scroll_area_invalidate (scroll_area);
}
@@ -127,7 +109,6 @@ on_viewport_changed (FooScrollArea *scroll_area,
GdkRectangle *viewport,
GdkRectangle *old_viewport)
{
- g_print ("viewport changed\n");
}
static void
diff --git a/scrollarea.c b/scrollarea.c
index 1d88534..f626308 100644
--- a/scrollarea.c
+++ b/scrollarea.c
@@ -636,7 +636,6 @@ emit_viewport_signals (FooScrollArea *scroll_area,
GdkRectangle *new_viewport,
GdkRectangle *old_viewport)
{
- int px, py;
gboolean position_changed;
gboolean size_changed;
@@ -648,6 +647,8 @@ emit_viewport_signals (FooScrollArea *scroll_area,
if (size_changed || position_changed)
{
+ int px, py;
+
g_signal_emit (scroll_area, signals[VIEWPORT_CHANGED], 0,
new_viewport, old_viewport);
@@ -656,21 +657,15 @@ emit_viewport_signals (FooScrollArea *scroll_area,
g_signal_emit (scroll_area, signals[VIEWPORT_SIZE_CHANGED], 0,
new_viewport, old_viewport);
}
- else
- {
- g_print ("old size: %d %d\n", old_viewport->width, old_viewport->height);
- g_print ("new size: %d %d\n", new_viewport->width, new_viewport->height);
- }
-
- gdk_window_get_pointer (GTK_WIDGET (scroll_area)->window, &px, &py, NULL);
+
+ /* Fake an event when the viewport changes
+ * FIXME: keep track of the last position in the window
+ */
+ gdk_window_get_pointer (GTK_WIDGET (scroll_area)->window,
+ &px, &py, NULL);
process_event (scroll_area, FOO_MOTION, px, py, 0);
}
- else
- {
- g_print ("old pos: %d %d\n", old_viewport->x, old_viewport->y);
- g_print ("new pos: %d %d\n", new_viewport->x, new_viewport->y);
- }
}
static void
@@ -1150,12 +1145,6 @@ foo_scroll_area_set_size_fixed_y (FooScrollArea *scroll_area,
scroll_area->priv->width = width;
scroll_area->priv->height = height;
-#if 0
- g_print ("diff: %d\n", new_y - old_y);
-#endif
-
- g_print ("old: %d new %d (dy %d)\n", old_y, new_y, dy);
-
scroll_area->priv->vadj->value += dy;
set_adjustment_values (scroll_area);
@@ -1215,8 +1204,6 @@ foo_scrollbar_adjustment_changed (GtkAdjustment *adj,
gint dy = 0;
GdkRectangle old_viewport, new_viewport;
- g_print ("adjustment changed\n");
-
/* FIXME: When dragging diagonally, this function will be called
* twice, causing two separate scrolls in the backing store.
*