mirror of
https://github.com/Polprzewodnikowy/N64FlashcartMenu.git
synced 2024-12-25 01:31:51 +01:00
Improve context menu vars
This commit is contained in:
parent
a1f2a5d56b
commit
3e37991b73
@ -73,8 +73,8 @@ void component_background_draw (void);
|
||||
void component_file_list_draw (entry_t *list, int entries, int selected);
|
||||
|
||||
typedef struct component_context_menu {
|
||||
int count;
|
||||
int selected;
|
||||
int row_count;
|
||||
int row_selected;
|
||||
bool hide_pending;
|
||||
struct component_context_menu *parent;
|
||||
struct component_context_menu *submenu;
|
||||
|
@ -13,22 +13,22 @@ static component_context_menu_t *get_current_submenu (component_context_menu_t *
|
||||
|
||||
|
||||
void component_context_menu_init (component_context_menu_t *cm) {
|
||||
cm->selected = -1;
|
||||
cm->count = 0;
|
||||
cm->row_selected = -1;
|
||||
cm->row_count = 0;
|
||||
cm->hide_pending = false;
|
||||
cm->parent = NULL;
|
||||
for (int i = 0; (cm->list[i].text) != NULL; i++) {
|
||||
cm->count += 1;
|
||||
cm->row_count += 1;
|
||||
}
|
||||
}
|
||||
|
||||
void component_context_menu_show (component_context_menu_t *cm) {
|
||||
cm->selected = 0;
|
||||
cm->row_selected = 0;
|
||||
cm->submenu = NULL;
|
||||
}
|
||||
|
||||
bool component_context_menu_process (menu_t *menu, component_context_menu_t *cm) {
|
||||
if (!cm || (cm->selected < 0)) {
|
||||
if (!cm || (cm->row_selected < 0)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -44,26 +44,26 @@ bool component_context_menu_process (menu_t *menu, component_context_menu_t *cm)
|
||||
}
|
||||
sound_play_effect(SFX_EXIT);
|
||||
} else if (menu->actions.enter) {
|
||||
if (cm->list[cm->selected].submenu) {
|
||||
cm->submenu = cm->list[cm->selected].submenu;
|
||||
if (cm->list[cm->row_selected].submenu) {
|
||||
cm->submenu = cm->list[cm->row_selected].submenu;
|
||||
component_context_menu_init(cm->submenu);
|
||||
cm->submenu->selected = 0;
|
||||
cm->submenu->row_selected = 0;
|
||||
cm->submenu->parent = cm;
|
||||
} else if (cm->list[cm->selected].action) {
|
||||
cm->list[cm->selected].action(menu, cm->list[cm->selected].arg);
|
||||
} else if (cm->list[cm->row_selected].action) {
|
||||
cm->list[cm->row_selected].action(menu, cm->list[cm->row_selected].arg);
|
||||
top->hide_pending = true;
|
||||
}
|
||||
sound_play_effect(SFX_ENTER);
|
||||
} else if (menu->actions.go_up) {
|
||||
cm->selected -= 1;
|
||||
if (cm->selected < 0) {
|
||||
cm->selected = 0;
|
||||
cm->row_selected -= 1;
|
||||
if (cm->row_selected < 0) {
|
||||
cm->row_selected = 0;
|
||||
}
|
||||
sound_play_effect(SFX_CURSOR);
|
||||
} else if (menu->actions.go_down) {
|
||||
cm->selected += 1;
|
||||
if (cm->selected >= cm->count) {
|
||||
cm->selected = (cm->count - 1);
|
||||
cm->row_selected += 1;
|
||||
if (cm->row_selected >= cm->row_count) {
|
||||
cm->row_selected = (cm->row_count - 1);
|
||||
}
|
||||
sound_play_effect(SFX_CURSOR);
|
||||
}
|
||||
@ -72,7 +72,7 @@ bool component_context_menu_process (menu_t *menu, component_context_menu_t *cm)
|
||||
}
|
||||
|
||||
void component_context_menu_draw (component_context_menu_t *cm) {
|
||||
if (!cm || (cm->selected < 0)) {
|
||||
if (!cm || (cm->row_selected < 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -92,7 +92,7 @@ void component_context_menu_draw (component_context_menu_t *cm) {
|
||||
NULL
|
||||
);
|
||||
|
||||
for (int i = 0; i < cm->count; i++) {
|
||||
for (int i = 0; i < cm->row_count; i++) {
|
||||
const char *text = cm->list[i].text;
|
||||
rdpq_paragraph_builder_span(text, strlen(text));
|
||||
if (cm->list[i + 1].text != NULL) {
|
||||
@ -110,7 +110,7 @@ void component_context_menu_draw (component_context_menu_t *cm) {
|
||||
int highlight_x0 = DISPLAY_CENTER_X - (width / 2);
|
||||
int highlight_x1 = DISPLAY_CENTER_X + (width / 2);
|
||||
int highlight_height = (layout->bbox.y1 - layout->bbox.y0) / layout->nlines;
|
||||
int highlight_y = VISIBLE_AREA_Y0 + layout->bbox.y0 + ((cm->selected) * highlight_height);
|
||||
int highlight_y = VISIBLE_AREA_Y0 + layout->bbox.y0 + ((cm->row_selected) * highlight_height);
|
||||
|
||||
component_box_draw(
|
||||
highlight_x0,
|
||||
@ -126,6 +126,6 @@ void component_context_menu_draw (component_context_menu_t *cm) {
|
||||
|
||||
if (top->hide_pending) {
|
||||
top->hide_pending = false;
|
||||
top->selected = -1;
|
||||
top->row_selected = -1;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user