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
|
#define main tablet_example_main
#include "../../examples/tablet.c"
#undef main
#include <assert.h>
static void pointer(struct app *app, enum yasl_event_type type,
enum yasl_pointer_device device, enum yasl_pointer_button button, int x, int y, uint16_t pressure)
{
struct yasl_event event = {
.type = type,
.pointer = {
.pos = (struct yasl_vector2i){x, y},
.device = device,
.button = button,
.pen = { .pressure = pressure },
},
};
input(app, &event);
}
int main(void)
{
struct app app = {0};
assert(resize_canvas(&app, (struct yasl_geometry){{400, 300}, 120}));
pointer(&app, YASL_EVENT_POINTER_MOTION, YASL_PTR_DEV_PEN, YASL_BUTTON_BACK, 80, 160, 65535);
/* Hover never paints. */
assert(app.canvas[(size_t)160 * app.geometry.size.x + 80] == PAPER);
pointer(&app, YASL_EVENT_POINTER_DOWN, YASL_PTR_DEV_PEN, YASL_BUTTON_SECONDARY, 80, 160, 65535);
/* Side button isn't the tip. */
assert(!app.down &&
app.canvas[(size_t)160 * app.geometry.size.x + 80] == PAPER);
pointer(&app, YASL_EVENT_POINTER_DOWN, YASL_PTR_DEV_PEN, YASL_BUTTON_PRIMARY, 80, 160, 0);
assert(app.down &&
app.canvas[(size_t)160 * app.geometry.size.x + 80] == INK &&
app.canvas[(size_t)160 * app.geometry.size.x + 90] == PAPER);
pointer(&app, YASL_EVENT_POINTER_MOTION, YASL_PTR_DEV_PEN, YASL_BUTTON_PRIMARY, 80, 160, 65535);
/* Stationary pressure widens brush. */
assert(app.canvas[(size_t)160 * app.geometry.size.x + 100] == INK);
pointer(&app, YASL_EVENT_POINTER_MOTION, YASL_PTR_DEV_PEN, YASL_BUTTON_PRIMARY, 180, 160, 20000);
/* Segments are continuous. */
assert(app.canvas[(size_t)160 * app.geometry.size.x + 130] == INK);
pointer(&app, YASL_EVENT_POINTER_UP, YASL_PTR_DEV_PEN, YASL_BUTTON_PRIMARY, 180, 160, 0);
pointer(&app, YASL_EVENT_POINTER_MOTION, YASL_PTR_DEV_PEN, YASL_BUTTON_BACK, 250, 160, 65535);
assert(!app.down && app.canvas[(size_t)160 * app.geometry.size.x + 250] == PAPER);
pointer(&app, YASL_EVENT_POINTER_DOWN, YASL_PTR_DEV_ERASER, YASL_BUTTON_PRIMARY, 80, 160, 65535);
assert(app.canvas[(size_t)160 * app.geometry.size.x + 80] == PAPER &&
app.canvas[(size_t)160 * app.geometry.size.x + 130] == INK);
struct yasl_event reset = {.type = YASL_EVENT_INPUT_RESET};
input(&app, &reset);
pointer(&app, YASL_EVENT_POINTER_MOTION, YASL_PTR_DEV_ERASER, YASL_BUTTON_PRIMARY, 130, 160, 65535);
assert(!app.down && app.canvas[(size_t)160 * app.geometry.size.x + 130] == INK);
pointer(&app, YASL_EVENT_POINTER_DOWN, YASL_PTR_DEV_MOUSE, YASL_BUTTON_PRIMARY, 300, 200, 0);
assert(app.canvas[(size_t)200 * app.geometry.size.x + 300] == INK);
struct yasl_event blur = {.type = YASL_EVENT_FOCUS, .focus.focused = false};
input(&app, &blur);
assert(!app.down);
assert(resize_canvas(&app, (struct yasl_geometry){{800, 600}, 240}));
/* DPI preserves logical drawing. */
assert(app.canvas[(size_t)400 * app.geometry.size.x + 600] == INK &&
!app.previous);
clear_canvas(&app);
assert(app.canvas[(size_t)400 * app.geometry.size.x + 600] == PAPER);
free(app.canvas);
return 0;
}
|