147 lines
3.9 KiB
C
147 lines
3.9 KiB
C
#include "ui.h"
|
|
#include "menu.h"
|
|
#include "display.h"
|
|
#include "main.h"
|
|
#include "graphics/graphics.h"
|
|
|
|
void ui_enter_submenu(void *const args);
|
|
void ui_toggle_led1(void *const args);
|
|
void ui_toggle_led2(void *const args);
|
|
void ui_draw_toggle_led1_switch(const menu_entry_size_t *const menu_entry_size, void *const args);
|
|
void ui_draw_toggle_led2_switch(const menu_entry_size_t *const menu_entry_size, void *const args);
|
|
|
|
/******************* */
|
|
/* Menu declarations */
|
|
/******************* */
|
|
|
|
static graphical_menu_t main_menu;
|
|
static graphical_menu_t runescape_memes_menu;
|
|
|
|
/******************* */
|
|
/* Menu definitions */
|
|
/******************* */
|
|
|
|
static graphical_menu_t main_menu = {
|
|
.parent_menu = 0,
|
|
.num_children = 3,
|
|
.highlighted_child_idx = 0,
|
|
.children = (graphical_menu_entry_t[]){
|
|
{
|
|
.title = "runescape memes menu",
|
|
.selected_callback_function = ui_enter_submenu,
|
|
.selected_callback_function_args = &runescape_memes_menu
|
|
},
|
|
{
|
|
.title = "Toggle LED1",
|
|
.disabled = true,
|
|
.selected_callback_function = ui_toggle_led1,
|
|
.selected_callback_function_args = 0,
|
|
.extra_draw_function = add_toggle_switch_to_menu_entry,
|
|
.extra_draw_function_args = (void *)&led1_state,
|
|
},
|
|
{
|
|
.title = "Toggle LED2",
|
|
.selected_callback_function = ui_toggle_led2,
|
|
.selected_callback_function_args = 0,
|
|
.extra_draw_function = add_toggle_switch_to_menu_entry,
|
|
.extra_draw_function_args = (void *)&led2_state,
|
|
}
|
|
}
|
|
};
|
|
|
|
static graphical_menu_t runescape_memes_menu = {
|
|
.parent_menu = &main_menu,
|
|
.num_children = 4,
|
|
.highlighted_child_idx = 0,
|
|
.children = (graphical_menu_entry_t[]){
|
|
{.title = "where varock", .disabled = false, .highlighted_callback_function = 0, .highlighted_callback_function_args = 0, .selected_callback_function = 0, .selected_callback_function_args = 0},
|
|
{.title = "you chop the tree", .disabled = false, .highlighted_callback_function = 0, .highlighted_callback_function_args = 0, .selected_callback_function = 0, .selected_callback_function_args = 0},
|
|
{.title = "you chop the tree", .disabled = false, .highlighted_callback_function = 0, .highlighted_callback_function_args = 0, .selected_callback_function = 0, .selected_callback_function_args = 0},
|
|
}
|
|
};
|
|
|
|
|
|
/********************** */
|
|
/* UI state definitions */
|
|
/********************** */
|
|
|
|
enum ui_state_t {
|
|
UI_STATE_MENU,
|
|
};
|
|
|
|
static bool redraw_requested = true;
|
|
// static enum ui_state_t ui_state = UI_STATE_MENU;
|
|
static graphical_menu_t *current_menu = &main_menu;
|
|
|
|
/********************** */
|
|
/* UI callback functions */
|
|
/********************** */
|
|
|
|
void ui_toggle_led1(void *const args)
|
|
{
|
|
LED1_TOGGLE();
|
|
ui_request_redraw();
|
|
}
|
|
|
|
void ui_toggle_led2(void *const args)
|
|
{
|
|
LED2_TOGGLE();
|
|
ui_request_redraw();
|
|
}
|
|
|
|
/************************* */
|
|
/* UI function definitions */
|
|
/************************* */
|
|
|
|
void ui_enter_submenu(void *const args)
|
|
{
|
|
current_menu = (graphical_menu_t *)args;
|
|
redraw_requested = true;
|
|
}
|
|
|
|
void ui_exit_submenu(void)
|
|
{
|
|
if (current_menu->parent_menu == 0)
|
|
{
|
|
return;
|
|
}
|
|
current_menu = current_menu->parent_menu;
|
|
redraw_requested = true;
|
|
}
|
|
|
|
void ui_left_button_pressed(void)
|
|
{
|
|
ui_exit_submenu();
|
|
}
|
|
|
|
void ui_up_button_pressed(void)
|
|
{
|
|
decrement_selected_menu_entry_idx(next_framebuffer, current_menu);
|
|
swap_framebuffers();
|
|
}
|
|
|
|
void ui_down_button_pressed(void)
|
|
{
|
|
increment_selected_menu_entry_idx(next_framebuffer, current_menu);
|
|
swap_framebuffers();
|
|
}
|
|
|
|
void ui_ok_button_pressed(void)
|
|
{
|
|
select_menu_entry(current_menu);
|
|
}
|
|
|
|
void ui_request_redraw(void)
|
|
{
|
|
redraw_requested = true;
|
|
}
|
|
|
|
void ui_task(void)
|
|
{
|
|
if (redraw_requested)
|
|
{
|
|
redraw_requested = false;
|
|
draw_menu(next_framebuffer, current_menu);
|
|
swap_framebuffers();
|
|
}
|
|
} |