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
104
105
106
107
|
#include "interactor.h"
#include "drawfuncs.h"
#include "spritedrawingarea.h"
#include "config.h"
void
interactor_sprite_layer_draw_func (
SDALayer *layer,
cairo_t *cr,
gpointer user_data
) {
const GdkPixbuf *sprite;
gint offsetX, offsetY;
Interactor *interactor = *((Interactor **) user_data);
if (interactor == NULL)
return;
sprite = interactor_get_sprite (interactor);
if (sprite == NULL)
return;
interactor_get_offset (interactor, &offsetX, &offsetY);
gdk_cairo_set_source_pixbuf (
cr, sprite,
offsetX,
offsetY + config_keys_get_tile_size () / 2
);
cairo_pattern_set_filter (
cairo_get_source (cr),
CAIRO_FILTER_NEAREST
);
cairo_paint (cr);
}
void
background_layer_draw_func (
SDALayer *layer,
cairo_t *cr,
gpointer user_data
) {
GdkRGBA *rgba = (GdkRGBA *) user_data;
gdk_cairo_set_source_rgba (cr, rgba);
cairo_rectangle (
cr,
-SPRITE_DRAWING_AREA_FIELD_SIZE,
-SPRITE_DRAWING_AREA_FIELD_SIZE,
2 * SPRITE_DRAWING_AREA_FIELD_SIZE,
2 * SPRITE_DRAWING_AREA_FIELD_SIZE
);
cairo_fill (cr);
}
void
tile_grid_layer_draw_func (
SDALayer *layer,
cairo_t *cr,
gpointer user_data
) {
gint x;
gint field_size = SPRITE_DRAWING_AREA_FIELD_SIZE;
gint tile_size = config_keys_get_tile_size ();
cairo_set_line_width (cr, 1.0);
cairo_set_operator (cr, CAIRO_OPERATOR_XOR);
cairo_set_source_rgba (cr, 0, 0, 0, 0.5);
cairo_translate (cr, 0.5, 0.5);
x = -tile_size / 2;
while (x >= -field_size)
x -= tile_size;
for (; x <= field_size; x += tile_size) {
cairo_move_to (cr, x, -field_size);
cairo_line_to (cr, x, field_size);
cairo_move_to (cr, -field_size, x);
cairo_line_to (cr, field_size, x);
}
cairo_stroke (cr);
}
void
pixel_grid_layer_draw_func (
SDALayer *layer,
cairo_t *cr,
gpointer user_data
) {
gint x;
gint field_size = SPRITE_DRAWING_AREA_FIELD_SIZE;
cairo_set_line_width (cr, 0.1);
cairo_set_source_rgb (cr, 0, 0, 0);
for (x = -field_size; x <= field_size; ++x) {
cairo_move_to (cr, x, -field_size);
cairo_line_to (cr, x, field_size);
cairo_move_to (cr, -field_size, x);
cairo_line_to (cr, field_size, x);
}
cairo_stroke (cr);
}
|