From b5e69abc838ac79ea61ca4532986f50be1a69742 Mon Sep 17 00:00:00 2001 From: Adolfo Reyna Date: Thu, 12 Feb 2026 20:46:41 -0500 Subject: [PATCH] Add virtual navigation buttons to game launcher - Display < PREV and NEXT > buttons at bottom of screen when multiple pages exist - Buttons are touchable and respond to taps - Button dimensions: 150x40 at y=235 - PREV button: x=30, NEXT button: x=200 - Updated instructions to show 'Touch buttons or KEY0/KEY1' - Both KEY0/KEY1 and touch button presses navigate pages - Updated lib/ and emulator/ versions --- .gitignore | 11 ++++++- emulator/game_launcher.cpp | 44 +++++++++++++++++++--------- emulator/game_launcher.h | 5 ++++ lib/game_launcher.cpp | 59 +++++++++++++++++++++++++++++--------- lib/game_launcher.h | 5 ++++ 5 files changed, 96 insertions(+), 28 deletions(-) diff --git a/.gitignore b/.gitignore index 90813ad..334b961 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,12 @@ build !.vscode/* -build*/ \ No newline at end of file +build*/ +*.o +*.o.d +*.a +*.so +*.dylib +CMakeFiles/ +*.cmake +emulator/build/ +.DS_Store \ No newline at end of file diff --git a/emulator/game_launcher.cpp b/emulator/game_launcher.cpp index 93a63c1..d380d34 100644 --- a/emulator/game_launcher.cpp +++ b/emulator/game_launcher.cpp @@ -39,26 +39,45 @@ void GameLauncher::draw() { renderer->draw_string_scaled(50, y + 36, games[i].description, 1); } - char nav_text[128]; if (total_pages > 1) { - snprintf(nav_text, sizeof(nav_text), "KEY0: Next Page | KEY1: Select"); + int button_y = height - 65; + gui->draw_button(window, PREV_BUTTON_X, button_y, "< PREV", false, true); + gui->draw_button(window, NEXT_BUTTON_X, button_y, "NEXT >", false, true); + renderer->set_font(&font_5x5_obj); + renderer->draw_string_scaled(30, height - 25, "Touch buttons or KEY0/KEY1", 1); } else { - snprintf(nav_text, sizeof(nav_text), "KEY0: Navigate | KEY1: Select"); + renderer->set_font(&font_5x5_obj); + renderer->draw_string_scaled(30, height - 35, "KEY0: Navigate | KEY1: Select | Touch to play", 1); } - - const char* instructions; - if (input_manager->has_buttons()) { - instructions = nav_text; - } else { - instructions = "Touch game to play"; - } - renderer->set_font(&font_5x5_obj); - renderer->draw_string_scaled(30, height - 35, instructions, 2); } bool GameLauncher::update(const InputEvent& event) { bool needs_refresh = false; + int total_pages = get_total_pages(); + switch (event.type) { case INPUT_TOUCH_DOWN: { + // Check if touch is on navigation buttons (if multiple pages) + if (total_pages > 1) { + if (event.x >= PREV_BUTTON_X && event.x < PREV_BUTTON_X + BUTTON_WIDTH && + event.y >= NAV_BUTTON_Y && event.y < NAV_BUTTON_Y + BUTTON_HEIGHT) { + if (current_page > 0) { + current_page--; + selected_index = get_page_start_index(); + needs_refresh = true; + } + break; + } + if (event.x >= NEXT_BUTTON_X && event.x < NEXT_BUTTON_X + BUTTON_WIDTH && + event.y >= NAV_BUTTON_Y && event.y < NAV_BUTTON_Y + BUTTON_HEIGHT) { + if (current_page + 1 < total_pages) { + current_page++; + selected_index = get_page_start_index(); + needs_refresh = true; + } + break; + } + } + int page_start = get_page_start_index(); int page_end = get_page_end_index(); @@ -79,7 +98,6 @@ bool GameLauncher::update(const InputEvent& event) { case INPUT_BUTTON_0: { int page_start = get_page_start_index(); int page_end = get_page_end_index(); - int total_pages = get_total_pages(); if (page_end - page_start > 1) { int old_index = selected_index; diff --git a/emulator/game_launcher.h b/emulator/game_launcher.h index e7a4994..852dea4 100644 --- a/emulator/game_launcher.h +++ b/emulator/game_launcher.h @@ -43,6 +43,11 @@ private: static const int MENU_ITEM_HEIGHT = 40; static const int MENU_PADDING = 10; static const int GAMES_PER_PAGE = 4; + static const int NAV_BUTTON_Y = 235; + static const int PREV_BUTTON_X = 30; + static const int NEXT_BUTTON_X = 200; + static const int BUTTON_WIDTH = 150; + static const int BUTTON_HEIGHT = 40; int get_total_pages() const; int get_page_start_index() const; diff --git a/lib/game_launcher.cpp b/lib/game_launcher.cpp index cebddf4..38150ed 100644 --- a/lib/game_launcher.cpp +++ b/lib/game_launcher.cpp @@ -57,32 +57,64 @@ void GameLauncher::draw() { renderer->draw_string_scaled(50, y + 36, games[i].description, 1); } - // Draw pagination controls at bottom - char nav_text[128]; + // Draw navigation buttons at bottom (only if multiple pages) if (total_pages > 1) { - snprintf(nav_text, sizeof(nav_text), "KEY0: Next Page | KEY1: Select"); + int button_y = height - 65; + + // Previous page button + bool has_prev = (current_page > 0); + gui->draw_button(window, 30, button_y, "< PREV", false, true); + + // Next page button + bool has_next = (current_page + 1 < total_pages); + gui->draw_button(window, 200, button_y, "NEXT >", false, true); + + // Draw instructions + renderer->set_font(&font_5x5_obj); + renderer->draw_string_scaled(30, height - 25, "Touch buttons or KEY0/KEY1", 1); } else { - snprintf(nav_text, sizeof(nav_text), "KEY0: Navigate | KEY1: Select"); + // Single page - just show select instruction + renderer->set_font(&font_5x5_obj); + renderer->draw_string_scaled(30, height - 35, "KEY0: Navigate | KEY1: Select | Touch to play", 1); } - - const char* instructions; - if (input_manager->has_buttons()) { - instructions = nav_text; - } else { - instructions = "Touch game to play"; - } - renderer->set_font(&font_5x5_obj); - renderer->draw_string_scaled(30, height - 35, instructions, 2); } bool GameLauncher::update(const InputEvent& event) { bool needs_refresh = false; + int total_pages = get_total_pages(); switch (event.type) { case INPUT_TOUCH_DOWN: { printf("Touch at (%d,%d) in launcher\n", event.x, event.y); + // Check if touch is on navigation buttons (if multiple pages) + if (total_pages > 1) { + // Previous button: x [30-180], y [235-275] + if (event.x >= PREV_BUTTON_X && event.x < PREV_BUTTON_X + BUTTON_WIDTH && + event.y >= NAV_BUTTON_Y && event.y < NAV_BUTTON_Y + BUTTON_HEIGHT) { + if (current_page > 0) { + current_page--; + selected_index = get_page_start_index(); + needs_refresh = true; + printf("Navigated to previous page: %d\n", current_page); + } + break; + } + + // Next button: x [200-350], y [235-275] + if (event.x >= NEXT_BUTTON_X && event.x < NEXT_BUTTON_X + BUTTON_WIDTH && + event.y >= NAV_BUTTON_Y && event.y < NAV_BUTTON_Y + BUTTON_HEIGHT) { + if (current_page + 1 < total_pages) { + current_page++; + selected_index = get_page_start_index(); + needs_refresh = true; + printf("Navigated to next page: %d\n", current_page); + } + break; + } + } + // Check if touch is on a game entry for current page int page_start = get_page_start_index(); int page_end = get_page_end_index(); @@ -110,7 +142,6 @@ bool GameLauncher::update(const InputEvent& event) { // Navigate within current page or switch pages int page_start = get_page_start_index(); int page_end = get_page_end_index(); - int total_pages = get_total_pages(); // If multiple games on current page, navigate within page first if (page_end - page_start > 1) { diff --git a/lib/game_launcher.h b/lib/game_launcher.h index 8759f3c..be9d24e 100644 --- a/lib/game_launcher.h +++ b/lib/game_launcher.h @@ -102,6 +102,11 @@ private: static const int MENU_ITEM_HEIGHT = 40; static const int MENU_PADDING = 10; static const int GAMES_PER_PAGE = 4; + static const int NAV_BUTTON_Y = 235; // Bottom navigation buttons + static const int PREV_BUTTON_X = 30; + static const int NEXT_BUTTON_X = 200; + static const int BUTTON_WIDTH = 150; + static const int BUTTON_HEIGHT = 40; // Helper functions for pagination int get_total_pages() const;