More Revisions

This commit is contained in:
J-D-K
2024-06-24 14:41:03 -04:00
parent 08f8ac724f
commit fc4cb118b0
28 changed files with 249 additions and 266 deletions

View File

@@ -4,7 +4,6 @@
#include <cstdint>
#include "appStates/appState.hpp"
#include "appStates/taskState.hpp"
#include "ui/progressBar.hpp"
#include "system/progressTask.hpp"
#include "system/taskArgs.hpp"

View File

@@ -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

View File

@@ -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

View File

@@ -1,28 +0,0 @@
#pragma once
#include <string>
#include <cstdint>
#include <SDL2/SDL.h>
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;
};
}

View File

@@ -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

View File

@@ -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"

View File

@@ -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

View File

@@ -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<sys::taskArgs> args, const sys::taskTypes &taskType) :
m_Message(message),

View File

@@ -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<sys::taskArgs> args)

View File

@@ -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<sys::taskArgs> args) :
m_Task(std::make_unique<sys::progressTask>(threadFunction, args)) { }

View File

@@ -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<sys::taskArgs> args) :
m_Task(std::make_unique<sys::task>(threadFunction, args)) { }

View File

@@ -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
{

View File

@@ -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),

View File

@@ -12,7 +12,9 @@
namespace
{
// Using vector for Users to preserve order
std::vector<std::pair<u128, data::user>> s_UserVector;
// Map of title data
std::unordered_map<uint64_t, data::titleInfo> s_TitleMap;
}

View File

@@ -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)

View File

@@ -1,16 +1,20 @@
#include <array>
#include <string>
#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)
{

View File

@@ -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.");

View File

@@ -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)
{

View File

@@ -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<uint32_t, 7> 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<std::pair<uint32_t, int>, 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<uint32_t, 7> s_BreakPoints = {' ', L' ', '/', '_', '-', L'。', L'、'};
}
//Resizes faces

View File

@@ -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<std::unique_ptr<appState>> 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

View File

@@ -1,13 +1,16 @@
#include <string>
#include <array>
#include <cstdarg>
#include <mutex>
#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
{

View File

@@ -1,3 +1,4 @@
#include <algorithm>
#include <array>
#include <string>
#include <cstring>
@@ -7,20 +8,19 @@
#include <switch.h>
#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<uint32_t, 13> 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;
}

View File

@@ -1,14 +1,19 @@
#include <cmath>
#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<double>(static_cast<double>(m_TargetY) - static_cast<double>(m_Y)) / config::getAnimationScaling();
m_Y += std::ceil(addToY);
}
}

View File

@@ -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<ui::popMessage::pMessage> s_MessageQueue;
// Actual vector of messages

View File

@@ -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<float>(m_Progress) / static_cast<float>(m_MaxValue)) * 648.0f;
}
// Get updated string
m_ProgressString = stringUtil::getFormattedString("%.2fMB / %.2fMB", static_cast<float>(m_Progress) / 1024.0f / 1024.0f, static_cast<float>(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);
}

View File

@@ -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<double>(m_TargetY) - (static_cast<double>(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<double>(ICON_STARTING_Y) - static_cast<double>(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);

View File

@@ -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;
}
}

View File

@@ -1,50 +1,51 @@
#include <array>
#include <memory>
#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<std::string, 8> s_LoadGlyphArray =
{
"\ue020", "\ue021", "\ue022", "\ue023",
"\ue024", "\ue025", "\ue026", "\ue027"
};
// Timer for changing glyph. Might wanna rethink this some time
std::unique_ptr<sys::timer> 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);
}