From 5fe10ab2295e99a4fbac49b7cef0a248dc5ad62f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Wiecz=C3=B3r-Retman?= Date: Mon, 29 May 2023 13:36:41 +0200 Subject: [PATCH] sdl_milton: Logic for stylus buttons with gui Added clauses so that when a button on the stylus is pressed an appropriate functionality is called based on the gui radio buttons in settings --- src/sdl_milton.cc | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/sdl_milton.cc b/src/sdl_milton.cc index e6374309..15839fe6 100644 --- a/src/sdl_milton.cc +++ b/src/sdl_milton.cc @@ -214,6 +214,26 @@ panning_update(PlatformState* platform) } } +static void stylus_buttons_exec_function(MiltonInput *milton_input, Milton *milton, int mode) +{ + switch (mode) { + case STYLUS_DEFAULT: + break; + case STYLUS_ERASER: + milton_input->mode_to_set = MiltonMode::ERASER; + break; + case STYLUS_BRUSH: + milton_input->mode_to_set = MiltonMode::PEN; + break; + case STYLUS_DECB: + for (int i=0;i<5;++i) milton_decrease_brush_size(milton); + break; + case STYLUS_INCB: + for (int i=0;i<5;++i) milton_increase_brush_size(milton); + break; + } +} + MiltonInput sdl_event_loop(Milton* milton, PlatformState* platform) { @@ -277,6 +297,9 @@ sdl_event_loop(Milton* milton, PlatformState* platform) if(bit_lower && platform->lower_button == STYLUS_BUTTON_NOT_PRESSED) { if(platform->lower_button == STYLUS_BUTTON_NOT_PRESSED) { platform->lower_button = STYLUS_BUTTON_PRESSED; + stylus_buttons_exec_function(&milton_input, + milton, + milton->settings->lower_button); } } @@ -287,6 +310,9 @@ sdl_event_loop(Milton* milton, PlatformState* platform) if(bit_upper) { if(platform->upper_button == STYLUS_BUTTON_NOT_PRESSED) { platform->upper_button = STYLUS_BUTTON_PRESSED; + stylus_buttons_exec_function(&milton_input, + milton, + milton->settings->upper_button); } }