From 7197d4291eb4d1070375cf1f44e8bfc91d077c3f Mon Sep 17 00:00:00 2001 From: Marcelo Lorenzati Date: Sun, 4 Feb 2024 22:04:26 -0300 Subject: [PATCH] gain_offset: multi option gain offset menu --- .vscode/settings.json | 3 ++- src/gui/gui.c | 8 ++++---- src/menu/menu.c | 14 ++++++++------ src/menu/menuCallback.c | 40 +++++++++++++++++++++++++++++++++------- src/menu/menuCallback.h | 5 ++++- src/menu/menuGlobals.c | 4 +++- src/menu/menuGlobals.h | 6 +++++- 7 files changed, 59 insertions(+), 21 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 25eea85..701f0c3 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -48,7 +48,8 @@ "flash.h": "c", "vector": "c", "initializer_list": "c", - "retro_logo_128x128_rgb.h": "c" + "retro_logo_128x128_rgb.h": "c", + "menuglobals.h": "c" }, "cortex-debug.variableUseNaturalFormat": true } diff --git a/src/gui/gui.c b/src/gui/gui.c index bbd6e19..54983c8 100644 --- a/src/gui/gui.c +++ b/src/gui/gui.c @@ -493,9 +493,9 @@ gui_object_t *gui_event(gui_status_t status, gui_object_t *origin) { gui_event(update_status.bits, update_dest); } - // Check if it was a focus request and it's not focusable - // WARNING: Request focus over a list of chained elements with at least one focusable - if (status.focused && !origin->base.properties.focusable && !status.go_next & !status.go_previous) { + // Check if it was a focus request and it's not focusable/enabled + // WARNING: Request focus over a list of chained elements with at least one focusable/enabled + if (status.focused && (!origin->base.properties.focusable || !origin->base.status.enabled) && !status.go_next & !status.go_previous) { status.go_next = 1; } @@ -513,7 +513,7 @@ gui_object_t *gui_event(gui_status_t status, gui_object_t *origin) { test_focused = test_focused->previous; } - if (test_focused->base.properties.focusable) { + if (test_focused->base.properties.focusable && test_focused->base.status.enabled) { status.go_next = 0; status.go_previous = 0; next_focused = test_focused; diff --git a/src/menu/menu.c b/src/menu/menu.c index b24db34..a5a03f0 100644 --- a/src/menu/menu.c +++ b/src/menu/menu.c @@ -232,12 +232,12 @@ gui_object_t menu_create_left_button_group(menu_button_group_type previous, menu case menu_button_sub_group_gain_offset: { gui_object_t elements[] = { gui_create_slider(&menu_overlay_ctx, 0, 0, 200, 12, &menu_colors_list, menu_spinbox_props, &gain_offset_slider_option), - gui_create_label(&menu_overlay_ctx, 0, 0, 200, 11, &menu_colors_list, menu_common_nshared_props, menu_gain_offset_opt_print), - gui_create_spinbox(&menu_overlay_ctx, 0, 0, 120, 12, &menu_colors_list, menu_spinbox_props, &spinbox_gain_offset_red), - gui_create_spinbox(&menu_overlay_ctx, 0, 0, 120, 12, &menu_colors_list, menu_spinbox_props, &spinbox_gain_offset_green), - gui_create_spinbox(&menu_overlay_ctx, 0, 0, 120, 12, &menu_colors_list, menu_spinbox_props, &spinbox_gain_offset_blue), - gui_create_window(&menu_overlay_ctx, 0, 0, 200, 12, &menu_colors_list, menu_common_label_props), - gui_create_spinbox(&menu_overlay_ctx, 0, 0, 120, 12, &menu_colors_list, menu_spinbox_props, &spinbox_gain_offset_unified), + gui_create_label(&menu_overlay_ctx, 0, 0, 200, 11, &menu_colors_list, menu_common_label_props, menu_gain_offset_rgb_opt_print), + gui_create_spinbox(&menu_overlay_ctx, 0, 0, 200, 12, &menu_colors_list, menu_spinbox_props, &spinbox_gain_offset_red), + gui_create_spinbox(&menu_overlay_ctx, 0, 0, 200, 12, &menu_colors_list, menu_spinbox_props, &spinbox_gain_offset_green), + gui_create_spinbox(&menu_overlay_ctx, 0, 0, 200, 12, &menu_colors_list, menu_spinbox_props, &spinbox_gain_offset_blue), + gui_create_label(&menu_overlay_ctx, 0, 0, 200, 11, &menu_colors_list, menu_common_label_props, menu_gain_offset_unified_opt_print), + gui_create_spinbox(&menu_overlay_ctx, 0, 0, 200, 12, &menu_colors_list, menu_spinbox_props, &spinbox_gain_offset_unified), gui_create_button(&menu_overlay_ctx, 0, 0, 200, 12, &menu_colors_list, menu_common_nshared_props, "Back") }; menu_elements_copy(elements, menu_left_buttons_group_elements); @@ -245,7 +245,9 @@ gui_object_t menu_create_left_button_group(menu_button_group_type previous, menu menu_left_buttons_group_list = group_list; gui_event_subscribe(spinbox_status, &menu_left_buttons_group_elements[0].base, &menu_left_buttons_group_elements[0], on_gain_offset_option_event); gui_event_subscribe(spinbox_status, &menu_left_buttons_group_elements[0].base, &menu_left_buttons_group_elements[1], NULL); + gui_event_subscribe(spinbox_status, &menu_left_buttons_group_elements[0].base, &menu_left_buttons_group_elements[5], NULL); gui_event_subscribe(button_status, &menu_left_buttons_group_elements[7].base, &menu_left_buttons_group_elements[7], on_back_event); + menu_update_gain_offset_sliders(); } break; case menu_button_sub_group_diagnostic: { diff --git a/src/menu/menuCallback.c b/src/menu/menuCallback.c index eba8abb..253d716 100644 --- a/src/menu/menuCallback.c +++ b/src/menu/menuCallback.c @@ -166,17 +166,38 @@ bool on_palette_option_event(gui_status_t status, gui_base_t *origin, gui_object return true; } +void menu_update_gain_offset_sliders(void) { + uint index = gain_offset_slider_option * (MENU_GAIN_OFFSET_OPT - 1) / GUI_BAR_100PERCENT; + + if (index <= MENU_GAIN_OFFSET_UNI) { + gui_disable(&menu_left_buttons_group_elements[2]); + gui_disable(&menu_left_buttons_group_elements[3]); + gui_disable(&menu_left_buttons_group_elements[4]); + gui_enable(&menu_left_buttons_group_elements[6]); + } else { + gui_enable(&menu_left_buttons_group_elements[2]); + gui_enable(&menu_left_buttons_group_elements[3]); + gui_enable(&menu_left_buttons_group_elements[4]); + gui_disable(&menu_left_buttons_group_elements[6]); + } +} + bool on_gain_offset_option_event(gui_status_t status, gui_base_t *origin, gui_object_t *destination) { uint *data = (uint *) origin->data; if (!status.activated && origin->status.activated) { destination->base.status.navigable = !destination->base.status.navigable; + destination->base.status.data_changed = 1; } else if (status.add && *data < GUI_BAR_100PERCENT) { - *data += (GUI_BAR_100PERCENT/(arraySize(menu_gain_offset_str) - 1)); + *data += (GUI_BAR_100PERCENT/(MENU_GAIN_OFFSET_OPT - 1)); + destination->base.status.data_changed = 1; } else if (status.substract && *data != 0) { - *data -= (GUI_BAR_100PERCENT/(arraySize(menu_gain_offset_str) - 1)); + *data -= (GUI_BAR_100PERCENT/(MENU_GAIN_OFFSET_OPT - 1)); + destination->base.status.data_changed = 1; + } + if (destination->base.status.data_changed) { + menu_update_gain_offset_sliders(); } - - destination->base.status.data_changed = 1; + return true; } @@ -324,9 +345,14 @@ void menu_palette_opt_print(print_delegate_t printer) { printer("%s", gui_colors_str[index]); } -void menu_gain_offset_opt_print(print_delegate_t printer) { - uint index = gain_offset_slider_option * (arraySize(menu_gain_offset_str) - 1) / GUI_BAR_100PERCENT; - printer("%s", menu_gain_offset_str[index]); +void menu_gain_offset_rgb_opt_print(print_delegate_t printer) { + uint index = gain_offset_slider_option * (MENU_GAIN_OFFSET_OPT - 1) / GUI_BAR_100PERCENT; + printer("%s", menu_gain_offset_rgb_str[index]); +} + +void menu_gain_offset_unified_opt_print(print_delegate_t printer) { + uint index = gain_offset_slider_option * (arraySize(menu_gain_offset_unified_str) - 1) / GUI_BAR_100PERCENT; + printer("%s", menu_gain_offset_unified_str[index]); } // --------- GUI Callbacks END --------- diff --git a/src/menu/menuCallback.h b/src/menu/menuCallback.h index 583c76c..1aba748 100644 --- a/src/menu/menuCallback.h +++ b/src/menu/menuCallback.h @@ -22,8 +22,10 @@ void gui_draw_palette_choice(gui_base_t *base); void menu_diagnostic_print(print_delegate_t printer); void menu_scan_print(print_delegate_t printer); void menu_palette_opt_print(print_delegate_t printer); -void menu_gain_offset_opt_print(print_delegate_t printer); +void menu_gain_offset_rgb_opt_print(print_delegate_t printer); +void menu_gain_offset_unified_opt_print(print_delegate_t printer); void menu_about_print(print_delegate_t printer); +void menu_update_gain_offset_sliders(void); //Utility void menu_setup_selected_color(); @@ -31,4 +33,5 @@ const char *menu_get_usb_button_txt(bool status); const char *menu_get_shutdown_opt_txt(bool status); const char *menu_get_scanline_opt_txt(bool status); const char *menu_get_display_mode_opt_txt(bool mode, bool confirmation); + #endif \ No newline at end of file diff --git a/src/menu/menuGlobals.c b/src/menu/menuGlobals.c index e6c7156..28e9a8c 100644 --- a/src/menu/menuGlobals.c +++ b/src/menu/menuGlobals.c @@ -66,5 +66,7 @@ bool menu_usb_enabled = false; bool menu_display_confirmation=false; display_t *menu_current_display; uint color_black, color_white; -const char *menu_gain_offset_str[5] = { "unified gain", "unified offset", "negative offset", "split gain", "split offset"}; +const char *menu_gain_offset_rgb_str[MENU_GAIN_OFFSET_OPT] = { "", "", "", "RGB gain", "RGB offset"}; +const char *menu_gain_offset_unified_str[MENU_GAIN_OFFSET_OPT] = { "Unified gain", "Unified offset", "Negative offset", "", ""}; + // --------- Global register end --------- \ No newline at end of file diff --git a/src/menu/menuGlobals.h b/src/menu/menuGlobals.h index e62773a..3f50c71 100644 --- a/src/menu/menuGlobals.h +++ b/src/menu/menuGlobals.h @@ -9,6 +9,9 @@ #define MENU_TOTAL_NAV_STACK 4 #define MENU_TOTAL_LEFT_BUTTONS 8 #define MENU_TOTAL_MAIN_VIEW 4 +#define MENU_GAIN_OFFSET_OPT 5 +#define MENU_GAIN_OFFSET_UNI 2 + // ------------ Defines End ------------ // ------------ Enum / Struct Start ------------ @@ -75,5 +78,6 @@ extern bool menu_usb_enabled; extern display_t *menu_current_display; extern uint color_black, color_white; extern bool menu_display_confirmation; -extern const char *menu_gain_offset_str[5]; +extern const char *menu_gain_offset_rgb_str[MENU_GAIN_OFFSET_OPT]; +extern const char *menu_gain_offset_unified_str[MENU_GAIN_OFFSET_OPT]; #endif \ No newline at end of file