summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSøren Sandmann <sandmann@redhat.com>2008-06-10 03:38:48 -0400
committerSøren Sandmann <sandmann@redhat.com>2008-06-10 03:38:48 -0400
commitb8d937f6877a64726d2147478c7409ea0b593582 (patch)
tree925064b7455a78ec4c524cbea7d8fd43128dd8c1
parentd25600cd73d18044f83f1b3803e96f11c2adcf83 (diff)
Maintain a width in the deck
-rw-r--r--deck.c94
-rw-r--r--deck.h36
-rw-r--r--main.c63
-rw-r--r--toolbar.c6
-rw-r--r--toolbar.h2
5 files changed, 156 insertions, 45 deletions
diff --git a/deck.c b/deck.c
index 3b40df2..970ba3e 100644
--- a/deck.c
+++ b/deck.c
@@ -8,6 +8,9 @@ struct Deck
{
DeckChangeNotify notify; /* Called on slide add/delete/reorder */
gpointer data;
+
+ int view_width;
+ int thumb_width;
};
Deck *
@@ -22,23 +25,41 @@ deck_new (DeckChangeNotify notify,
return deck;
}
-int
-deck_get_slide_height (Deck *deck, int view_width)
+void
+deck_set_main_width (Deck *deck, int view_width)
+{
+ deck->view_width = view_width;
+}
+
+static int
+get_slide_height (int view_width)
{
return (view_width - 2 * MARGIN) / RATIO;
}
-void
-deck_paint (Deck *deck,
- cairo_t *cr,
- int orig_x,
- int orig_y,
- int width)
+int
+deck_get_main_slide_height (Deck *deck)
+{
+ return get_slide_height (deck->view_width);
+}
+
+int
+deck_get_thumb_slide_height (Deck *deck)
+{
+ return get_slide_height (deck->thumb_width);
+}
+
+static void
+deck_paint (Deck *deck,
+ cairo_t *cr,
+ int orig_x,
+ int orig_y,
+ int width)
{
int height;
int i;
- height = deck_get_slide_height (deck, width);
+ height = get_slide_height (width);
width -= 2 * MARGIN;
@@ -68,6 +89,24 @@ deck_paint (Deck *deck,
}
}
+void
+deck_paint_main (Deck *deck,
+ cairo_t *cr,
+ int orig_x,
+ int orig_y)
+{
+ deck_paint (deck, cr, orig_x, orig_y, deck->view_width);
+}
+
+void
+deck_paint_thumbs (Deck *deck,
+ cairo_t *cr,
+ int x,
+ int y)
+{
+ deck_paint (deck, cr, x, y, deck->thumb_width);
+}
+
/* Returns the slide the user is likely looking
* at, given the viewport.
*/
@@ -75,7 +114,7 @@ int
deck_get_view_slide (Deck *deck,
GdkRectangle *viewport)
{
- int slide_height = deck_get_slide_height (deck, viewport->width);
+ int slide_height = deck_get_main_slide_height (deck);
/* Compute the y-coordinate of the first visible top edge of a slide */
return (viewport->y - MARGIN) / (MARGIN + slide_height) + 1;
@@ -85,19 +124,42 @@ deck_get_view_slide (Deck *deck,
* the viewport
*/
int
-deck_get_slide_location (Deck *deck,
- int view_width,
- int nth_slide)
+deck_get_main_slide_location (Deck *deck,
+ int nth_slide)
{
- int slide_height = deck_get_slide_height (deck, view_width);
+ int slide_height = deck_get_main_slide_height (deck);
return nth_slide * (MARGIN + slide_height) + MARGIN;
}
int
-deck_get_height (Deck *deck, int view_width)
+deck_get_thumb_slide_location (Deck *deck,
+ int nth_slide)
+{
+ int slide_height = deck_get_thumb_slide_height (deck);
+
+ return nth_slide * (MARGIN + slide_height) + MARGIN;
+}
+
+int
+deck_get_main_height (Deck *deck)
{
- int slide_height = deck_get_slide_height (deck, view_width);
+ int slide_height = deck_get_main_slide_height (deck);
return N_SLIDES * slide_height + (N_SLIDES + 1) * MARGIN;
}
+
+
+void
+deck_set_thumb_width (Deck *deck, int thumb_width)
+{
+ deck->thumb_width = thumb_width;
+}
+
+int
+deck_get_thumb_height (Deck *deck)
+{
+ int thumb_height = deck_get_thumb_slide_height (deck);
+
+ return N_SLIDES * thumb_height + (N_SLIDES + 1) * MARGIN;
+}
diff --git a/deck.h b/deck.h
index 2c26d79..3ba2357 100644
--- a/deck.h
+++ b/deck.h
@@ -7,11 +7,14 @@ typedef void (* DeckChangeNotify) (gpointer data);
Deck *deck_new (DeckChangeNotify notify,
gpointer data);
-void deck_paint (Deck *deck,
+void deck_paint_main (Deck *deck,
cairo_t *cr,
int x,
- int y,
- int width);
+ int y);
+void deck_paint_thumbs (Deck *deck,
+ cairo_t *cr,
+ int x,
+ int y);
/* Returns the slide the user is likely looking
* at, given the viewport.
@@ -23,12 +26,27 @@ deck_get_view_slide (Deck *deck,
* the width of the viewport
*/
int
-deck_get_slide_location (Deck *deck,
- int view_width,
- int nth_slide);
+deck_get_main_slide_location (Deck *deck,
+ int nth_slide);
+
+int
+deck_get_thumb_slide_location (Deck *deck,
+ int nth_slide);
+
int
-deck_get_slide_height (Deck *deck,
- int view_width);
+deck_get_main_slide_height (Deck *deck);
+
+int
+deck_get_thumb_slide_height (Deck *deck);
+
+int
+deck_get_main_height (Deck *deck);
+
+void
+deck_set_main_width (Deck *deck, int main_width);
+
+void
+deck_set_thumb_width (Deck *deck, int thumb_width);
int
-deck_get_height (Deck *deck, int view_width);
+deck_get_thumb_height (Deck *deck);
diff --git a/main.c b/main.c
index bbbe44d..0230d69 100644
--- a/main.c
+++ b/main.c
@@ -44,7 +44,7 @@ on_thumbs_paint (FooScrollArea *scroll_area,
foo_scroll_area_get_viewport (app->thumbnails, &viewport);
- deck_paint (app->deck, cr, 0, 0, viewport.width);
+ deck_paint_thumbs (app->deck, cr, 0, 0);
}
static void
@@ -54,9 +54,12 @@ on_thumbs_viewport_size_changed (FooScrollArea *scroll_area,
gpointer data)
{
App *app = data;
- int height = deck_get_height (app->deck, viewport->width);
- foo_scroll_area_set_size (scroll_area, viewport->width, height);
+ deck_set_thumb_width (app->deck, viewport->width);
+
+ foo_scroll_area_set_size (scroll_area,
+ viewport->width,
+ deck_get_thumb_height (app->deck));
}
static gboolean
@@ -98,6 +101,15 @@ invalidate_toolbar (App *app, GdkRectangle *viewport)
app->main_area, viewport->x, viewport->y);
}
+static int
+get_toolbar_width (App *app)
+{
+ if (is_maximized (app))
+ return toolbar_get_width (app->toolbar) + 12;
+ else
+ return toolbar_get_width (app->toolbar) + 6;
+}
+
static void
on_main_paint (FooScrollArea *scroll_area,
cairo_t *cr,
@@ -112,9 +124,7 @@ on_main_paint (FooScrollArea *scroll_area,
cairo_save (cr);
- cairo_translate (cr, 72 + 12, 0);
-
- deck_paint (app->deck, cr, 0, 0, viewport.width - (72 + 12) );
+ deck_paint_main (app->deck, cr, get_toolbar_width (app), 0);
cairo_restore (cr);
paint_toolbar (app, scroll_area, cr);
@@ -127,7 +137,11 @@ on_main_viewport_size_changed (FooScrollArea *scroll_area,
gpointer data)
{
App *app = data;
- int height = deck_get_height (app->deck, new_viewport->width);
+ int new_height;
+ int toolbar_width = get_toolbar_width (app);
+ int deck_width = new_viewport->width - toolbar_width;
+
+ /* Ugh, fixme */
static int first = 1;
if (first)
{
@@ -135,21 +149,32 @@ on_main_viewport_size_changed (FooScrollArea *scroll_area,
first = 0;
}
+ deck_set_main_width (app->deck, deck_width);
+ new_height = deck_get_main_height (app->deck);
+
if (old_viewport)
{
- int nth_slide = app->nth_slide; /* deck_get_view_slide (app->deck, old_viewport); */
- int old_location = deck_get_slide_location (app->deck,
- old_viewport->width,
- nth_slide);
- int new_location = deck_get_slide_location (app->deck,
- new_viewport->width,
- nth_slide);
- foo_scroll_area_set_size_fixed_y (scroll_area, new_viewport->width,
- height, old_location, new_location);
+ int nth_slide, old_location, new_location;
+
+ nth_slide = app->nth_slide;
+
+ deck_set_main_width (app->deck, old_viewport->width - toolbar_width);
+ old_location = deck_get_main_slide_location (app->deck, nth_slide);
+
+ deck_set_main_width (app->deck, deck_width);
+ new_location = deck_get_main_slide_location (app->deck, nth_slide);
+
+ foo_scroll_area_set_size_fixed_y (scroll_area,
+ new_viewport->width, new_height,
+ old_location, new_location);
}
else
{
- foo_scroll_area_set_size (scroll_area, new_viewport->width, height);
+ deck_set_main_width (app->deck, deck_width);
+
+ foo_scroll_area_set_size (scroll_area,
+ new_viewport->width,
+ new_height);
foo_scroll_area_set_viewport_pos (scroll_area, 0, 0);
}
@@ -167,8 +192,8 @@ make_thumbnail_viewable (App *app)
foo_scroll_area_get_viewport (area, &viewport);
- top = deck_get_slide_location (app->deck, viewport.width, app->nth_slide);
- height = deck_get_slide_height (app->deck, viewport.width);
+ top = deck_get_thumb_slide_location (app->deck, app->nth_slide);
+ height = deck_get_thumb_slide_height (app->deck);
if (top - margin < viewport.y)
viewport.y = top - margin;
diff --git a/toolbar.c b/toolbar.c
index adfa629..74b7709 100644
--- a/toolbar.c
+++ b/toolbar.c
@@ -20,6 +20,12 @@ toolbar_new (void)
return g_new0 (Toolbar, 1);
}
+int
+toolbar_get_width (Toolbar *bar)
+{
+ return BORDER_WIDTH + TOOL_SIZE;
+}
+
void
toolbar_paint (Toolbar *bar,
FooScrollArea *scroll_area,
diff --git a/toolbar.h b/toolbar.h
index ede9e47..5e6a0c9 100644
--- a/toolbar.h
+++ b/toolbar.h
@@ -12,4 +12,4 @@ void toolbar_invalidate (Toolbar *bar,
FooScrollArea *scroll_area,
int x,
int y);
-
+int toolbar_get_width (Toolbar *bar);