diff --git a/include/menu/gui/gui_menu_entry.h b/include/menu/gui/gui_menu_entry.h index a0fa10b1..91588519 100644 --- a/include/menu/gui/gui_menu_entry.h +++ b/include/menu/gui/gui_menu_entry.h @@ -43,7 +43,7 @@ gui_menu_entry_t *gui_create_menu_entry_no_bitmap(const char *text, u32 width, u32 height, int (*handler)(void *), void *param); /* Renders a gfx menu entry */ -void gui_menu_render_entry(gui_menu_entry_t*, bool); +void gui_menu_render_entry(gui_menu_entry_t*); /* Destroy menu entry */ void gui_menu_entry_destroy(gui_menu_entry_t*); diff --git a/include/utils/touch.h b/include/utils/touch.h index a3e72304..8bf27f5c 100644 --- a/include/utils/touch.h +++ b/include/utils/touch.h @@ -87,14 +87,11 @@ typedef struct { u16 y; } touch_event_t; -/* Set to true or create an empty file called "touch" inside "argon" dir to enable touch support */ -bool g_touch_enabled; /* Init touch support */ int touch_power_on(); /* Wait for touch input */ -/* No safe to call it when g_touch_enabled = false */ touch_event_t touch_wait(); /** diff --git a/src/core/custom-gui.c b/src/core/custom-gui.c index 239182fd..1c950c8a 100644 --- a/src/core/custom-gui.c +++ b/src/core/custom-gui.c @@ -105,6 +105,6 @@ int screenshot(void* params) g_gfx_con.scale = 2; gfx_con_setpos(&g_gfx_con, 0, 665); - gfx_printf(&g_gfx_con, " Screenshot saved!\n Found it at argon/screenshot.bmp"); + gfx_printf(&g_gfx_con, " Screenshot saved!\n Find it at argon/screenshot.bmp"); return 0; } \ No newline at end of file diff --git a/src/main.c b/src/main.c index 8342839e..5327bcd2 100644 --- a/src/main.c +++ b/src/main.c @@ -69,8 +69,6 @@ void ipl_main() g_gfx_con.mute = 0; /* Cofigure touch input */ - /* If touch file exists enable touch support*/ - g_touch_enabled = true; touch_power_on(); /* Mount Sd card and launch payload */ diff --git a/src/menu/gui/gui_menu.c b/src/menu/gui/gui_menu.c index 7f82410a..b11794d8 100644 --- a/src/menu/gui/gui_menu.c +++ b/src/menu/gui/gui_menu.c @@ -32,18 +32,17 @@ #define MINOR_VERSION 2 #define MAJOR_VERSION 0 -bool g_first_render = true; /* Render the menu */ +static void gui_menu_render_menu(gui_menu_t*); static void gui_menu_draw_background(gui_menu_t*); static void gui_menu_draw_entries(gui_menu_t*); /* Update menu after an input */ static int gui_menu_update(gui_menu_t*); -/* Handle inputs input */ +/* Handle input */ static int handle_touch_input(gui_menu_t*); -static int handle_btn_input(gui_menu_t*); gui_menu_t *gui_menu_create(const char *title) { @@ -80,38 +79,29 @@ static void gui_menu_draw_background(gui_menu_t* menu) } } +static void gui_menu_render_menu(gui_menu_t* menu) +{ + gui_menu_draw_background(menu); + gui_menu_draw_entries(menu); + gfx_swap_buffer(&g_gfx_ctxt); +} + static void gui_menu_draw_entries(gui_menu_t *menu) { for (s16 i = 0; i < menu->next_entry; i++) - gui_menu_render_entry(menu->entries[i], i == menu->selected_index); + gui_menu_render_entry(menu->entries[i]); } -static bool first_render = true; static int gui_menu_update(gui_menu_t *menu) { u32 res = 0; + gui_menu_draw_background(menu); - - if (first_render) - { - /* When first render, we must render all because input is blocking */ - gui_menu_draw_entries(menu); - gfx_swap_buffer(&g_gfx_ctxt); - } + gui_menu_draw_entries(menu); - if (!g_touch_enabled) - res = handle_btn_input(menu); - else - res = handle_touch_input(menu); + res = handle_touch_input(menu); - if (first_render) /* Force render background because on first render we flushed buffers before input */ - { - gui_menu_draw_background(menu); - first_render = false; - } - /* Draw entries after handling input */ - gui_menu_draw_entries(menu); gfx_swap_buffer(&g_gfx_ctxt); return res; @@ -120,6 +110,11 @@ static int gui_menu_update(gui_menu_t *menu) int gui_menu_open(gui_menu_t *menu) { gfx_con_setcol(&g_gfx_con, 0xFFF9F9F9, 0, 0xFF191414); + /* + * Render and flush at first render because blocking input won't allow us + * flush buffers + */ + gui_menu_render_menu(menu); while (gui_menu_update(menu)) ; @@ -157,32 +152,3 @@ static int handle_touch_input(gui_menu_t *menu) return 1; } - - -static int handle_btn_input(gui_menu_t *menu) -{ - gui_menu_entry_t *entry = NULL; - u32 input; - - input = btn_wait(); - - if ((input & BTN_VOL_DOWN) && menu->selected_index > 0) - { - menu->selected_index--; - } - else if ((input & BTN_VOL_UP) && menu->selected_index < menu->next_entry - 1) - { - menu->selected_index++; - } - else if (input & BTN_POWER) - { - entry = menu->entries[menu->selected_index]; - if (entry->handler != NULL) - { - if (entry->handler(entry->param) != 0) - return 0; - } - } - - return 1; -} diff --git a/src/menu/gui/gui_menu_entry.c b/src/menu/gui/gui_menu_entry.c index 70f4b7dc..69d86799 100644 --- a/src/menu/gui/gui_menu_entry.c +++ b/src/menu/gui/gui_menu_entry.c @@ -40,9 +40,10 @@ gui_menu_entry_t *gui_create_menu_entry(const char *text, if (bitmap != NULL) { + /* When not using the default icon set the text empty */ + /* User knows which icon he uses for each payload */ menu_entry->bitmap = bitmap; - if (g_touch_enabled) - strcpy(menu_entry->text, ""); // If not default icon, text is not needed on touch input + strcpy(menu_entry->text, ""); // If not default icon, text is not needed on touch input } else menu_entry->bitmap = sd_file_read(DEFAULT_LOGO); @@ -80,7 +81,7 @@ static u32 get_text_width(char *text) return lenght * g_gfx_con.scale * (u32)CHAR_WIDTH; } -static void render_text_centered(gui_menu_entry_t *entry, char *text, bool selected) +static void render_text_centered(gui_menu_entry_t *entry, char *text) { g_gfx_con.scale = 2; @@ -88,25 +89,20 @@ static void render_text_centered(gui_menu_entry_t *entry, char *text, bool selec s32 x_offset = -(get_text_width(text) - entry->width) / 2; u32 y_offset = entry->bitmap != NULL ? entry->height + 20 : 0; - u32 prevColor = g_gfx_con.fgcol; - g_gfx_con.scale = 2; gfx_con_setpos(&g_gfx_con, entry->x + x_offset, entry->y + y_offset); - if (selected && !g_touch_enabled) /* If touch is enabled there s no selected text */ - gfx_printf(&g_gfx_con, "%k%s%k", 0xFF1971FF, entry->text, prevColor); - else - gfx_printf(&g_gfx_con, "%s", entry->text); + gfx_printf(&g_gfx_con, "%s", entry->text); } /* Renders a gfx menu entry */ -void gui_menu_render_entry(gui_menu_entry_t* entry, bool selected) +void gui_menu_render_entry(gui_menu_entry_t* entry) { gfx_render_bmp_arg_bitmap(&g_gfx_ctxt, entry->bitmap, entry->x, entry->y, entry->width, entry->height); - render_text_centered(entry, entry->text, selected); + render_text_centered(entry, entry->text); } void gui_menu_entry_destroy(gui_menu_entry_t *entry) diff --git a/src/utils/touch.c b/src/utils/touch.c index a859649d..6b468d75 100644 --- a/src/utils/touch.c +++ b/src/utils/touch.c @@ -64,13 +64,12 @@ static void touch_poll(touch_event_t *event) touch_event_t touch_wait() { touch_event_t event; - if (g_touch_enabled) - { - do - { - touch_poll(&event); - } while(event.type != STMFTS_EV_MULTI_TOUCH_ENTER); - } + + do + { + touch_poll(&event); + } while(event.type != STMFTS_EV_MULTI_TOUCH_ENTER); + return event; } @@ -78,11 +77,6 @@ int touch_power_on() { int err; - /* Avoid switch freeze if touch support is not enabled */ - if (!g_touch_enabled) - { - return -1; - } /* * The datasheet does not specify the power on time, but considering * that the reset time is < 10ms, I sleep 20ms to be sure @@ -118,7 +112,7 @@ int touch_power_on() bool is_rect_touched(touch_event_t* event, u32 x, u32 y, u32 width, u32 height) { - if (!g_touch_enabled || event == NULL) + if (event == NULL) return false; u32 event_x = event->y;