Skip to content

Commit

Permalink
Condense some video functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Nightkingale committed May 7, 2024
1 parent 196ed99 commit 85e91a5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 33 deletions.
5 changes: 2 additions & 3 deletions include/video.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ void draw_background(int r, int g, int b, int a);
void draw_rectangle(int x, int y, int w, int h, int r, int g, int b, int a);
void draw_text(const char* text, int x, int y, int size, SDL_Color color = {255, 255, 255, 255});
void draw_icon(const char* icon, int x, int y, int size, SDL_Color color = {255, 255, 255, 255});
int get_text_width(const char* text, int size);
void draw_screen_bars();
void draw_confirm_button();
int get_text_size(const char* text, int size, bool get_height = false);
void draw_screen_bars(bool show_confirm = false, bool show_controls = true);


#endif
18 changes: 6 additions & 12 deletions source/screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void draw_menu_screen(int selected_menu_item) {
if (item == selected_menu_item) {
draw_rectangle(0, 90 + item * 120, SCREEN_WIDTH, 120, 100, 100, 255, 255); // Blue border.
draw_rectangle(5, 95 + item * 120, 1910, 110, 0, 0, 0, 255); // Black rectangle.
draw_text("\ue000", SCREEN_WIDTH - 64 - get_text_width("\ue000", 50), 115 + item * 120, 50, {100, 100, 255, 255});
draw_text("\ue000", SCREEN_WIDTH - 64 - get_text_size("\ue000", 50), 115 + item * 120, 50, {100, 100, 255, 255});
}
draw_text(menu_options[item], 160, 120 + item * 120, 50);

Expand All @@ -75,7 +75,7 @@ void draw_menu_screen(int selected_menu_item) {

void draw_unlink_menu() {
draw_background(16, 16, 16, 255);
draw_screen_bars();
draw_screen_bars(true);

draw_text("Before unlinking, please read the following notice!", 64, 120, 50);

Expand All @@ -87,16 +87,14 @@ void draw_unlink_menu() {
draw_text("You won't be able to use this account on any other Wii U.", 64, 520, 50);

draw_text("You must confirm to continue the process.", 64, 840, 50);

draw_confirm_button();

SDL_RenderPresent(renderer);
}


void draw_backup_menu() {
draw_background(16, 16, 16, 255);
draw_screen_bars();
draw_screen_bars(true);

draw_text("Before backing up, please read the following notice!", 64, 120, 50);

Expand All @@ -109,15 +107,13 @@ void draw_backup_menu() {

draw_text("You must confirm to continue the process.", 64, 840, 50);

draw_confirm_button();

SDL_RenderPresent(renderer);
}


void draw_overwrite_menu(const char* backup_path) {
draw_background(10, 10, 60, 255); // Blue background.
draw_screen_bars();
draw_screen_bars(true);

draw_text("Before backing up, please read the following notice!", 64, 120, 50);

Expand All @@ -128,15 +124,13 @@ void draw_overwrite_menu(const char* backup_path) {

draw_text("You must confirm to continue the process.", 64, 840, 50);

draw_confirm_button();

SDL_RenderPresent(renderer);
}


void draw_error_menu(const char* error_message) {
draw_background(60, 10, 10, 255); // Red background.
draw_screen_bars();
draw_screen_bars(false, false);

draw_text("An exception has occurred!", 64, 120, 50);

Expand All @@ -151,7 +145,7 @@ void draw_error_menu(const char* error_message) {

void draw_success_menu(const char* type, bool inkay_configured = false) {
draw_background(10, 60, 10, 255); // Green background.
draw_screen_bars();
draw_screen_bars(false, false);

draw_text("The operation was successful!", 64, 120, 50);

Expand Down
36 changes: 18 additions & 18 deletions source/video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void draw_icon(const char* icon, int x, int y, int size, SDL_Color color) {
}


int get_text_width(const char* text, int size) {
int get_text_size(const char* text, int size, bool get_height) {
void* font_data = nullptr;
uint32_t font_size = 0;
// We are essentially recreating the font here.
Expand All @@ -103,39 +103,39 @@ int get_text_width(const char* text, int size) {
TTF_SizeUTF8(font, text, &width, &height); // This works with unicode characters.

TTF_CloseFont(font);
return width; // We could return height as well, but we don't need it.

if (get_height)
return height; // We don't usually need the height.

return width;
}


void draw_screen_bars() {
void draw_screen_bars(bool show_confirm, bool show_controls) {
// These lines draw the top bar (with title, version, and author).
draw_rectangle(0, 0, SCREEN_WIDTH, 90, 100, 0, 100, 255);
draw_text("Wii U Account Swap", 64, 10, 50);
draw_text(APP_VERSION, 64 + get_text_width("Wii U Account Swap", 50) + 16, 10, 50, {176, 176, 176, 255});
draw_text("Nightkingale", SCREEN_WIDTH - 64 - get_text_width("Nightkingale", 50), 10, 50);
draw_text(APP_VERSION, 64 + get_text_size("Wii U Account Swap", 50) + 16, 10, 50, {176, 176, 176, 255});
draw_text("Nightkingale", SCREEN_WIDTH - 64 - get_text_size("Nightkingale", 50), 10, 50);

// These lines draw the bottom bar (with current user and account file).
draw_rectangle(0, 940, SCREEN_WIDTH, 140, 100, 0, 100, 255);
draw_text("Current User: ", 64, 955, 40);
draw_text(MII_NICKNAME.c_str(), 64 + get_text_width("Current User: ", 40), 955, 40, {176, 176, 176, 255});
draw_text(MII_NICKNAME.c_str(), 64 + get_text_size("Current User: ", 40), 955, 40, {176, 176, 176, 255});

if (INKAY_EXISTS)
// Draw the plugin checkmark icon next to the name.
draw_icon("\ue55c", 64 + get_text_width("Current User: ", 40) + get_text_width(MII_NICKNAME.c_str(), 40) + 16, 960, 40, {176, 176, 176, 255});
draw_icon("\ue55c", 64 + get_text_size("Current User: ", 40) + get_text_size(MII_NICKNAME.c_str(), 40) + 16, 960, 40, {176, 176, 176, 255});
else
// Draw the plugin exit icon next to the name.
draw_icon("\ue560", 64 + get_text_width("Current User: ", 40) + get_text_width(MII_NICKNAME.c_str(), 40) + 16, 960, 40, {176, 176, 176, 255});
draw_icon("\ue560", 64 + get_text_size("Current User: ", 40) + get_text_size(MII_NICKNAME.c_str(), 40) + 16, 960, 40, {176, 176, 176, 255});

draw_text(ACCOUNT_FILE.c_str(), 64, 1005, 40);

draw_text("\ue07d Navigate", SCREEN_WIDTH - 64 - get_text_width("\ue07d Navigate", 50), 975, 50);
}


void draw_confirm_button() {
// Draw the confirm and decline buttons over the bottom bar.
draw_rectangle(0, 940, SCREEN_WIDTH, 140, 100, 0, 100, 255);
draw_text("\ue000 Confirm", 64, 975, 50);
draw_text("\ue001 Decline", SCREEN_WIDTH - 64 - get_text_width("\ue001 Decline", 50), 975, 50);
SDL_RenderPresent(renderer);
if (show_confirm) {
draw_rectangle(0, 940, SCREEN_WIDTH, 140, 100, 0, 100, 255);
draw_text("\ue000 Confirm", 64, 975, 50);
draw_text("\ue001 Decline", SCREEN_WIDTH - 64 - get_text_size("\ue001 Decline", 50), 975, 50);
} else if (show_controls)
draw_text("\ue07d Navigate", SCREEN_WIDTH - 64 - get_text_size("\ue07d Navigate", 50), 975, 50);
}

0 comments on commit 85e91a5

Please sign in to comment.