summaryrefslogtreecommitdiff
path: root/gfx-app
diff options
context:
space:
mode:
Diffstat (limited to 'gfx-app')
-rw-r--r--gfx-app/include/gfx/gfx_app.h32
-rw-r--r--gfx-app/src/gfx_app.c63
2 files changed, 95 insertions, 0 deletions
diff --git a/gfx-app/include/gfx/gfx_app.h b/gfx-app/include/gfx/gfx_app.h
index 3c544fa..86c502a 100644
--- a/gfx-app/include/gfx/gfx_app.h
+++ b/gfx-app/include/gfx/gfx_app.h
@@ -28,12 +28,44 @@ typedef struct GfxAppCallbacks {
28 GfxAppShutdown shutdown; 28 GfxAppShutdown shutdown;
29} GfxAppCallbacks; 29} GfxAppCallbacks;
30 30
31typedef enum Key {
32 KeyA = 'a',
33 KeyB,
34 KeyC,
35 KeyD,
36 KeyE,
37 KeyF,
38 KeyG,
39 KeyH,
40 KeyI,
41 KeyJ,
42 KeyK,
43 KeyL,
44 KeyM,
45 KeyN,
46 KeyO,
47 KeyP,
48 KeyQ,
49 KeyR,
50 KeyS,
51 KeyT,
52 KeyU,
53 KeyV,
54 KeyW,
55 KeyX,
56 KeyY,
57 KeyZ,
58} Key;
59
31/// Create a window with an OpenGL context and run the main loop. 60/// Create a window with an OpenGL context and run the main loop.
32bool gfx_app_run(const GfxAppDesc*, const GfxAppCallbacks*); 61bool gfx_app_run(const GfxAppDesc*, const GfxAppCallbacks*);
33 62
34/// Get the mouse coordinates relative to the app's window. 63/// Get the mouse coordinates relative to the app's window.
35void gfx_app_get_mouse_position(double* x, double* y); 64void gfx_app_get_mouse_position(double* x, double* y);
36 65
66/// Return true if the given key is pressed.
67bool gfx_is_key_pressed(Key);
68
37/// Define a main function that initializes and puts the application in a loop. 69/// Define a main function that initializes and puts the application in a loop.
38/// See also: gfx_app_run(). 70/// See also: gfx_app_run().
39#define GFX_APP_MAIN(WIDTH, HEIGHT, MAX_FPS) \ 71#define GFX_APP_MAIN(WIDTH, HEIGHT, MAX_FPS) \
diff --git a/gfx-app/src/gfx_app.c b/gfx-app/src/gfx_app.c
index a313ce8..e0211b1 100644
--- a/gfx-app/src/gfx_app.c
+++ b/gfx-app/src/gfx_app.c
@@ -138,3 +138,66 @@ cleanup:
138void gfx_app_get_mouse_position(double* x, double* y) { 138void gfx_app_get_mouse_position(double* x, double* y) {
139 glfwGetCursorPos(g_gfx_app.window, x, y); 139 glfwGetCursorPos(g_gfx_app.window, x, y);
140} 140}
141
142static int to_glfw_key(Key key);
143
144bool gfx_is_key_pressed(Key key) {
145 return glfwGetKey(g_gfx_app.window, to_glfw_key(key)) == GLFW_PRESS;
146}
147
148static int to_glfw_key(Key key) {
149 switch (key) {
150 case KeyA:
151 return GLFW_KEY_A;
152 case KeyB:
153 return GLFW_KEY_B;
154 case KeyC:
155 return GLFW_KEY_C;
156 case KeyD:
157 return GLFW_KEY_D;
158 case KeyE:
159 return GLFW_KEY_E;
160 case KeyF:
161 return GLFW_KEY_F;
162 case KeyG:
163 return GLFW_KEY_G;
164 case KeyH:
165 return GLFW_KEY_H;
166 case KeyI:
167 return GLFW_KEY_I;
168 case KeyJ:
169 return GLFW_KEY_J;
170 case KeyK:
171 return GLFW_KEY_K;
172 case KeyL:
173 return GLFW_KEY_L;
174 case KeyM:
175 return GLFW_KEY_M;
176 case KeyN:
177 return GLFW_KEY_N;
178 case KeyO:
179 return GLFW_KEY_O;
180 case KeyP:
181 return GLFW_KEY_P;
182 case KeyQ:
183 return GLFW_KEY_Q;
184 case KeyR:
185 return GLFW_KEY_R;
186 case KeyS:
187 return GLFW_KEY_S;
188 case KeyT:
189 return GLFW_KEY_T;
190 case KeyU:
191 return GLFW_KEY_U;
192 case KeyV:
193 return GLFW_KEY_V;
194 case KeyW:
195 return GLFW_KEY_W;
196 case KeyX:
197 return GLFW_KEY_X;
198 case KeyY:
199 return GLFW_KEY_Y;
200 case KeyZ:
201 return GLFW_KEY_Z;
202 }
203}