summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/include/gfx/app.h11
-rw-r--r--app/src/app.c20
2 files changed, 29 insertions, 2 deletions
diff --git a/app/include/gfx/app.h b/app/include/gfx/app.h
index 3843d92..77b6ad2 100644
--- a/app/include/gfx/app.h
+++ b/app/include/gfx/app.h
@@ -31,6 +31,12 @@ typedef struct GfxAppCallbacks {
31 GfxAppResize resize; 31 GfxAppResize resize;
32} GfxAppCallbacks; 32} GfxAppCallbacks;
33 33
34typedef enum MouseButton {
35 LMB,
36 RMB,
37 MMB,
38} MouseButton;
39
34typedef enum Key { 40typedef enum Key {
35 KeyA = 'a', 41 KeyA = 'a',
36 KeyB, 42 KeyB,
@@ -70,8 +76,11 @@ bool gfx_app_run(const GfxAppDesc*, const GfxAppCallbacks*);
70/// Get the mouse coordinates relative to the app's window. 76/// Get the mouse coordinates relative to the app's window.
71void gfx_app_get_mouse_position(double* x, double* y); 77void gfx_app_get_mouse_position(double* x, double* y);
72 78
79/// Return if the given mouse button is pressed.
80bool gfx_app_is_mouse_button_pressed(MouseButton);
81
73/// Return true if the given key is pressed. 82/// Return true if the given key is pressed.
74bool gfx_is_key_pressed(Key); 83bool gfx_app_is_key_pressed(Key);
75 84
76#ifdef __cplusplus 85#ifdef __cplusplus
77} // extern "C" 86} // extern "C"
diff --git a/app/src/app.c b/app/src/app.c
index 1e636af..9b816ee 100644
--- a/app/src/app.c
+++ b/app/src/app.c
@@ -149,12 +149,30 @@ void gfx_app_get_mouse_position(double* x, double* y) {
149 glfwGetCursorPos(g_gfx_app.window, x, y); 149 glfwGetCursorPos(g_gfx_app.window, x, y);
150} 150}
151 151
152static int to_glfw_mouse_button(MouseButton button);
153
154bool gfx_app_is_mouse_button_pressed(MouseButton button) {
155 return glfwGetMouseButton(g_gfx_app.window, to_glfw_mouse_button(button)) ==
156 GLFW_PRESS;
157}
158
152static int to_glfw_key(Key key); 159static int to_glfw_key(Key key);
153 160
154bool gfx_is_key_pressed(Key key) { 161bool gfx_app_is_key_pressed(Key key) {
155 return glfwGetKey(g_gfx_app.window, to_glfw_key(key)) == GLFW_PRESS; 162 return glfwGetKey(g_gfx_app.window, to_glfw_key(key)) == GLFW_PRESS;
156} 163}
157 164
165static int to_glfw_mouse_button(MouseButton button) {
166 switch (button) {
167 case LMB:
168 return GLFW_MOUSE_BUTTON_LEFT;
169 case RMB:
170 return GLFW_MOUSE_BUTTON_RIGHT;
171 case MMB:
172 return GLFW_MOUSE_BUTTON_MIDDLE;
173 }
174}
175
158static int to_glfw_key(Key key) { 176static int to_glfw_key(Key key) {
159 switch (key) { 177 switch (key) {
160 case KeyA: 178 case KeyA: