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
92
93
94
95
96
97
98
99
100
101
102
103
|
#include "deck.h"
#define MARGIN 18
#define RATIO 1.414
#define N_SLIDES 30
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;
}
int
deck_get_slide_height (Deck *deck, 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 height;
int i;
height = deck_get_slide_height (deck, width);
width -= 2 * MARGIN;
for (i = 0; i < N_SLIDES; ++i)
{
double x, y;
x = orig_x + MARGIN;
y = orig_y + MARGIN + i * (MARGIN + height);
cairo_set_source_rgba (cr, 1, 1, 1, 1);
cairo_rectangle (cr, x, y, width, height);
cairo_fill_preserve (cr);
cairo_set_source_rgba (cr, 0, 0, 0, 0.5);
cairo_set_line_width (cr, 2);
cairo_stroke (cr);
cairo_set_source_rgba (cr, (i + 1.0) / N_SLIDES, 0,
1 - (i + 1.0) / N_SLIDES, 1);
cairo_rectangle (cr, x + width/2 - 10, y + height/2 - 10, 20, 20);
cairo_fill (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 = deck_get_slide_height (deck, viewport->width);
/* 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,
int view_width,
int nth_slide)
{
int slide_height = deck_get_slide_height (deck, view_width);
return nth_slide * (MARGIN + slide_height) + MARGIN;
}
int
deck_get_height (Deck *deck, int view_width)
{
int slide_height = deck_get_slide_height (deck, view_width);
return N_SLIDES * slide_height + (N_SLIDES + 1) * MARGIN;
}
|