Skip to content

Commit

Permalink
First prototype of argon gui
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillem96 committed Dec 24, 2018
1 parent 33e8f70 commit ae83791
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build Docker image using: docker build . -t argon-nx-builder
# Run docker image using: docker run -a stdout -a stderr -v $(pwd)/out:/argon-nx/out argon-nx-builder
# Run docker image using: docker run -a stdout -a stderr -v $(pwd)/output:/argon-nx/output argon-nx-builder

FROM devkitpro/devkitarm
WORKDIR /argon-nx
Expand Down
2 changes: 1 addition & 1 deletion include/menu/gui/gui_menu_entry.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ gui_menu_entry_t *gui_create_menu_entry(const char *text,
int (*handler)(void *), void *param);

/* 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*, bool, bool);

/* Destroy menu entry */
void gui_menu_entry_destroy(gui_menu_entry_t*);
Expand Down
4 changes: 2 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void ipl_main()
if (sd_mount())
{
g_gfx_con.scale = 5;
gfx_printf(&g_gfx_con, "Hello from ArgonNX!!!\n\n");
// gfx_printf(&g_gfx_con, "Hello from ArgonNX!!!\n\n");

// if (launch_payload("payload.bin"))
// {
Expand All @@ -72,6 +72,6 @@ void ipl_main()

/* If payload launch fails wait for user input to reboot the switch */
g_gfx_con.scale = 2;
gfx_printf(&g_gfx_con, "Press power button to reboot into RCM...\n\n");
// gfx_printf(&g_gfx_con, "Press power button to reboot into RCM...\n\n");
wait_for_button_and_reboot();
}
61 changes: 45 additions & 16 deletions src/menu/gui/gui_argon_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@

#include <string.h>

#define COLUMNS 4
#define ROWS 2
#define ELEM_SIZE 230
#define MARGIN 50


void setup_gfx_gui()
{
u32 clear_color = 0xFFF7F7F7;
Expand All @@ -42,7 +48,8 @@ void setup_gfx_gui()
void gui_init_argon_menu(void)
{
setup_gfx_gui();
// gfx_printf(&g_gfx_con, "Hello from ArgonNX");
gfx_con_setpos(&g_gfx_con, 550, 10);
gfx_printf(&g_gfx_con, "ArgonNX");

char* dir = "argon/payloads";
const char* payloads = dirlist(dir, "*.bin", false);
Expand All @@ -55,26 +62,48 @@ void gui_init_argon_menu(void)
/* Generate dinamycally the entries */
u32 i = 0;
/* For each payload generate its logo, its name and its path */
// while(payloads[i * 256])
// {
// char* payload_path = (char*)malloc(256);
// payload_full_path(&payloads[i * 256], payload_path);
while(payloads[i * 256])
{
char* payload_path = (char*)malloc(256);
payload_full_path(&payloads[i * 256], payload_path);

// char payload_logo[256];
// payload_logo_path(&payloads[i * 256], payload_logo);
char payload_logo[256];
payload_logo_path(&payloads[i * 256], payload_logo);

u32 row = i / COLUMNS;
u32 col = i % COLUMNS;
u32 x = g_gfx_ctxt.width / COLUMNS * col + MARGIN;
u32 y = g_gfx_ctxt.height / ROWS * row + MARGIN + (row == 0 ? 30 : -30);

gui_menu_append_entry(menu,
gui_create_menu_entry(&payloads[i * 256],
sd_file_read("argon/logos/Reinx.bmp"),
x, y,
200, 200,
(int (*)(void *))launch_payload, (void*)payload_path));
i++;
}

// gui_menu_append_entry(menu,
// gui_create_menu_entry(&payloads[i * 256],
// sd_file_read(payload_logo),
// 100 * i, 200 *i,
// 200, 200,
// (int (*)(void *))launch_payload, (void*)payload_path));
// i++;
// }
gui_menu_append_entry(menu,
gui_create_menu_entry("Power off", NULL, 900, 680, 1, 1, (int (*)(void *))power_off, NULL));

gfx_render_bmp_arg_file(&g_gfx_ctxt, "argon/logos/fusee-primary.bmp", 100, 100, 200, 200);
gui_menu_append_entry(menu,
gui_create_menu_entry("Reboot RCM", NULL, 1100, 680, 1, 1, (int (*)(void *))reboot_rcm, NULL));


gui_menu_open(menu);

// gfx_render_bmp_arg_file(&g_gfx_ctxt, "argon/logos/fusee-primary.bmp", 100, 100, 200, 200);

/* Clear all entries and menus */
gui_menu_pool_cleanup();
}

// W: 1280
// H: 720
// 4 columnes
// 2 Files
// 250 cada elem

// W / cols
// H / 2
16 changes: 9 additions & 7 deletions src/menu/gui/gui_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include "mem/heap.h"
#include <string.h>

bool g_force_render = true;

/* Render the menu */
void gui_menu_draw(gui_menu_t *menu);

Expand Down Expand Up @@ -49,7 +51,11 @@ void gui_menu_append_entry(gui_menu_t *menu, gui_menu_entry_t *menu_entry)

void gui_menu_draw(gui_menu_t *menu)
{

for (s16 i = 0; i < menu->next_entry; i++)
{
gui_menu_render_entry(menu->entries[i], i == menu->selected_index, g_force_render);
}
g_force_render = false;
}


Expand All @@ -62,11 +68,11 @@ int gui_menu_update(gui_menu_t *menu)

input = btn_wait();

if ((input & BTN_VOL_UP) && menu->selected_index > 0)
if ((input & BTN_VOL_DOWN) && menu->selected_index > 0)
{
menu->selected_index--;
}
else if ((input & BTN_VOL_DOWN) && menu->selected_index < menu->next_entry - 1)
else if ((input & BTN_VOL_UP) && menu->selected_index < menu->next_entry - 1)
{
menu->selected_index++;
}
Expand All @@ -75,13 +81,9 @@ int gui_menu_update(gui_menu_t *menu)
entry = menu->entries[menu->selected_index];
if (entry->handler != NULL)
{
// TODO: When select
gfx_clear_color(&g_gfx_ctxt, BLACK);
gfx_con_setpos(&g_gfx_con, 20, 50);
if (entry->handler(entry->param) != 0)
return 0;

gfx_clear_color(&g_gfx_ctxt, BLACK);
gui_menu_draw(menu);
}
}
Expand Down
17 changes: 12 additions & 5 deletions src/menu/gui/gui_menu_entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,23 @@ gui_menu_entry_t *gui_create_menu_entry(const char *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, bool selected, bool render_bmp)
{
gfx_render_bmp_arg_bitmap(&g_gfx_ctxt, entry->bitmap,
entry->x, entry->y,
entry->width, entry->height);
if (render_bmp)
gfx_render_bmp_arg_bitmap(&g_gfx_ctxt, entry->bitmap,
entry->x, entry->y,
entry->width, entry->height);

g_gfx_con.scale = 2;
gfx_con_setpos(&g_gfx_con, entry->x, entry->y + entry->height + 20);
if (selected)
gfx_printf(&g_gfx_con, "%k%s%k", 0xFF1971FF, entry->text, 0);
else
gfx_printf(&g_gfx_con, "%s", entry->text);
}

void gui_menu_entry_destroy(gui_menu_entry_t* entry)
{

free(entry->bitmap);
free(entry->text);
free(entry->param);
Expand Down

0 comments on commit ae83791

Please sign in to comment.