diff options
| author | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2022-06-24 17:28:38 +0200 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2022-06-24 17:28:38 +0200 |
| commit | 992e7fb9358a0d0a5d99ba119cf584477bda8d72 (patch) | |
| tree | 1cd753a73b560e60e0de353b9a1b7d0e15b002d6 /src/peripheral | |
| parent | 5ac01ff845f37fadd1822f99149f1b610f510bba (diff) | |
| download | rts-992e7fb9358a0d0a5d99ba119cf584477bda8d72.tar.gz | |
peripheral: provide common actions
Whereas some actions are context-specific (e.g.: selecting a player),
some are context-independent and can be executed for all screens
(e.g.: exiting the game).
Diffstat (limited to 'src/peripheral')
| -rw-r--r-- | src/peripheral/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/peripheral/inc/peripheral.h | 1 | ||||
| -rw-r--r-- | src/peripheral/src/peripheral.c | 25 |
3 files changed, 27 insertions, 1 deletions
diff --git a/src/peripheral/CMakeLists.txt b/src/peripheral/CMakeLists.txt index 9666a5c..54f5f1b 100644 --- a/src/peripheral/CMakeLists.txt +++ b/src/peripheral/CMakeLists.txt @@ -1,3 +1,3 @@ add_library(peripheral "src/peripheral.c") target_include_directories(peripheral PUBLIC "inc") -target_link_libraries(peripheral PUBLIC pad mouse keyboard util) +target_link_libraries(peripheral PUBLIC pad mouse keyboard util PRIVATE gfx) diff --git a/src/peripheral/inc/peripheral.h b/src/peripheral/inc/peripheral.h index c405c3c..956d965 100644 --- a/src/peripheral/inc/peripheral.h +++ b/src/peripheral/inc/peripheral.h @@ -25,6 +25,7 @@ union peripheral struct peripheral_common { enum peripheral_type type; + bool exit; } common; struct peripheral_pad diff --git a/src/peripheral/src/peripheral.c b/src/peripheral/src/peripheral.c index a1f61be..c461573 100644 --- a/src/peripheral/src/peripheral.c +++ b/src/peripheral/src/peripheral.c @@ -1,8 +1,26 @@ #include <peripheral.h> +#include <gfx.h> #include <keyboard.h> #include <mouse.h> #include <pad.h> +static void update_pad_common(union peripheral *const p) +{ + if (pad_justpressed(&p->pad.pad, PAD_KEY_EXIT)) + p->common.exit = true; +} + +static void update_kbm_common(union peripheral *const p) +{ + struct peripheral_kbm *const kbm = &p->kbm; + struct keyboard *const k = &kbm->keyboard; + + if (keyboard_justpressed(k, &KEYBOARD_COMBO(KEYBOARD_KEY_EXIT))) + p->common.exit = true; + else if (keyboard_justreleased(k, &KEYBOARD_COMBO(KEYBOARD_KEY_F11))) + gfx_toggle_fullscreen(); +} + void peripheral_update(union peripheral *const p) { switch (p->common.type) @@ -12,10 +30,12 @@ void peripheral_update(union peripheral *const p) case PERIPHERAL_TYPE_KEYBOARD_MOUSE: mouse_update(&p->kbm.mouse); keyboard_update(&p->kbm.keyboard); + update_kbm_common(p); break; case PERIPHERAL_TYPE_PAD: pad_update(&p->pad.pad); + update_pad_common(p); break; } } @@ -39,3 +59,8 @@ void peripheral_init(const struct peripheral_cfg *const cfg, break; } } + +int peripheral_get_default(struct peripheral_cfg *const cfg) +{ + return -1; +} |
