From fc4cb118b0863e6a89ae3f4259805ae1df9712e9 Mon Sep 17 00:00:00 2001 From: J-D-K Date: Mon, 24 Jun 2024 14:41:03 -0400 Subject: [PATCH] More Revisions --- inc/appStates/progressState.hpp | 1 - inc/filesystem/filesystem.hpp | 2 +- inc/ui/menu.hpp | 4 +- inc/ui/progressBar.hpp | 28 --------- inc/ui/titleSelection.hpp | 8 +-- inc/ui/ui.hpp | 1 - src/appStates/backupMenuState.cpp | 15 +++-- src/appStates/confirmState.cpp | 5 +- src/appStates/mainMenuState.cpp | 41 +++++++------ src/appStates/progressState.cpp | 41 +++++++------ src/appStates/taskState.cpp | 9 ++- src/appStates/titleOptionState.cpp | 21 ++++--- src/appStates/titleSelectionState.cpp | 17 +++--- src/data/data.cpp | 2 + src/data/user.cpp | 2 - src/filesystem/fileParser.cpp | 18 +++--- src/filesystem/filesystem.cpp | 6 +- src/filesystem/zip.cpp | 5 +- src/graphics/systemFont.cpp | 22 ++++--- src/jksv.cpp | 10 ++-- src/log.cpp | 13 ++-- src/stringUtil.cpp | 20 +++---- src/ui/menu.cpp | 19 +++--- src/ui/popMessage.cpp | 6 +- src/ui/progressBar.cpp | 32 ---------- src/ui/titleSelection.cpp | 62 +++++++++++-------- src/ui/titleTile.cpp | 19 ++++-- src/ui/ui.cpp | 86 +++++++++++++-------------- 28 files changed, 249 insertions(+), 266 deletions(-) delete mode 100755 inc/ui/progressBar.hpp delete mode 100755 src/ui/progressBar.cpp diff --git a/inc/appStates/progressState.hpp b/inc/appStates/progressState.hpp index c73dbf2..cd8b66c 100755 --- a/inc/appStates/progressState.hpp +++ b/inc/appStates/progressState.hpp @@ -4,7 +4,6 @@ #include #include "appStates/appState.hpp" #include "appStates/taskState.hpp" -#include "ui/progressBar.hpp" #include "system/progressTask.hpp" #include "system/taskArgs.hpp" diff --git a/inc/filesystem/filesystem.hpp b/inc/filesystem/filesystem.hpp index 9e1448d..a5b504d 100755 --- a/inc/filesystem/filesystem.hpp +++ b/inc/filesystem/filesystem.hpp @@ -9,7 +9,7 @@ namespace fs { // Default device name used for the currently open save filesystem - extern const char *DEFAULT_SAVE_MOUNT_DEVICE; + extern const std::string DEFAULT_SAVE_MOUNT_DEVICE; // Inits fs, creates folders, etc bool init(void); // Mounts save from saveInfo diff --git a/inc/ui/menu.hpp b/inc/ui/menu.hpp index aa713bf..80a4fe4 100755 --- a/inc/ui/menu.hpp +++ b/inc/ui/menu.hpp @@ -34,10 +34,10 @@ namespace ui int m_X, m_Y; // These are used for scrolling effect int m_OriginalY, m_TargetY; - // Selection rectangle width and height - int m_RectWidth, m_RectHeight; // Font size to use int m_FontSize; + // Selection rectangle width and height + int m_RectWidth, m_RectHeight; // Selected option int m_Selected; // Maximum options for scrolling occurs diff --git a/inc/ui/progressBar.hpp b/inc/ui/progressBar.hpp deleted file mode 100755 index cfcbb20..0000000 --- a/inc/ui/progressBar.hpp +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once -#include -#include -#include - -namespace ui -{ - class progressBar - { - public: - // Inits progress bar with maxValue as maximum - progressBar(const uint64_t &maxValue); - // Updates bar. Progress is the current number/max - void update(const uint64_t &progress); - // Renders bar to target - void render(const std::string &text, SDL_Texture *target); - - private: - // Maximum value - uint64_t m_MaxValue; - // Current progress - uint64_t m_Progress = 0; - // Width of bar to render - uint32_t m_BarWidth; - // String that displays XMB / XMB - std::string m_ProgressString; - }; -} \ No newline at end of file diff --git a/inc/ui/titleSelection.hpp b/inc/ui/titleSelection.hpp index c107678..bffe42a 100755 --- a/inc/ui/titleSelection.hpp +++ b/inc/ui/titleSelection.hpp @@ -20,7 +20,7 @@ namespace ui private: // Pointer to current user to load/reload data::user *m_CurrentUser; - // X and Y to render tiles to + // X and Y int m_X, m_Y; // Target X and Y (???) int m_TargetX, m_TargetY; @@ -28,12 +28,6 @@ namespace ui int m_Selected; // X and Y to render selection box int m_SelectionX, m_SelectionY; - // Width and height of icons - int m_IconWidth, m_IconHeight; - // Gaps between icons - int m_HorizontalGap, m_VerticalGap; - // How long a row is - int m_RowSize; // Color shifting for selection box bool m_ColorShift; // How much color is modified diff --git a/inc/ui/ui.hpp b/inc/ui/ui.hpp index d8673e7..413fb52 100755 --- a/inc/ui/ui.hpp +++ b/inc/ui/ui.hpp @@ -3,7 +3,6 @@ #include "ui/strings.hpp" #include "ui/menu.hpp" #include "ui/iconMenu.hpp" -#include "ui/progressBar.hpp" #include "ui/slidePanel.hpp" #include "ui/titleSelection.hpp" #include "ui/popMessage.hpp" diff --git a/src/appStates/backupMenuState.cpp b/src/appStates/backupMenuState.cpp index 091a2b4..91a8844 100755 --- a/src/appStates/backupMenuState.cpp +++ b/src/appStates/backupMenuState.cpp @@ -17,12 +17,15 @@ #include "log.hpp" // Names of panels, render targets, and coordinates + dimensions of menu -static const std::string BACKUP_PANEL_NAME = "backupMenuPanel"; -static const std::string BACKUP_MENU_TARGET_NAME = "backupMenuRenderTarget"; -static const int BACKUP_MENU_X = 10; -static const int BACKUP_MENU_Y = 4; -static const int BACKUP_MENU_FONT_SIZE = 18; -static const int BACKUP_MENU_SCROLL_LENGTH = 6; +namespace +{ + const std::string BACKUP_PANEL_NAME = "backupMenuPanel"; + const std::string BACKUP_MENU_TARGET_NAME = "backupMenuRenderTarget"; + const int BACKUP_MENU_X = 10; + const int BACKUP_MENU_Y = 4; + const int BACKUP_MENU_FONT_SIZE = 18; + const int BACKUP_MENU_SCROLL_LENGTH = 6; +} // This is for backup task struct backupArgs : sys::taskArgs diff --git a/src/appStates/confirmState.cpp b/src/appStates/confirmState.cpp index a5355ad..686f802 100755 --- a/src/appStates/confirmState.cpp +++ b/src/appStates/confirmState.cpp @@ -7,7 +7,10 @@ #include "jksv.hpp" #include "log.hpp" -static const int HOLD_TICKS = 1000; +namespace +{ + const int HOLD_TICKS = 1000; +} confirmState::confirmState(const std::string &message, sys::taskFunction onConfirmation, std::shared_ptr args, const sys::taskTypes &taskType) : m_Message(message), diff --git a/src/appStates/mainMenuState.cpp b/src/appStates/mainMenuState.cpp index 47ed144..25fcddd 100755 --- a/src/appStates/mainMenuState.cpp +++ b/src/appStates/mainMenuState.cpp @@ -12,27 +12,30 @@ #include "stringUtil.hpp" #include "log.hpp" -// Main menu coordinates and dimensions -static const int MAIN_MENU_X = 50; -static const int MAIN_MENU_Y = 16; -static const int MAIN_MENU_SCROLL_LENGTH = 1; -// Render target -static const int RENDER_TARGET_WIDTH = 200; -static const int RENDER_TARGET_HEIGHT = 555; -// This is the font size used to render 'Settings' and 'Extras' to their icons -static const int EXTRA_OPTIONS_FONT_SIZE = 42; -// Coordinates and font size of control guide -static const int CONTROL_GUIDE_Y_POSITION = 673; -static const int CONTROL_GUIDE_FONT_SIZE = 18; +namespace +{ + // Main menu coordinates and dimensions + const int MAIN_MENU_X = 50; + const int MAIN_MENU_Y = 16; + const int MAIN_MENU_SCROLL_LENGTH = 1; + // Render target + const int RENDER_TARGET_WIDTH = 200; + const int RENDER_TARGET_HEIGHT = 555; + // This is the font size used to render 'Settings' and 'Extras' to their icons + const int EXTRA_OPTIONS_FONT_SIZE = 42; + // Coordinates and font size of control guide + const int CONTROL_GUIDE_Y_POSITION = 673; + const int CONTROL_GUIDE_FONT_SIZE = 18; -// Texture names -static const char *MAIN_MENU_RENDER_TARGET = "mainMenuRenderTarget"; -static const char *MAIN_MENU_SETTINGS = "mainMenuSettings"; -static const char *MAIN_MENU_EXTRAS = "mainMenuExtras"; -static const char *MAIN_MENU_TEXTURE_NAME = "mainMenuBackgroundTexture"; + // Texture names + const char *MAIN_MENU_RENDER_TARGET = "mainMenuRenderTarget"; + const char *MAIN_MENU_SETTINGS = "mainMenuSettings"; + const char *MAIN_MENU_EXTRAS = "mainMenuExtras"; + const char *MAIN_MENU_TEXTURE_NAME = "mainMenuBackgroundTexture"; -// Path to texture needed -static const char *MAIN_MENU_BACKGROUND_TEXTURE_PATH = "romfs:/img/menu/backgroundDark.png"; + // Path to texture needed + const char *MAIN_MENU_BACKGROUND_TEXTURE_PATH = "romfs:/img/menu/backgroundDark.png"; +} // Tasks static void backupAllUserSaves(sys::task *task, std::shared_ptr args) diff --git a/src/appStates/progressState.cpp b/src/appStates/progressState.cpp index 515ed89..232e9d3 100755 --- a/src/appStates/progressState.cpp +++ b/src/appStates/progressState.cpp @@ -4,25 +4,28 @@ #include "stringUtil.hpp" #include "jksv.hpp" -// These are the coordinates and dimensions of the dialog boxrendered to screen -static const int PROG_DIALOG_X = 280; -static const int PROG_DIALOG_Y = 262; -static const int PROG_DIALOG_WIDTH = 720; -static const int PROG_DIALOG_HEIGHT = 256; -// These are for the actual bar inside the box -static const double PROG_BAR_WIDTH = 648.0f; -static const int PROG_BAR_X = 312; -static const int PROG_BAR_Y = 471; -//static const int PROG_BAR_WIDTH = 484; Where'd this come from? Try to figure it out later... -static const int PROG_BAR_HEIGHT = 32; -// These are for the status string -static const int STATUS_TEXT_X = PROG_DIALOG_X + 16; -static const int STATUS_TEXT_Y = PROG_DIALOG_Y + 16; -static const int STATUS_TEXT_MAX_WIDTH = 478; -static const int STATUS_TEXT_FONT_SIZE = 18; -// For the [X]MB/[X]MB -static const int PROGRESS_STATUS_Y = 478; -static const int PROGRESS_STATUS_FONT_SIZE = 18; +namespace +{ + // These are the coordinates and dimensions of the dialog boxrendered to screen + const int PROG_DIALOG_X = 280; + const int PROG_DIALOG_Y = 262; + const int PROG_DIALOG_WIDTH = 720; + const int PROG_DIALOG_HEIGHT = 256; + // These are for the actual bar inside the box + const double PROG_BAR_WIDTH = 648.0f; + const int PROG_BAR_X = 312; + const int PROG_BAR_Y = 471; + //static const int PROG_BAR_WIDTH = 484; Where'd this come from? Try to figure it out later... + const int PROG_BAR_HEIGHT = 32; + // These are for the status string + const int STATUS_TEXT_X = PROG_DIALOG_X + 16; + const int STATUS_TEXT_Y = PROG_DIALOG_Y + 16; + const int STATUS_TEXT_MAX_WIDTH = 478; + const int STATUS_TEXT_FONT_SIZE = 18; + // For the [X]MB/[X]MB + const int PROGRESS_STATUS_Y = 478; + const int PROGRESS_STATUS_FONT_SIZE = 18; +} progressState::progressState(sys::taskFunction threadFunction, std::shared_ptr args) : m_Task(std::make_unique(threadFunction, args)) { } diff --git a/src/appStates/taskState.cpp b/src/appStates/taskState.cpp index 585958f..937be7d 100755 --- a/src/appStates/taskState.cpp +++ b/src/appStates/taskState.cpp @@ -4,9 +4,12 @@ #include "jksv.hpp" #include "log.hpp" -// Y position of thread status text -static const int STATUS_TEXT_Y = 348; -static const int STATUS_TEXT_FONT_SIZE = 24; +namespace +{ + // Y position of thread status text + static const int STATUS_TEXT_Y = 348; + static const int STATUS_TEXT_FONT_SIZE = 24; +} taskState::taskState(sys::taskFunction threadFunction, std::shared_ptr args) : m_Task(std::make_unique(threadFunction, args)) { } diff --git a/src/appStates/titleOptionState.cpp b/src/appStates/titleOptionState.cpp index 75061a5..9bee138 100755 --- a/src/appStates/titleOptionState.cpp +++ b/src/appStates/titleOptionState.cpp @@ -11,16 +11,19 @@ #include "jksv.hpp" #include "log.hpp" -// Texture/target names -const char *PANEL_RENDER_TARGET_NAME = "titleOptionPanel"; +namespace +{ + // Texture/target names + const char *PANEL_RENDER_TARGET_NAME = "titleOptionPanel"; -// Dimensions and coordinates for panel and menu -static const int PANEL_WIDTH = 410; -static const int MENU_X = 10; -static const int MENU_Y = 32; -static const int MENU_WIDTH = 390; -static const int MENU_FONT_SIZE = 20; -static const int MENU_SCROLL_LENGTH = 7; + // Dimensions and coordinates for panel and menu + const int PANEL_WIDTH = 410; + const int MENU_X = 10; + const int MENU_Y = 32; + const int MENU_WIDTH = 390; + const int MENU_FONT_SIZE = 20; + const int MENU_SCROLL_LENGTH = 7; +} enum { diff --git a/src/appStates/titleSelectionState.cpp b/src/appStates/titleSelectionState.cpp index 311e697..6b0179f 100755 --- a/src/appStates/titleSelectionState.cpp +++ b/src/appStates/titleSelectionState.cpp @@ -9,15 +9,18 @@ #include "log.hpp" #include "jksv.hpp" -// Texture names -const char *TITLE_SELECT_RENDER_TARGET = "titleSelectionRenderTarget"; +namespace +{ + // Texture names + const char *TITLE_SELECT_RENDER_TARGET = "titleSelectionRenderTarget"; -// Render target dimensions -static const int RENDER_TARGET_WIDTH = 1080; -static const int RENDER_TARGET_HEIGHT = 555; + // Render target dimensions + static const int RENDER_TARGET_WIDTH = 1080; + static const int RENDER_TARGET_HEIGHT = 555; -// X coordinate to subtract from for guide text -static const int GUIDE_STARTING_X = 1220; + // X coordinate to subtract from for guide text + static const int GUIDE_STARTING_X = 1220; +} titleSelectionState::titleSelectionState(data::user *currentUser) : m_CurrentUser(currentUser), diff --git a/src/data/data.cpp b/src/data/data.cpp index c64d005..d88347a 100755 --- a/src/data/data.cpp +++ b/src/data/data.cpp @@ -12,7 +12,9 @@ namespace { + // Using vector for Users to preserve order std::vector> s_UserVector; + // Map of title data std::unordered_map s_TitleMap; } diff --git a/src/data/user.cpp b/src/data/user.cpp index 0b43aa9..e2ee058 100755 --- a/src/data/user.cpp +++ b/src/data/user.cpp @@ -97,8 +97,6 @@ data::user::user(const AccountUid &accountID) : m_AccountID(accountID) m_PathSafeUsername = m_Username; logger::log("Error getting profile for user 0x%X", getAccountIDU128()); } - - logger::log("%s @ %p", m_Username.c_str(), this); } data::user::user(const AccountUid &accountID, const std::string &username, const std::string &pathSafeUsername) : m_AccountID(accountID), m_Username(username), m_PathSafeUsername(pathSafeUsername) diff --git a/src/filesystem/fileParser.cpp b/src/filesystem/fileParser.cpp index d43bde9..45721e6 100755 --- a/src/filesystem/fileParser.cpp +++ b/src/filesystem/fileParser.cpp @@ -1,16 +1,20 @@ #include +#include #include "filesystem/fileParser.hpp" #include "stringUtil.hpp" #include "log.hpp" -// Strings needed for this file -static const char *VALUE_DELIMINATORS = "()=,"; -static const char *STRING_DELIMINATORS = ",;\n"; -static const char *VALUE_TRUE = "true"; -static const char *VALUE_FALSE = "false"; +namespace +{ + // Strings needed for this file + const std::string VALUE_DELIMINATORS = "()=,"; + const std::string STRING_DELIMINATORS = ",;\n"; + const std::string VALUE_TRUE = "true"; + const std::string VALUE_FALSE = "false"; -// Length limit for line reading -static const int FILE_PARSER_LINE_SIZE_LIMIT = 0x1000; + // Length limit for line reading + const int FILE_PARSER_LINE_SIZE_LIMIT = 0x1000; +} fs::fileParser::fileParser(const std::string &filePath) { diff --git a/src/filesystem/filesystem.cpp b/src/filesystem/filesystem.cpp index fecc41e..f691d7b 100755 --- a/src/filesystem/filesystem.cpp +++ b/src/filesystem/filesystem.cpp @@ -4,7 +4,7 @@ #include "config.hpp" #include "log.hpp" -const char *fs::DEFAULT_SAVE_MOUNT_DEVICE = "save:/"; +const std::string fs::DEFAULT_SAVE_MOUNT_DEVICE = "save:/"; bool fs::init(void) { @@ -96,12 +96,12 @@ bool fs::mountSaveData(const FsSaveDataInfo &saveInfo) void fs::unmountSaveData(void) { - fsdevUnmountDevice(fs::DEFAULT_SAVE_MOUNT_DEVICE); + fsdevUnmountDevice(fs::DEFAULT_SAVE_MOUNT_DEVICE.c_str()); } void fs::commitSaveData(void) { - Result commitError = fsdevCommitDevice(fs::DEFAULT_SAVE_MOUNT_DEVICE); + Result commitError = fsdevCommitDevice(fs::DEFAULT_SAVE_MOUNT_DEVICE.c_str()); if(R_SUCCEEDED(commitError)) { logger::log("Commit succeeded."); diff --git a/src/filesystem/zip.cpp b/src/filesystem/zip.cpp index 407ffa6..44ccad9 100755 --- a/src/filesystem/zip.cpp +++ b/src/filesystem/zip.cpp @@ -12,7 +12,10 @@ #include "stringUtil.hpp" #include "log.hpp" -static const int ZIP_BUFFER_SIZE = 0x80000; +namespace +{ + const int ZIP_BUFFER_SIZE = 0x80000; +} void fs::zip::copyDirectoryToZip(const std::string &source, zipFile zip, sys::progressTask *task) { diff --git a/src/graphics/systemFont.cpp b/src/graphics/systemFont.cpp index d527650..38956a5 100755 --- a/src/graphics/systemFont.cpp +++ b/src/graphics/systemFont.cpp @@ -13,18 +13,6 @@ #include "graphics/systemFont.hpp" #include "log.hpp" -// This is how large the buffer is for words for line wrapping -static const int WORD_WRAP_BUFFER_LENGTH = 0x1000; - -//Masks for converting glyphs to sdl surface -static const uint32_t s_RedMask = 0xFF000000; -static const uint32_t s_GreenMask = 0x00FF0000; -static const uint32_t s_BlueMask = 0x0000FF00; -static const uint32_t s_AlphaMask = 0x000000FF; - -//Codepoints to break a line at -static const std::array s_BreakPoints = {' ', L' ', '/', '_', '-', L'。', L'、'}; - //This struct is for caching glyph data needed typedef struct { @@ -40,7 +28,17 @@ namespace FT_Face s_FTFaces[6]; //Number of fonts loaded int s_TotalFonts; + // This is the glyph texture cache map std::map, glyphData> s_GlyphMap; + // How large the word buffer is for line wrapping. + const int WORD_WRAP_BUFFER_LENGTH = 0x1000; + // Masks for converting glyphs to sdl surface + const uint32_t s_RedMask = 0xFF000000; + const uint32_t s_GreenMask = 0x00FF0000; + const uint32_t s_BlueMask = 0x0000FF00; + const uint32_t s_AlphaMask = 0x000000FF; + // Codepoints to break lines at + const std::array s_BreakPoints = {' ', L' ', '/', '_', '-', L'。', L'、'}; } //Resizes faces diff --git a/src/jksv.cpp b/src/jksv.cpp index 6bcec84..496a2b6 100755 --- a/src/jksv.cpp +++ b/src/jksv.cpp @@ -14,15 +14,17 @@ // Things specifically only for here namespace { + // This is for returning whether or not the program was successfully initialized and is running bool s_IsRunning = false; + // This is the icon at the top left SDL_Texture *s_HeaderIcon = NULL; + // This is the vector of states std::vector> s_AppStateVector; + // Name of icon texture + const std::string ICON_NAME = "appIcon"; + const std::string ICON_PATH = "romfs:/img/icn/iconWhite.png"; } -// Icon name & path -static const char *ICON_NAME = "appIcon"; -static const char *ICON_PATH = "romfs:/img/icn/iconWhite.png"; - bool jksv::init(void) { // Init logger diff --git a/src/log.cpp b/src/log.cpp index 0c7f2e2..bca288c 100755 --- a/src/log.cpp +++ b/src/log.cpp @@ -1,13 +1,16 @@ +#include #include #include #include #include "log.hpp" -// Log path -static const char *LOG_OUTPUT_PATH = "/JKSV/log.txt"; - -// Size for va -static const int LOG_VA_BUFFER_SIZE = 0x1000; +namespace +{ + // Log output path. Will be updated once settings is added. + const std::string LOG_OUTPUT_PATH = "/JKSV/log.txt"; + // Buffer size for va + const int LOG_VA_BUFFER_SIZE = 0x1000; +} namespace { diff --git a/src/stringUtil.cpp b/src/stringUtil.cpp index def0777..dbbd603 100755 --- a/src/stringUtil.cpp +++ b/src/stringUtil.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -7,20 +8,19 @@ #include #include "stringUtil.hpp" -// va buffer size -static const int VA_BUFFER_SIZE = 0x800; - -// Chars that shouldn't be in paths & function to test for them -static const uint32_t forbiddenPathChars[] = {L',', L'/', L'\\', L'<', L'>', L':', L'"', L'|', L'?', L'*', L'™', L'©', L'®'}; +namespace +{ + // Size for VA + const int VA_BUFFER_SIZE = 0x1000; + // Characters forbidden from file paths + std::array FORBIDDEN_PATH_CHARACTERS = { L',', L'/', L'\\', L'<', L'>', L':', L'"', L'|', L'?', L'*', L'™', L'©', L'®' }; +} static bool characterIsForbidden(const uint32_t &codepoint) { - for (int i = 0; i < 13; i++) + if(std::find(FORBIDDEN_PATH_CHARACTERS.begin(), FORBIDDEN_PATH_CHARACTERS.end(), codepoint) != FORBIDDEN_PATH_CHARACTERS.end()) { - if (codepoint == forbiddenPathChars[i]) - { - return true; - } + return true; } return false; } diff --git a/src/ui/menu.cpp b/src/ui/menu.cpp index 10a994f..f3d19ad 100755 --- a/src/ui/menu.cpp +++ b/src/ui/menu.cpp @@ -1,14 +1,19 @@ +#include #include "ui/menu.hpp" #include "ui/ui.hpp" #include "system/input.hpp" #include "graphics/systemFont.hpp" #include "config.hpp" -ui::menu::menu(const int &x, const int &y, const int &rectWidth, const int &fontSize, const int &maxScroll) : m_X(x), m_Y(y), m_OriginalY(y), m_RectWidth(rectWidth), m_FontSize(fontSize), m_MaxScroll(maxScroll) -{ - m_RectHeight = m_FontSize + 30; - m_Selected = 0; -} +ui::menu::menu(const int &x, const int &y, const int &rectWidth, const int &fontSize, const int &maxScroll) : +m_X(x), +m_Y(y), +m_OriginalY(y), +m_FontSize(fontSize), +m_RectWidth(rectWidth), +m_RectHeight(m_FontSize + 32), +m_Selected(0), +m_MaxScroll(maxScroll) { } ui::menu::menu(const int &x, const int &y, const int &rectWidth, const int &fontSize, const int &maxScroll, const std::string *menuOpts, const int &menuOptCount) : menu(x, y, rectWidth, fontSize, maxScroll) { @@ -55,8 +60,8 @@ void ui::menu::update(void) // Calculate scroll amount if (m_Y != m_TargetY) { - float addY = (float)((float)m_TargetY - (float)m_Y) / config::getAnimationScaling(); - m_Y += addY; + double addToY = static_cast(static_cast(m_TargetY) - static_cast(m_Y)) / config::getAnimationScaling(); + m_Y += std::ceil(addToY); } } diff --git a/src/ui/popMessage.cpp b/src/ui/popMessage.cpp index 0a15952..06b5589 100755 --- a/src/ui/popMessage.cpp +++ b/src/ui/popMessage.cpp @@ -5,11 +5,11 @@ #include "ui/ui.hpp" #include "ui/popMessage.hpp" -static const int POPMESSAGE_X_COORDINATE = 24; -static const int POPMESSAGE_Y_COORDINATE = 640; - namespace { + // X and starting Y coordinate for pop messages. + const int POPMESSAGE_X_COORDINATE = 24; + const int POPMESSAGE_Y_COORDINATE = 640; // Queue to be processed. Needed to avoid threading graphics issues. std::vector s_MessageQueue; // Actual vector of messages diff --git a/src/ui/progressBar.cpp b/src/ui/progressBar.cpp deleted file mode 100755 index 8423bc4..0000000 --- a/src/ui/progressBar.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include "ui/progressBar.hpp" -#include "graphics/graphics.hpp" -#include "graphics/systemFont.hpp" -#include "ui/ui.hpp" -#include "stringUtil.hpp" - -ui::progressBar::progressBar(const uint64_t &maxValue) : m_MaxValue(maxValue) { } - -void ui::progressBar::update(const uint64_t &progress) -{ - m_Progress = progress; - - // Calculat bar width - if(m_MaxValue > 0) - { - m_BarWidth = (static_cast(m_Progress) / static_cast(m_MaxValue)) * 648.0f; - } - - // Get updated string - m_ProgressString = stringUtil::getFormattedString("%.2fMB / %.2fMB", static_cast(m_Progress) / 1024.0f / 1024.0f, static_cast(m_MaxValue) / 1024.0f / 1024.0f); -} - -void ui::progressBar::render(const std::string &text, SDL_Texture *target) -{ - // Calculate X position of progress string - int progressX = 640 - (graphics::systemFont::getTextWidth(m_ProgressString, 18) / 2); - - ui::renderDialogBox(target, 280, 262, 720, 256); - graphics::renderRect(target, 312, 471, 484, 32, COLOR_BLACK); - graphics::renderRect(target, 312, 471, m_BarWidth, 32, COLOR_GREEN); - graphics::systemFont::renderText(m_ProgressString, target, progressX, 478, 18, COLOR_WHITE); -} \ No newline at end of file diff --git a/src/ui/titleSelection.cpp b/src/ui/titleSelection.cpp index 8436eca..5a27a84 100755 --- a/src/ui/titleSelection.cpp +++ b/src/ui/titleSelection.cpp @@ -5,24 +5,35 @@ #include "system/input.hpp" #include "config.hpp" -ui::titleSelection::titleSelection(data::user *currentUser) : m_CurrentUser(currentUser) +namespace { - // To do: Not this. Originally were passed as variables - m_X = 32; - m_Y = 38; - m_IconWidth = 128; - m_IconHeight = 128; - m_HorizontalGap = 16; - m_VerticalGap = 16; - m_RowSize = 7; - m_Selected = 0; - m_ColorMod = 0; + // Starting coordinates for rendering loop + const int ICON_STARTING_X = 32; + const int ICON_STARTING_Y = 38; + // Icon dimensions + const int ICON_WIDTH = 128; + const int ICON_HEIGHT = 128; + // Gap size in between icons + const int ICON_GAP_HORIZONTAL = 16; + const int ICON_GAP_VERTICAL = 16; + // How many icons per row + const int ICON_ROW_SIZE = 7; + // I really need to figure out what this is and where it came from. I don't remember. + const int TARGET_Y_START = 280; +} +ui::titleSelection::titleSelection(data::user *currentUser) : +m_X(ICON_STARTING_X), +m_Y(ICON_STARTING_Y), +m_CurrentUser(currentUser), +m_Selected(0), +m_ColorMod(0) +{ for (int i = 0; i < m_CurrentUser->getTotalUserSaveInfo(); i++) { data::userSaveInfo *currentUserSaveInfo = m_CurrentUser->getUserSaveInfoAt(i); data::titleInfo *currentTitleInfo = data::getTitleInfoByTitleID(currentUserSaveInfo->getTitleID()); - m_TitleTiles.emplace_back(128, 128, config::titleIsFavorite(currentUserSaveInfo->getTitleID()), currentTitleInfo->getIcon()); + m_TitleTiles.emplace_back(ICON_WIDTH, ICON_HEIGHT, config::titleIsFavorite(currentUserSaveInfo->getTitleID()), currentTitleInfo->getIcon()); } } @@ -44,11 +55,11 @@ void ui::titleSelection::update(void) } // I chose this over switch case because the _AnyX can't work that way - if (sys::input::buttonDown(HidNpadButton_AnyUp) && (m_Selected -= m_RowSize) < 0) + if (sys::input::buttonDown(HidNpadButton_AnyUp) && (m_Selected -= ICON_ROW_SIZE) < 0) { m_Selected = 0; } - else if (sys::input::buttonDown(HidNpadButton_AnyDown) && (m_Selected += m_RowSize) > totalTiles) + else if (sys::input::buttonDown(HidNpadButton_AnyDown) && (m_Selected += ICON_ROW_SIZE) > totalTiles) { m_Selected = totalTiles; } @@ -60,27 +71,27 @@ void ui::titleSelection::update(void) { ++m_Selected; } - else if (sys::input::buttonDown(HidNpadButton_L) && (m_Selected -= m_RowSize * 3) < 0) + else if (sys::input::buttonDown(HidNpadButton_L) && (m_Selected -= ICON_ROW_SIZE * 3) < 0) { m_Selected = 0; } - else if (sys::input::buttonDown(HidNpadButton_R) && (m_Selected += m_RowSize * 3) > totalTiles) + else if (sys::input::buttonDown(HidNpadButton_R) && (m_Selected += ICON_ROW_SIZE * 3) > totalTiles) { m_Selected = totalTiles; } // Calculate scrolling float animationScaling = config::getAnimationScaling(); - m_TargetY = 280; + m_TargetY = TARGET_Y_START; if (m_SelectionY > m_TargetY) { - float addToY = ((float)m_TargetY - (float)m_SelectionY) / animationScaling; - m_Y += ceil(addToY); + double addToY = (static_cast(m_TargetY) - (static_cast(m_SelectionY))) / animationScaling; + m_Y += std::ceil(addToY); } - else if (m_SelectionY < 38) + else if (m_SelectionY < ICON_STARTING_Y) { - float addToY = (38.0f - (float)m_SelectionY) / animationScaling; - m_Y += ceil(addToY); + double addToY = (static_cast(ICON_STARTING_Y) - static_cast(m_SelectionY)) / animationScaling; + m_Y += std::ceil(addToY); } // Update title titles @@ -111,11 +122,11 @@ void ui::titleSelection::render(SDL_Texture *target) int totalTiles = m_TitleTiles.size(); m_TargetY = m_Y; - for (int i = 0; i < totalTiles; m_TargetY += (m_IconHeight + m_VerticalGap)) + for (int i = 0; i < totalTiles; m_TargetY += (ICON_HEIGHT + ICON_GAP_VERTICAL)) { - int endOfRow = i + m_RowSize; + int endOfRow = i + ICON_ROW_SIZE; m_TargetX = m_X; - for (; i < endOfRow; m_TargetX += (m_IconWidth + m_HorizontalGap), i++) + for (; i < endOfRow; m_TargetX += (ICON_WIDTH + ICON_GAP_HORIZONTAL), i++) { if (i >= totalTiles) { @@ -134,7 +145,6 @@ void ui::titleSelection::render(SDL_Texture *target) } } } - // This renders the selected title icon so it's over top of the surrounding ones graphics::renderRect(target, m_SelectionX - 23, m_SelectionY - 23, 174, 174, COLOR_DEFAULT_CLEAR); m_TitleTiles[m_Selected].render(target, m_SelectionX, m_SelectionY); diff --git a/src/ui/titleTile.cpp b/src/ui/titleTile.cpp index ffd6e04..12fb1f9 100755 --- a/src/ui/titleTile.cpp +++ b/src/ui/titleTile.cpp @@ -1,12 +1,19 @@ #include "ui/titleTile.hpp" #include "graphics/systemFont.hpp" +namespace +{ + double ICON_SIZE_MULTIPLIER = 1.28f; + int ICON_EXPAND_SIZE = 18; + int ICON_CONTRACT_SIZE = 9; +} + ui::titleTile::titleTile(const int &width, const int &height, const bool &favorite, SDL_Texture *icon) : m_Width(width), m_Height(height), m_IsFavorite(favorite), m_Icon(icon) { m_RenderWidth = m_Width; m_RenderHeight = m_Height; - m_SelectedWidth = m_Width * 1.28f; - m_SelectedHeight = m_Height * 1.28; + m_SelectedWidth = m_Width * ICON_SIZE_MULTIPLIER; + m_SelectedHeight = m_Height * ICON_SIZE_MULTIPLIER; } void ui::titleTile::update(const bool &isSelected) @@ -14,22 +21,22 @@ void ui::titleTile::update(const bool &isSelected) // Not sure if I should leave this like this. Feels kind of wrong if (isSelected && m_RenderWidth < m_SelectedWidth) { - m_RenderWidth += 18; + m_RenderWidth += ICON_EXPAND_SIZE; } if (isSelected && m_RenderHeight < m_SelectedHeight) { - m_RenderHeight += 18; + m_RenderHeight += ICON_EXPAND_SIZE; } if (!isSelected && m_RenderWidth > m_Width) { - m_RenderWidth -= 9; + m_RenderWidth -= ICON_CONTRACT_SIZE; } if (!isSelected && m_RenderHeight > m_Height) { - m_RenderHeight -= 9; + m_RenderHeight -= ICON_CONTRACT_SIZE; } } diff --git a/src/ui/ui.cpp b/src/ui/ui.cpp index 0099dbb..1670b6e 100755 --- a/src/ui/ui.cpp +++ b/src/ui/ui.cpp @@ -1,50 +1,51 @@ +#include #include #include "ui/ui.hpp" #include "graphics/graphics.hpp" #include "system/system.hpp" // Oh boy, here we go~ -// Selection bounding box names -static const std::string SELECTION_TOP_LEFT_NAME = "s_SelectionTopLeft"; -static const std::string SELECTION_TOP_RIGHT_NAME = "s_SelectionTopRight"; -static const std::string SELECTION_BOTTOM_LEFT_NAME = "s_SelectionBottomLeft"; -static const std::string SELECTION_BOTTOM_RIGHT_NAME = "s_SelectionBottomRight"; - -// Dialog box paths -static const std::string DIALOG_TOP_LEFT_NAME = "s_DialogTopLeft"; -static const std::string DIALOG_TOP_RIGHT_NAME = "s_DialogTopRight"; -static const std::string DIALOG_BOTTOM_LEFT_NAME = "s_DialogBottomLeft"; -static const std::string DIALOG_BOTTOM_RIGHT_NAME = "s_DialogBottomRight"; - -// Selection paths -static const std::string SELECTION_TOP_LEFT_PATH = "romfs:/img/menu/selectionTopLeft.png"; -static const std::string SELECTION_TOP_RIGHT_PATH = "romfs:/img/menu/selectionTopRight.png"; -static const std::string SELECTION_BOTTOM_LEFT_PATH = "romfs:/img/menu/selectionBottomLeft.png"; -static const std::string SELECTION_BOTTOM_RIGHT_PATH = "romfs:/img/menu/selectionBottomRight.png"; - -// Dialog paths -static const std::string DIALOG_TOP_LEFT_PATH = "romfs:/img/dialogDark/dialogTopLeft.png"; -static const std::string DIALOG_TOP_RIGHT_PATH = "romfs:/img/dialogDark/dialogTopRight.png"; -static const std::string DIALOG_BOTTOM_LEFT_PATH = "romfs:/img/dialogDark/dialogBottomLeft.png"; -static const std::string DIALOG_BOTTOM_RIGHT_PATH = "romfs:/img/dialogDark/dialogBottomRight.png"; - -// Nintendo Wii or 3DS? loading glyph array -static const std::string s_LoadGlyphArray[8] = -{ - "\ue020", "\ue021", "\ue022", "\ue023", - "\ue024", "\ue025", "\ue026", "\ue027" -}; - -// Ticks for loading glyph changing -static const int LOADING_GLYPH_CHANGE_TICKS = 50; - -// Loading Glyph render coordinates -static const int LOADING_GLYPH_RENDER_X = 56; -static const int LOADING_GLYPH_RENDER_Y = 673; -static const int LOADING_GLYPH_RENDER_SIZE = 32; - namespace { + // Selection bounding box names + const std::string SELECTION_TOP_LEFT_NAME = "s_SelectionTopLeft"; + const std::string SELECTION_TOP_RIGHT_NAME = "s_SelectionTopRight"; + const std::string SELECTION_BOTTOM_LEFT_NAME = "s_SelectionBottomLeft"; + const std::string SELECTION_BOTTOM_RIGHT_NAME = "s_SelectionBottomRight"; + + // Dialog box paths + const std::string DIALOG_TOP_LEFT_NAME = "s_DialogTopLeft"; + const std::string DIALOG_TOP_RIGHT_NAME = "s_DialogTopRight"; + const std::string DIALOG_BOTTOM_LEFT_NAME = "s_DialogBottomLeft"; + const std::string DIALOG_BOTTOM_RIGHT_NAME = "s_DialogBottomRight"; + + // Selection paths + const std::string SELECTION_TOP_LEFT_PATH = "romfs:/img/menu/selectionTopLeft.png"; + const std::string SELECTION_TOP_RIGHT_PATH = "romfs:/img/menu/selectionTopRight.png"; + const std::string SELECTION_BOTTOM_LEFT_PATH = "romfs:/img/menu/selectionBottomLeft.png"; + const std::string SELECTION_BOTTOM_RIGHT_PATH = "romfs:/img/menu/selectionBottomRight.png"; + + // Dialog paths + const std::string DIALOG_TOP_LEFT_PATH = "romfs:/img/dialogDark/dialogTopLeft.png"; + const std::string DIALOG_TOP_RIGHT_PATH = "romfs:/img/dialogDark/dialogTopRight.png"; + const std::string DIALOG_BOTTOM_LEFT_PATH = "romfs:/img/dialogDark/dialogBottomLeft.png"; + const std::string DIALOG_BOTTOM_RIGHT_PATH = "romfs:/img/dialogDark/dialogBottomRight.png"; + + // Ticks for loading glyph changing + const int LOADING_GLYPH_CHANGE_TICKS = 50; + + // Loading Glyph render coordinates + const int LOADING_GLYPH_RENDER_X = 56; + const int LOADING_GLYPH_RENDER_Y = 673; + const int LOADING_GLYPH_RENDER_SIZE = 32; + + // Nintendo Wii or 3DS? loading glyph array + const std::array s_LoadGlyphArray = + { + "\ue020", "\ue021", "\ue022", "\ue023", + "\ue024", "\ue025", "\ue026", "\ue027" + }; + // Timer for changing glyph. Might wanna rethink this some time std::unique_ptr s_LoadGlyphChangeTimer; // Frame the animation is on @@ -53,10 +54,7 @@ namespace bool s_GlyphColorModifier = true; // This is the how much to add to the base color for the pulse uint8_t s_GlyphColorModification = 0x00; -} -namespace -{ // These are all corner textures for rendering various things on screen SDL_Texture *s_SelectionTopLeft, *s_SelectionTopRight, *s_SelectionBottomLeft, *s_SelectionBottomRight; SDL_Texture *s_DialogTopLeft, *s_DialogTopRight, *s_DialogBottomLeft, *s_DialogBottomRight; @@ -74,7 +72,7 @@ void ui::init(void) s_SelectionTopLeft = graphics::textureLoadFromFile(SELECTION_TOP_LEFT_NAME, SELECTION_TOP_LEFT_PATH); s_SelectionTopRight = graphics::textureLoadFromFile(SELECTION_TOP_RIGHT_NAME, SELECTION_TOP_RIGHT_PATH); s_SelectionBottomLeft = graphics::textureLoadFromFile(SELECTION_BOTTOM_LEFT_NAME, SELECTION_BOTTOM_LEFT_PATH); - s_SelectionBottomRight = graphics::textureLoadFromFile(SELECTION_BOTTOM_RIGHT_NAME, SELECTION_TOP_RIGHT_PATH); + s_SelectionBottomRight = graphics::textureLoadFromFile(SELECTION_BOTTOM_RIGHT_NAME, SELECTION_BOTTOM_RIGHT_PATH); // Corners for dialog s_DialogTopLeft = graphics::textureLoadFromFile(DIALOG_TOP_LEFT_NAME, DIALOG_TOP_LEFT_PATH); @@ -137,5 +135,5 @@ void ui::renderLoadingGlyph(void) // Create color. For semi-readability uint32_t loadingGlyphColor = createColor(0x00, (0x88 + s_GlyphColorModification), (0xC5 + (s_GlyphColorModification / 2)), 0xFF); // Finally render it to screen - graphics::systemFont::renderText(s_LoadGlyphArray[s_LoadGlyphFrame], NULL, LOADING_GLYPH_RENDER_X, LOADING_GLYPH_RENDER_Y, LOADING_GLYPH_RENDER_SIZE, loadingGlyphColor); + graphics::systemFont::renderText(s_LoadGlyphArray.at(s_LoadGlyphFrame), NULL, LOADING_GLYPH_RENDER_X, LOADING_GLYPH_RENDER_Y, LOADING_GLYPH_RENDER_SIZE, loadingGlyphColor); } \ No newline at end of file