Skip to content
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ SRCS = \
menu/ui_components/common.c \
menu/ui_components/context_menu.c \
menu/ui_components/file_list.c \
menu/ui_components/sprites.c \
menu/usb_comm.c \
menu/views/browser.c \
menu/views/credits.c \
Expand Down
2 changes: 2 additions & 0 deletions src/menu/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ static void menu_init (boot_params_t *boot_params) {
rdpq_init();
dfs_init(DFS_DEFAULT_LOCATION);

ui_components_sprites_init();

actions_init();
sound_init_default();
sound_init_sfx();
Expand Down
40 changes: 39 additions & 1 deletion src/menu/ui_components.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,38 @@ typedef enum {
IMAGE_TYPE_END /**< List end marker */
} file_image_type_t;

/**
* @brief joypad button sprite Enumeration.
*
* Enumeration for different types of joypad button sprites used in the user interface.
*/
typedef enum {
SPRITE_JOYPAD_BUTTON_NONE,
SPRITE_JOYPAD_BUTTON_A,
SPRITE_JOYPAD_BUTTON_B,
SPRITE_JOYPAD_BUTTON_C_DOWN,
SPRITE_JOYPAD_BUTTON_C_LEFT,
SPRITE_JOYPAD_BUTTON_C_RIGHT,
SPRITE_JOYPAD_BUTTON_C_UP,
SPRITE_JOYPAD_BUTTON_D_DOWN,
SPRITE_JOYPAD_BUTTON_D_LEFT,
SPRITE_JOYPAD_BUTTON_D_RIGHT,
SPRITE_JOYPAD_BUTTON_D_UP,
SPRITE_JOYPAD_BUTTON_L,
SPRITE_JOYPAD_BUTTON_R,
SPRITE_JOYPAD_BUTTON_START,
SPRITE_JOYPAD_BUTTON_Z,
SPRITE_JOYPAD_BUTTON_TYPE_END /**< List end marker */
} sprite_joypad_button_type_t;


typedef enum {
ACTION_BAR_LINE_ONE,
ACTION_BAR_LINE_TWO,
ACTION_BAR_LINE_END /**< List end marker */
} action_bar_line_t;


/**
* @brief Draw a box component.
*
Expand Down Expand Up @@ -136,7 +168,7 @@ void ui_components_main_text_draw(rdpq_align_t align, rdpq_valign_t valign, char
* @param fmt Format string for the text.
* @param ... Additional arguments for the format string.
*/
void ui_components_actions_bar_text_draw(rdpq_align_t align, rdpq_valign_t valign, char *fmt, ...);
void ui_components_actions_bar_text_draw(rdpq_align_t align, rdpq_valign_t valign, action_bar_line_t line, sprite_joypad_button_type_t action_button, char *fmt, ...);

/**
* @brief Initialize the background component.
Expand Down Expand Up @@ -252,4 +284,10 @@ void ui_components_boxart_free(component_boxart_t *b);
*/
void ui_components_boxart_draw(component_boxart_t *b);


void ui_components_sprites_init(void);

void ui_components_joypad_buttons_draw (sprite_joypad_button_type_t button, float pos_x, float pos_y);


#endif /* UI_COMPONENTS_H__ */
19 changes: 18 additions & 1 deletion src/menu/ui_components/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ void ui_components_main_text_draw (rdpq_align_t align, rdpq_valign_t valign, cha
}
}

