Skip to content

Commit

Permalink
gain_offset: multi option gain offset menu
Browse files Browse the repository at this point in the history
  • Loading branch information
mlorenzati committed Feb 5, 2024
1 parent 0ecaf64 commit 7197d42
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 21 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
8 changes: 4 additions & 4 deletions src/gui/gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
Expand Down
14 changes: 8 additions & 6 deletions src/menu/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,20 +232,22 @@ 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);
gui_list_t group_list = initalizeGuiDynList(menu_left_buttons_group_elements, arraySize(elements));
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: {
Expand Down
40 changes: 33 additions & 7 deletions src/menu/menuCallback.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 ---------
Expand Down
5 changes: 4 additions & 1 deletion src/menu/menuCallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ 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();
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
4 changes: 3 additions & 1 deletion src/menu/menuGlobals.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ---------
6 changes: 5 additions & 1 deletion src/menu/menuGlobals.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 ------------
Expand Down Expand Up @@ -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

0 comments on commit 7197d42

Please sign in to comment.