Applying formatting and moving libraries into specific folders

This commit is contained in:
GearsProgress
2026-10-18 11:07:35 -04:00
parent 1e90aa40ce
commit f1e2b62e4a
74 changed files with 6147 additions and 5199 deletions

View File

@@ -1,12 +1,12 @@
#include "dbg/debug_menu.h"
#include "dbg/debug_menu_functions.h"
#include "sprite_data.h"
#include "background_engine.h"
#include "vertical_menu_cursor_handler.h"
#include "dbg/debug_menu_functions.h"
#include "libraries/nanoprintf/nanoprintf.h"
#include "sprite_data.h"
#include "vertical_menu_cursor_handler.h"
#include <tonc.h>
#include <cstdlib>
#include <tonc.h>
static on_execute_callback delayed_execute_callback = nullptr;
static void *delayed_execute_context = nullptr;
@@ -16,12 +16,10 @@ static unsigned delayed_execute_user_param = 0;
static DebugMenuSection current_menu_section[MAX_MENU_LAYERS];
static unsigned current_menu_section_stack_size;
static void pop_submenu()
{
--current_menu_section_stack_size;
}
static void pop_submenu() { --current_menu_section_stack_size; }
static __attribute__((noinline)) void show_debug_menu_internal(DebugMenuSection sectionType)
static __attribute__((noinline)) void show_debug_menu_internal(
DebugMenuSection sectionType)
{
u16 charset[256];
const s16 cursor_offset_x = 3;
@@ -36,8 +34,7 @@ static __attribute__((noinline)) void show_debug_menu_internal(DebugMenuSection
obj_unhide(toggle_arrow_left, 0);
const vertical_menu_settings menu_settings = {
.x = 20,
const vertical_menu_settings menu_settings = {.x = 20,
.y = 0,
.width = 208,
.height = 155,
@@ -48,10 +45,10 @@ static __attribute__((noinline)) void show_debug_menu_internal(DebugMenuSection
.text_table_index = INT32_MAX,
.allow_cancel = true,
.should_delete_item_widgets_on_destruct = true,
.should_hide_state_changed_handler_on_not_focused = true
};
.should_hide_state_changed_handler_on_not_focused = true};
vertical_menu_cursor_handler cursor_handler(cursor_offset_x, cursor_offset_y);
vertical_menu_cursor_handler cursor_handler(
cursor_offset_x, cursor_offset_y);
vertical_menu debug_menu(menu_settings);
debug_menu.set_state_changed_handler(&cursor_handler);
@@ -66,19 +63,21 @@ static __attribute__((noinline)) void show_debug_menu_internal(DebugMenuSection
hide_textbox();
tte_erase_rect(0, 0, H_MAX, V_MAX);
// execute any callback that was delayed by pressing the A button on an executable row.
// This is done to make sure the debug menu is fully hidden before executing the callback,
// to avoid rendering issues.
if(delayed_execute_callback)
// execute any callback that was delayed by pressing the A button on an
// executable row. This is done to make sure the debug menu is fully hidden
// before executing the callback, to avoid rendering issues.
if (delayed_execute_callback)
{
delayed_execute_callback(delayed_execute_context, delayed_execute_user_param);
delayed_execute_callback(
delayed_execute_context, delayed_execute_user_param);
delayed_execute_callback = nullptr;
delayed_execute_context = nullptr;
delayed_execute_user_param = 0;
}
else if(ret == UINT32_MAX)
else if (ret == UINT32_MAX)
{
// if the user cancelled out of the menu, we pop the submenu stack to go back to the previous menu.
// if the user cancelled out of the menu, we pop the submenu stack to go
// back to the previous menu.
pop_submenu();
}
}
@@ -89,12 +88,12 @@ void show_debug_menu()
current_menu_section_stack_size = 0;
push_debug_menu_section(DebugMenuSection::MAIN);
while(current_menu_section_stack_size > 0)
while (current_menu_section_stack_size > 0)
{
curr_section = current_menu_section[current_menu_section_stack_size - 1];
curr_section =
current_menu_section[current_menu_section_stack_size - 1];
show_debug_menu_internal(curr_section);
}
}
debug_menu_row_widget::debug_menu_row_widget(const debug_menu_row_data &data)
@@ -104,14 +103,15 @@ debug_menu_row_widget::debug_menu_row_widget(const debug_menu_row_data &data)
debug_menu_row_widget::~debug_menu_row_widget()
{
if(data_.option_section.should_free_on_destruct)
if (data_.option_section.should_free_on_destruct)
{
free(const_cast<option_data*>(data_.option_section.options));
free(const_cast<option_data *>(data_.option_section.options));
data_.option_section.options = nullptr;
}
}
void debug_menu_row_widget::render_item(FileContainerReader &text_table, unsigned x, unsigned y, bool is_focused)
void debug_menu_row_widget::render_item(
FileContainerReader &text_table, unsigned x, unsigned y, bool is_focused)
{
const int label_margin_left = 12;
const int margin_top = 2;
@@ -123,33 +123,43 @@ void debug_menu_row_widget::render_item(FileContainerReader &text_table, unsigne
tte_set_pos(x + label_margin_left, y + margin_top);
ptgb_write_debug(data_.charset, data_.labelText, true);
if(data_.option_section.num_options > 0)
if (data_.option_section.num_options > 0)
{
const u8 selected_option_index = data_.option_section.selected_option_index;
const u8 selected_option_index =
data_.option_section.selected_option_index;
tte_set_pos(x + option_margin_left, y + margin_top);
if(data_.option_section.options[selected_option_index].text)
if (data_.option_section.options[selected_option_index].text)
{
ptgb_write_debug(data_.charset, data_.option_section.options[selected_option_index].text, true);
ptgb_write_debug(data_.charset,
data_.option_section.options[selected_option_index].text, true);
}
else
{
char buf[32];
npf_snprintf(buf, sizeof(buf), "%u", data_.option_section.options[selected_option_index].value);
npf_snprintf(buf, sizeof(buf), "%u",
data_.option_section.options[selected_option_index].value);
ptgb_write_debug(data_.charset, buf, true);
}
}
if(is_focused)
if (is_focused)
{
if(data_.option_section.num_options > 0)
if (data_.option_section.num_options > 0)
{
const int toggle_arrow_left_x = static_cast<int>(x) + option_margin_left + toggle_arrow_left_offset_x;
const int toggle_arrow_right_x = static_cast<int>(x) + option_margin_left + toggle_arrow_right_offset_x;
const int toggle_arrows_y = static_cast<int>(y) + margin_top + toggle_arrows_offset_y;
const int toggle_arrow_left_x = static_cast<int>(x) +
option_margin_left +
toggle_arrow_left_offset_x;
const int toggle_arrow_right_x = static_cast<int>(x) +
option_margin_left +
toggle_arrow_right_offset_x;
const int toggle_arrows_y =
static_cast<int>(y) + margin_top + toggle_arrows_offset_y;
obj_set_pos(toggle_arrow_left, toggle_arrow_left_x, toggle_arrows_y);
obj_set_pos(toggle_arrow_right, toggle_arrow_right_x, toggle_arrows_y);
obj_set_pos(
toggle_arrow_left, toggle_arrow_left_x, toggle_arrows_y);
obj_set_pos(
toggle_arrow_right, toggle_arrow_right_x, toggle_arrows_y);
obj_unhide(toggle_arrow_left, 0);
obj_unhide(toggle_arrow_right, 0);
}
@@ -163,50 +173,58 @@ void debug_menu_row_widget::render_item(FileContainerReader &text_table, unsigne
MenuInputHandleState debug_menu_row_widget::handle_input()
{
if(data_.option_section.num_options > 0)
if (data_.option_section.num_options > 0)
{
bool handled = false;
if(key_hit(KEY_RIGHT))
if (key_hit(KEY_RIGHT))
{
data_.option_section.selected_option_index = (data_.option_section.selected_option_index + 1) % data_.option_section.num_options;
data_.option_section.selected_option_index =
(data_.option_section.selected_option_index + 1) %
data_.option_section.num_options;
handled = true;
}
if(key_hit(KEY_LEFT))
if (key_hit(KEY_LEFT))
{
--data_.option_section.selected_option_index;
if(data_.option_section.selected_option_index >= data_.option_section.num_options)
if (data_.option_section.selected_option_index >=
data_.option_section.num_options)
{
data_.option_section.selected_option_index = data_.option_section.num_options - 1;
data_.option_section.selected_option_index =
data_.option_section.num_options - 1;
}
handled = true;
}
if(handled && data_.option_section.on_option_activate)
if (handled && data_.option_section.on_option_activate)
{
data_.option_section.on_option_activate(data_.context, data_.option_section.options[data_.option_section.selected_option_index].value);
data_.option_section.on_option_activate(data_.context,
data_.option_section
.options[data_.option_section.selected_option_index]
.value);
}
if(handled)
if (handled)
{
return MenuInputHandleState::HANDLED_UPDATE_VIEWPORT;
}
}
if(key_hit(KEY_A) && data_.on_execute)
if (key_hit(KEY_A) && data_.on_execute)
{
delayed_execute_callback = data_.on_execute;
delayed_execute_context = data_.context;
delayed_execute_user_param = data_.user_param;
return MenuInputHandleState::CHOICE_MADE;
}
return MenuInputHandleState::NOT_HANDLED;
}
void push_debug_menu_section(DebugMenuSection section)
{
constexpr size_t num_levels = sizeof(current_menu_section) / sizeof(current_menu_section[0]);
if(current_menu_section_stack_size < num_levels)
constexpr size_t num_levels =
sizeof(current_menu_section) / sizeof(current_menu_section[0]);
if (current_menu_section_stack_size < num_levels)
{
current_menu_section[current_menu_section_stack_size] = section;
++current_menu_section_stack_size;