aboutsummaryrefslogtreecommitdiff
path: root/src/sdl/action.c
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2019-01-13 08:29:12 -0500
committerPaul Duncan <pabs@pablotron.org>2019-01-13 08:29:12 -0500
commitcd0f70f86d1cedffcd1bacf57d9250fdff1f7af3 (patch)
treea7be11a817a89e47700691f5042ba005e756bc4a /src/sdl/action.c
parenta3f788b6a64bbf89342fec2111eb1e1b478db13f (diff)
downloadsok-cd0f70f86d1cedffcd1bacf57d9250fdff1f7af3.tar.bz2
sok-cd0f70f86d1cedffcd1bacf57d9250fdff1f7af3.zip
refactor sok-sdl, add zoom and warp_buf support
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 };
+ }
+}