-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvtk.h
More file actions
112 lines (92 loc) · 2.54 KB
/
vtk.h
File metadata and controls
112 lines (92 loc) · 2.54 KB
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
108
109
110
111
112
#ifndef __VTK_H__
#define __VTK_H__
#include <cairo.h>
typedef enum vtk_err {
VTK_SUCCESS = 0,
VTK_ALLOCATION_FAILED,
VTK_NO_SUITABLE_VISUAL,
VTK_XOPENDISPLAY_FAILED,
VTK_EVENTFD_FAILED,
} vtk_err;
char *vtk_strerr(vtk_err err);
typedef struct vtk_root *vtk;
vtk_err vtk_new(vtk *root);
void vtk_destroy(vtk root);
typedef struct vtk_window *vtk_window;
vtk_err vtk_window_new(vtk_window *win, vtk root, const char *title, int x, int y, int width, int height);
void vtk_window_destroy(vtk_window win);
void vtk_window_close(vtk_window win);
void vtk_window_redraw(vtk_window win);
void vtk_window_mainloop(vtk_window win);
void vtk_window_set_title(vtk_window win, const char *title);
void vtk_window_get_size(vtk_window win, int *width, int *height);
cairo_t *vtk_window_get_cairo(vtk_window win);
void vtk_window_trigger_update(vtk_window win);
typedef enum vtk_event_type {
VTK_EV_CLOSE,
VTK_EV_DRAW,
VTK_EV_KEY_PRESS,
VTK_EV_KEY_RELEASE,
VTK_EV_MOUSE_MOVE,
VTK_EV_MOUSE_PRESS,
VTK_EV_MOUSE_RELEASE,
VTK_EV_RESIZE,
VTK_EV_SCROLL,
VTK_EV_UPDATE,
} vtk_event_type;
typedef enum vtk_key {
VTK_K_NONE,
VTK_K_BACKSPACE = 0x08,
VTK_K_TAB = 0x09,
VTK_K_RETURN = 0x0a,
VTK_K_ESCAPE = 0x1b,
VTK_K_SPACE = 0x20,
VTK_K_DELETE = 0x7f,
VTK_K_INSERT,
VTK_K_PAGE_UP,
VTK_K_PAGE_DOWN,
VTK_K_HOME,
VTK_K_END,
VTK_K_UP,
VTK_K_DOWN,
VTK_K_LEFT,
VTK_K_RIGHT,
} vtk_key;
vtk_key vtk_key_from_string(const char *s);
typedef enum vtk_modifiers {
VTK_M_SHIFT = 1 << 0,
VTK_M_CAPS_LOCK = 1 << 1,
VTK_M_CONTROL = 1 << 2,
VTK_M_ALT = 1 << 3,
VTK_M_SUPER = 1 << 4,
VTK_M_LEFT_BTN = 1 << 5,
VTK_M_MIDDLE_BTN = 1 << 6,
VTK_M_RIGHT_BTN = 1 << 7,
} vtk_modifiers;
vtk_modifiers vtk_modifier_from_string(const char *s);
typedef union vtk_event {
vtk_event_type type;
struct vtk_key_event {
vtk_event_type type;
vtk_key key; // ASCII character or value from vtk_key
vtk_modifiers mods; // ORed mask of values from vtk_modifiers
} key;
struct vtk_mouse_move_event {
vtk_event_type type;
vtk_modifiers mods; // ORed mask of values from vtk_modifiers
int x, y;
} mouse_move;
struct vtk_mouse_button_event {
vtk_event_type type;
vtk_modifiers btn; // The button that was pressed or released
vtk_modifiers mods; // ORed mask of values from vtk_modifiers
int x, y;
} mouse_button;
struct vtk_scroll_event {
vtk_event_type type;
double amount;
} scroll;
} vtk_event;
typedef void (*vtk_event_handler)(vtk_event ev, void *u);
void vtk_window_set_event_handler(vtk_window win, vtk_event_type type, vtk_event_handler handler, void *data);
#endif