aboutsummaryrefslogtreecommitdiff
path: root/src/sdl/action.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sdl/action.c')
-rw-r--r--src/sdl/action.c37
1 files changed, 35 insertions, 2 deletions
diff --git a/src/sdl/action.c b/src/sdl/action.c
index a4dcb79..8307f19 100644
--- a/src/sdl/action.c
+++ b/src/sdl/action.c
@@ -24,8 +24,8 @@ keycode_to_dir(const SDL_Keycode code) {
}
}
-action_t
-get_action(
+static action_t
+get_key_action(
const SDL_Keycode code
) {
switch (code) {
@@ -61,3 +61,36 @@ get_action(
return (action_t) { .type = ACTION_NONE };
}
}
+
+static action_t
+get_wheel_action(
+ const Sint32 y
+) {
+ if (y > 0) {
+ return (action_t) { .type = ACTION_ZOOM_IN, .data = y };
+ } else if (y < 0) {
+ return (action_t) { .type = ACTION_ZOOM_OUT, .data = -y };
+ } else {
+ return (action_t) { .type = ACTION_NONE };
+ }
+}
+
+action_t
+get_action(
+ const SDL_Event * const ev
+) {
+ switch (ev->type) {
+ case SDL_QUIT:
+ return (action_t) { .type = ACTION_QUIT };
+ break;
+ case SDL_KEYUP:
+ return get_key_action(ev->key.keysym.sym);
+ break;
+ case SDL_MOUSEWHEEL:
+ return get_wheel_action(ev->wheel.y);
+ break;
+ default:
+ // ignore event
+ return (action_t) { .type = ACTION_NONE };
+ }
+}