1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
#include "deck.h"
#define MARGIN 20
#define RATIO 1.414
#define N_SLIDES 10
struct Deck
{
DeckChangeNotify notify; /* Called on slide add/delete/reorder */
gpointer data;
};
Deck *
deck_new (DeckChangeNotify notify,
gpointer data)
{
Deck *deck = g_new0 (Deck, 1);
deck->notify = notify;
deck->data = data;
return deck;
}
static int
get_slide_height (Deck *deck,
GdkRectangle *viewport)
{
return (viewport->width - 2 * MARGIN) / RATIO;
}
void
deck_paint (Deck *deck,
FooScrollArea *area,
cairo_t *cr)
{
int height;
int i;
GdkRectangle viewport;
foo_scroll_area_get_viewport (area, &viewport);
height = get_slide_height (deck, &viewport);
cairo_move_to (cr, MARGIN, MARGIN);
for (i = 0; i < N_SLIDES; ++i)
{
cairo_move_to (cr, MARGIN, MARGIN + i * (MARGIN + height));
cairo_set_source_rgba (cr, 1, 1, 1, 1);
cairo_rel_line_to (cr, viewport.width - 2 * MARGIN, 0);
cairo_rel_line_to (cr, 0, height);
cairo_rel_line_to (cr, -(viewport.width - 2 * MARGIN), 0);
cairo_close_path (cr);
cairo_fill_preserve (cr);
cairo_set_source_rgba (cr, 0, 0, 0, 0.5);
cairo_set_line_width (cr, 2);
cairo_stroke (cr);
}
}
/* Returns the slide the user is likely looking
* at, given the viewport.
*/
int
deck_get_view_slide (Deck *deck,
GdkRectangle *viewport)
{
int slide_height = get_slide_height (deck, viewport);
/* Compute the y-coordinate of the first visible top edge of a slide */
return (viewport->y - MARGIN) / (MARGIN + slide_height) + 1;
}
/* Returns the y coordinate of the nth slide given
* the viewport
*/
int
deck_get_slide_location (Deck *deck,
GdkRectangle *viewport,
int nth_slide)
{
int slide_height = get_slide_height (deck, viewport);
return nth_slide * (MARGIN + slide_height) + MARGIN;
}
|