From 992e7fb9358a0d0a5d99ba119cf584477bda8d72 Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Fri, 24 Jun 2022 17:28:38 +0200 Subject: 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). --- src/peripheral/CMakeLists.txt | 2 +- src/peripheral/inc/peripheral.h | 1 + src/peripheral/src/peripheral.c | 25 +++++++++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) (limited to 'src/peripheral') 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 +#include #include #include #include +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; +} -- cgit v1.2.3