void ui_components_actions_bar_text_draw (rdpq_align_t align, rdpq_valign_t valign, char *fmt, ...) {
void ui_components_actions_bar_text_draw (rdpq_align_t align, rdpq_valign_t valign, action_bar_line_t line, sprite_joypad_button_type_t action_button, char *fmt, ...) {
char buffer[256];
size_t nbytes = sizeof(buffer);

Expand All @@ -175,6 +175,23 @@ void ui_components_actions_bar_text_draw (rdpq_align_t align, rdpq_valign_t vali
char *formatted = vasnprintf(buffer, &nbytes, fmt, va);
va_end(va);

uint16_t btn_offset_x = 0;
uint16_t btn_offset_y = 0;


// FIXME: improve bar align and line offsets. Currently they are just best guesses!
if (line == ACTION_BAR_LINE_TWO) {
btn_offset_y = 18;
}

if (align == ALIGN_RIGHT) {
btn_offset_x = 450;
}

if(action_button != SPRITE_JOYPAD_BUTTON_NONE) {
ui_components_joypad_buttons_draw(action_button, VISIBLE_AREA_X0 + TEXT_MARGIN_HORIZONTAL + btn_offset_x, LAYOUT_ACTIONS_SEPARATOR_Y + BORDER_THICKNESS + TEXT_MARGIN_VERTICAL + TEXT_OFFSET_VERTICAL + btn_offset_y);
}

rdpq_text_printn(
&(rdpq_textparms_t) {
.width = VISIBLE_AREA_WIDTH - (TEXT_MARGIN_HORIZONTAL * 2),
Expand Down
93 changes: 93 additions & 0 deletions src/menu/ui_components/sprites.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#include <stdio.h>
#include <stdlib.h>

#include "../ui_components.h"

sprite_t *sprite_joypad_a;
sprite_t *sprite_joypad_b;
sprite_t *sprite_joypad_c_down;
sprite_t *sprite_joypad_c_left;
sprite_t *sprite_joypad_c_right;
sprite_t *sprite_joypad_c_up;
sprite_t *sprite_joypad_d_down;
sprite_t *sprite_joypad_d_left;
sprite_t *sprite_joypad_d_right;
sprite_t *sprite_joypad_d_up;
sprite_t *sprite_joypad_l;
sprite_t *sprite_joypad_r;
sprite_t *sprite_joypad_start;
sprite_t *sprite_joypad_z;

void ui_components_sprites_init(void) {
sprite_joypad_a = sprite_load("rom:/joypad_a.sprite");
sprite_joypad_b = sprite_load("rom:/joypad_b.sprite");
sprite_joypad_c_down = sprite_load("rom:/joypad_c_down.sprite");
sprite_joypad_c_left = sprite_load("rom:/joypad_c_left.sprite");
sprite_joypad_c_right = sprite_load("rom:/joypad_c_right.sprite");
sprite_joypad_c_up = sprite_load("rom:/joypad_c_up.sprite");
sprite_joypad_d_down = sprite_load("rom:/joypad_d_down.sprite");
sprite_joypad_d_left = sprite_load("rom:/joypad_d_left.sprite");
sprite_joypad_d_right = sprite_load("rom:/joypad_d_right.sprite");
sprite_joypad_d_up = sprite_load("rom:/joypad_d_up.sprite");
sprite_joypad_l = sprite_load("rom:/joypad_l.sprite");
sprite_joypad_r = sprite_load("rom:/joypad_r.sprite");
sprite_joypad_start = sprite_load("rom:/joypad_start.sprite");
sprite_joypad_z = sprite_load("rom:/joypad_z.sprite");
}

void ui_components_joypad_buttons_draw (sprite_joypad_button_type_t button, float pos_x, float pos_y) {
sprite_t *current_button;

switch (button) {
case SPRITE_JOYPAD_BUTTON_A:
current_button = sprite_joypad_a;
break;
case SPRITE_JOYPAD_BUTTON_B:
current_button = sprite_joypad_b;
break;
case SPRITE_JOYPAD_BUTTON_C_DOWN:
current_button = sprite_joypad_c_down;
break;
case SPRITE_JOYPAD_BUTTON_C_LEFT:
current_button = sprite_joypad_c_left;
break;
case SPRITE_JOYPAD_BUTTON_C_RIGHT:
current_button = sprite_joypad_c_right;
break;
case SPRITE_JOYPAD_BUTTON_C_UP:
current_button = sprite_joypad_c_up;
break;
case SPRITE_JOYPAD_BUTTON_D_DOWN:
current_button = sprite_joypad_d_down;
break;
case SPRITE_JOYPAD_BUTTON_D_LEFT:
current_button = sprite_joypad_d_left;
break;
case SPRITE_JOYPAD_BUTTON_D_RIGHT:
current_button = sprite_joypad_d_right;
break;
case SPRITE_JOYPAD_BUTTON_D_UP:
current_button = sprite_joypad_d_up;
break;
case SPRITE_JOYPAD_BUTTON_L:
current_button = sprite_joypad_l;
break;
case SPRITE_JOYPAD_BUTTON_R:
current_button = sprite_joypad_r;
break;
case SPRITE_JOYPAD_BUTTON_START:
current_button = sprite_joypad_start;
break;
case SPRITE_JOYPAD_BUTTON_Z:
current_button = sprite_joypad_z;
break;
default:
return;
}

rdpq_set_mode_standard();
rdpq_mode_blender(RDPQ_BLENDER_MULTIPLY);
rdpq_sprite_blit(current_button, pos_x, pos_y, &(rdpq_blitparms_t){
.scale_x = 1, .scale_y = 1,
});
}
20 changes: 14 additions & 6 deletions src/menu/views/browser.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,23 +386,31 @@ static void draw (menu_t *menu, surface_t *d) {
}

ui_components_actions_bar_text_draw(
ALIGN_LEFT, VALIGN_TOP,
"%s\n"
ALIGN_LEFT, VALIGN_TOP, ACTION_BAR_LINE_ONE, SPRITE_JOYPAD_BUTTON_A,
"%s",
menu->browser.entries == 0 ? "" : action
);
ui_components_actions_bar_text_draw(
ALIGN_LEFT, VALIGN_TOP, ACTION_BAR_LINE_TWO, SPRITE_JOYPAD_BUTTON_B,
"\n"
"^%02XB: Back^00",
menu->browser.entries == 0 ? "" : action,
path_is_root(menu->browser.directory) ? STL_GRAY : STL_DEFAULT
);

ui_components_actions_bar_text_draw(
ALIGN_RIGHT, VALIGN_TOP,
"Start: Settings\n"
ALIGN_RIGHT, VALIGN_TOP, ACTION_BAR_LINE_ONE, SPRITE_JOYPAD_BUTTON_START,
"Start: Settings"
);
ui_components_actions_bar_text_draw(
ALIGN_RIGHT, VALIGN_TOP, ACTION_BAR_LINE_TWO, SPRITE_JOYPAD_BUTTON_R,
"\n"
"^%02XR: Options^00",
menu->browser.entries == 0 ? STL_GRAY : STL_DEFAULT
);

if (menu->current_time >= 0) {
ui_components_actions_bar_text_draw(
ALIGN_CENTER, VALIGN_TOP,
ALIGN_CENTER, VALIGN_TOP, ACTION_BAR_LINE_TWO, SPRITE_JOYPAD_BUTTON_NONE,
"\n"
"%s",
ctime(&menu->current_time)
Expand Down
2 changes: 1 addition & 1 deletion src/menu/views/credits.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static void draw (menu_t *menu, surface_t *d) {
);

ui_components_actions_bar_text_draw(
ALIGN_LEFT, VALIGN_TOP,
ALIGN_LEFT, VALIGN_TOP, ACTION_BAR_LINE_TWO, SPRITE_JOYPAD_BUTTON_B,
"\n"
"B: Exit"
);
Expand Down
2 changes: 1 addition & 1 deletion src/menu/views/file_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ static void draw (menu_t *menu, surface_t *d) {
);

ui_components_actions_bar_text_draw(
ALIGN_LEFT, VALIGN_TOP,
ALIGN_LEFT, VALIGN_TOP, ACTION_BAR_LINE_TWO, SPRITE_JOYPAD_BUTTON_B,
"\n"
"B: Exit"
);
Expand Down
2 changes: 1 addition & 1 deletion src/menu/views/flashcart_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ static void draw (menu_t *menu, surface_t *d) {
);

ui_components_actions_bar_text_draw(
ALIGN_LEFT, VALIGN_TOP,
ALIGN_LEFT, VALIGN_TOP, ACTION_BAR_LINE_TWO, SPRITE_JOYPAD_BUTTON_B,
"\n"
"B: Back"
);
Expand Down
10 changes: 7 additions & 3 deletions src/menu/views/load_disk.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,18 @@ static void draw (menu_t *menu, surface_t *d) {
);

ui_components_actions_bar_text_draw(
ALIGN_LEFT, VALIGN_TOP,
"A: Load and run 64DD disk\n"
ALIGN_LEFT, VALIGN_TOP, ACTION_BAR_LINE_ONE, SPRITE_JOYPAD_BUTTON_A,
"A: Load and run 64DD disk"
);
ui_components_actions_bar_text_draw(
ALIGN_LEFT, VALIGN_TOP, ACTION_BAR_LINE_TWO, SPRITE_JOYPAD_BUTTON_B,
"\n"
"B: Exit"
);

if (menu->load.rom_path) {
ui_components_actions_bar_text_draw(
ALIGN_RIGHT, VALIGN_TOP,
ALIGN_RIGHT, VALIGN_TOP, ACTION_BAR_LINE_ONE, SPRITE_JOYPAD_BUTTON_L,
"L|Z: Load with ROM\n"
);
}
Expand Down
8 changes: 6 additions & 2 deletions src/menu/views/load_emulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,12 @@ static void draw (menu_t *menu, surface_t *d) {
);

ui_components_actions_bar_text_draw(
ALIGN_LEFT, VALIGN_TOP,
"A: Load and run Emulated ROM\n"
ALIGN_LEFT, VALIGN_TOP, ACTION_BAR_LINE_ONE, SPRITE_JOYPAD_BUTTON_A,
"A: Load and run Emulated ROM"
);
ui_components_actions_bar_text_draw(
ALIGN_LEFT, VALIGN_TOP, ACTION_BAR_LINE_TWO, SPRITE_JOYPAD_BUTTON_B,
"\n"
"B: Exit"
);
}
Expand Down
16 changes: 12 additions & 4 deletions src/menu/views/load_rom.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,14 +263,22 @@ static void draw (menu_t *menu, surface_t *d) {
);

ui_components_actions_bar_text_draw(
ALIGN_LEFT, VALIGN_TOP,
"A: Load and run ROM\n"
ALIGN_LEFT, VALIGN_TOP, ACTION_BAR_LINE_ONE, SPRITE_JOYPAD_BUTTON_A,
"A: Load and run ROM"
);
ui_components_actions_bar_text_draw(
ALIGN_LEFT, VALIGN_TOP, ACTION_BAR_LINE_TWO, SPRITE_JOYPAD_BUTTON_B,
"\n"
"B: Back"
);

ui_components_actions_bar_text_draw(
ALIGN_RIGHT, VALIGN_TOP,
"L|Z: Extra Info\n"
ALIGN_RIGHT, VALIGN_TOP, ACTION_BAR_LINE_ONE, SPRITE_JOYPAD_BUTTON_L,
"L|Z: Extra Info"
);
ui_components_actions_bar_text_draw(
ALIGN_RIGHT, VALIGN_TOP, ACTION_BAR_LINE_TWO, SPRITE_JOYPAD_BUTTON_R,
"\n"
"R: Options"
);

Expand Down
10 changes: 7 additions & 3 deletions src/menu/views/music_player.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,15 @@ static void draw (menu_t *menu, surface_t *d) {
);

ui_components_actions_bar_text_draw(
ALIGN_LEFT, VALIGN_TOP,
"A: %s\n"
"B: Exit | Left / Right: Rewind / Fast forward",
ALIGN_LEFT, VALIGN_TOP, ACTION_BAR_LINE_ONE, SPRITE_JOYPAD_BUTTON_A,
"A: %s",
mp3player_is_playing() ? "Pause" : mp3player_is_finished() ? "Play again" : "Play"
);
ui_components_actions_bar_text_draw(
ALIGN_LEFT, VALIGN_TOP, ACTION_BAR_LINE_TWO, SPRITE_JOYPAD_BUTTON_B,
"\n"
"B: Exit | Left / Right: Rewind / Fast forward"
);

rdpq_detach_show();
}
Expand Down
23 changes: 17 additions & 6 deletions src/menu/views/rtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,11 @@ static void draw (menu_t *menu, surface_t *d) {
);

ui_components_actions_bar_text_draw(
ALIGN_LEFT, VALIGN_TOP,
ALIGN_LEFT, VALIGN_TOP, ACTION_BAR_LINE_ONE, SPRITE_JOYPAD_BUTTON_A,
"A: Adjust time\n"
);
ui_components_actions_bar_text_draw(
ALIGN_LEFT, VALIGN_TOP, ACTION_BAR_LINE_TWO, SPRITE_JOYPAD_BUTTON_B,
"B: Back"
);
}
Expand All @@ -207,21 +210,29 @@ static void draw (menu_t *menu, surface_t *d) {
);

ui_components_actions_bar_text_draw(
ALIGN_LEFT, VALIGN_TOP,
ALIGN_LEFT, VALIGN_TOP, ACTION_BAR_LINE_TWO, SPRITE_JOYPAD_BUTTON_B,
"\n"
"B: Back"
);
}
}
else {
ui_components_actions_bar_text_draw(
ALIGN_RIGHT, VALIGN_TOP,
"Up/Down: Adjust Field\n"
ALIGN_RIGHT, VALIGN_TOP, ACTION_BAR_LINE_ONE, SPRITE_JOYPAD_BUTTON_NONE,
"Up/Down: Adjust Field"
);
ui_components_actions_bar_text_draw(
ALIGN_RIGHT, VALIGN_TOP, ACTION_BAR_LINE_TWO, SPRITE_JOYPAD_BUTTON_NONE,
"\n"
"Left/Right: Switch Field"
);
ui_components_actions_bar_text_draw(
ALIGN_LEFT, VALIGN_TOP,
"R: Save\n"
ALIGN_LEFT, VALIGN_TOP, ACTION_BAR_LINE_ONE, SPRITE_JOYPAD_BUTTON_R,
"R: Save"
);
ui_components_actions_bar_text_draw(
ALIGN_LEFT, VALIGN_TOP, ACTION_BAR_LINE_TWO, SPRITE_JOYPAD_BUTTON_B,
"\n"
"B: Back"
);
}
Expand Down
Loading
Loading