Initial commit. Needs debugging.

This commit is contained in:
J-D-K
2026-03-20 12:41:04 -04:00
parent d39fd80a20
commit 347f1bc75f
112 changed files with 1331 additions and 1109 deletions

View File

@@ -30,6 +30,21 @@ class JKSV
static void request_quit() noexcept;
private:
/// @brief SDL2 instance.
sdl2::SDL2 m_sdl2{};
/// @brief SDL2 Window.
sdl2::Window m_window{};
/// @brief SDL2 Renderer.
sdl2::Renderer m_renderer{};
/// @brief SDL2 Audio.
sdl2::Audio m_audio{};
/// @brief Not really a part of SDL2, but...
sdl2::Input m_input{};
/// @brief Whether or not initialization was successful and JKSV is still running.
static inline std::atomic_bool sm_isRunning{};
@@ -37,7 +52,13 @@ class JKSV
bool m_showTranslationInfo{};
/// @brief JKSV icon in upper left corner.
sdl::SharedTexture m_headerIcon{};
sdl2::SharedTexture m_headerIcon{};
/// @brief This is used for rendering JKSV.
sdl2::SharedFont m_titleFont{};
/// @brief This is used to render the build date.
sdl2::SharedFont m_buildFont{};
/// @brief Stores the translation string.
std::string m_translationInfo{};
@@ -60,9 +81,6 @@ class JKSV
// Creates the needed directories on SD.
bool create_directories();
/// @brief Adds the text color changing characters.
void add_color_chars();
/// @brief Retrieves the strings from the map and sets them up for printing.
void setup_translation_info_strings();

View File

@@ -1,6 +1,8 @@
#pragma once
#include "appstates/BaseState.hpp"
#include "sdl.hpp"
#include <concepts>
#include <memory>
#include <vector>
@@ -14,10 +16,10 @@ class StateManager
StateManager &operator=(StateManager &&) = delete;
/// @brief Runs the state update routine.
static void update();
static void update(const sdl2::Input &input);
/// @brief Runs the state rendering routine(s);
static void render() noexcept;
static void render(sdl2::Renderer &renderer) noexcept;
/// @brief Returns whether the back of the vector is a closable state.
static bool back_is_closable() noexcept;

View File

@@ -15,10 +15,10 @@ class AppletModeState final : public BaseState
static inline std::shared_ptr<AppletModeState> create() { return std::make_shared<AppletModeState>(); }
/// @brief Runs the update routine. Basically does nothing.
void update() override;
void update(const sdl2::Input &input) override;
/// @brief Renders the message to the screen.
void render() override;
void render(sdl2::Renderer &renderer) override;
private:
/// @brief Pointer to the string rendered to the screen.

View File

@@ -26,9 +26,7 @@ class BackupMenuState final : public BaseState
static inline std::shared_ptr<BackupMenuState> create(data::User *user,
data::TitleInfo *titleInfo,
const FsSaveDataInfo *saveInfo)
{
return std::make_shared<BackupMenuState>(user, titleInfo, saveInfo);
}
{ return std::make_shared<BackupMenuState>(user, titleInfo, saveInfo); }
/// @brief Creates and pushes a new BackupMenuState to the vector.
static inline std::shared_ptr<BackupMenuState> create_and_push(data::User *user,
@@ -41,10 +39,10 @@ class BackupMenuState final : public BaseState
}
/// @brief Required. Inherited virtual function from AppState.
void update() override;
void update(const sdl2::Input &input) override;
/// @brief Required. Inherited virtual function from AppState.
void render() override;
void render(sdl2::Renderer &renderer) override;
/// @brief Refreshes the directory listing and menu.
void refresh();
@@ -153,7 +151,10 @@ class BackupMenuState final : public BaseState
static inline std::shared_ptr<ui::SlideOutPanel> sm_slidePanel{};
/// @brief Inner render target so the menu only renders to a certain area.
static inline sdl::SharedTexture sm_menuRenderTarget{};
static inline sdl2::SharedTexture sm_menuRenderTarget{};
/// @brief Font used for rendering text.
static inline sdl2::SharedFont sm_font{};
/// @brief Initializes the static members all instances share if they haven't been already.
void initialize_static_members();
@@ -174,7 +175,7 @@ class BackupMenuState final : public BaseState
void initialize_remote_storage();
/// @brief This is the function called when New Backup is selected.
void name_and_create_backup();
void name_and_create_backup(const sdl2::Input &input);
/// @brief This is the function called when a backup is selected to be overwritten.
void confirm_overwrite();

View File

@@ -15,13 +15,13 @@ class BaseState
virtual ~BaseState();
/// @brief Every derived class is required to have this function.
virtual void update() = 0;
virtual void update(const sdl2::Input &input) = 0;
/// @brief Sub update routine. Meant to handle minor background tasks. Not meant for full update routines.
virtual void sub_update() {};
/// @brief Every derived class is required to have this function.
virtual void render() = 0;
virtual void render(sdl2::Renderer &renderer) = 0;
/// @brief Deactivates state and allows JKSV to purge it from the vector.
void deactivate();

View File

@@ -1,5 +1,6 @@
#pragma once
#include "appstates/BaseState.hpp"
#include "sdl.hpp"
#include "sys/sys.hpp"
#include "ui/ColorMod.hpp"
@@ -15,10 +16,10 @@ class BaseTask : public BaseState
/// @brief Runs the update routine for rendering the loading glyph animation.
/// @param
virtual void update() = 0;
virtual void update(const sdl2::Input &input) = 0;
/// @brief Virtual render function.
virtual void render() = 0;
virtual void render(sdl2::Renderer &renderer) = 0;
protected:
/// @brief Underlying system task. This needs to be allocated by the derived classes.
@@ -28,15 +29,12 @@ class BaseTask : public BaseState
void update_loading_glyph();
/// @brief Displays the "can't quit JKSV" when plus is pressed.
void pop_on_plus();
void pop_on_plus(const sdl2::Input &input);
/// @brief This function renders the loading glyph in the bottom left corner.
/// @note This is mostly just so users don't think JKSV has frozen when operations take a long time.
void render_loading_glyph();
/// @brief This is the font size used for displaying text during tasks.
static inline constexpr int FONT_SIZE = 20;
private:
/// @brief This is the current frame of the loading glyph animation.
int m_currentFrame{};
@@ -53,4 +51,10 @@ class BaseTask : public BaseState
/// @brief This array holds the glyphs of the loading sequence. I think it's from the Wii?
static inline constexpr std::array<std::string_view, 8> sm_glyphArray =
{"\ue020", "\ue021", "\ue022", "\ue023", "\ue024", "\ue025", "\ue026", "\ue027"};
/// @brief Font for rendering the glyph.
static inline sdl2::SharedFont sm_font{};
/// @brief Ensures the font is loaded.
void initialize_static_members();
};

View File

@@ -1,6 +1,7 @@
#pragma once
#include "StateManager.hpp"
#include "appstates/BaseState.hpp"
#include "sdl.hpp"
#include "ui/ui.hpp"
#include <memory>
@@ -24,10 +25,10 @@ class BlacklistEditState final : public BaseState
}
/// @brief Update override.
void update() override;
void update(const sdl2::Input &input) override;
/// @brief Render override.
void render() override;
void render(sdl2::Renderer &renderer) override;
private:
/// @brief Local copy of the blacklist.

View File

@@ -5,8 +5,8 @@
#include "appstates/ProgressState.hpp"
#include "appstates/TaskState.hpp"
#include "graphics/colors.hpp"
#include "graphics/fonts.hpp"
#include "graphics/screen.hpp"
#include "input.hpp"
#include "logging/logger.hpp"
#include "sdl.hpp"
#include "strings/strings.hpp"
@@ -108,9 +108,7 @@ class ConfirmState final : public BaseState
sys::threadpool::JobFunction onConfirm,
sys::threadpool::JobFunction onCancel,
sys::Task::TaskData taskData)
{
return std::make_shared<ConfirmState>(query, holdRequired, onConfirm, onCancel, taskData);
}
{ return std::make_shared<ConfirmState>(query, holdRequired, onConfirm, onCancel, taskData); }
/// @brief Returns a new ConfirmState. See constructor.
static inline std::shared_ptr<ConfirmState> create(std::string &query,
@@ -118,9 +116,7 @@ class ConfirmState final : public BaseState
sys::threadpool::JobFunction onConfirm,
sys::threadpool::JobFunction onCancel,
sys::Task::TaskData taskData)
{
return std::make_shared<ConfirmState>(query, holdRequired, onConfirm, onCancel, taskData);
}
{ return std::make_shared<ConfirmState>(query, holdRequired, onConfirm, onCancel, taskData); }
/// @brief Creates and returns a new ConfirmState and pushes it.
static inline std::shared_ptr<ConfirmState> create_and_push(std::string_view query,
@@ -173,23 +169,22 @@ class ConfirmState final : public BaseState
}
/// @brief Just updates the ConfirmState.
void update() override
void update(const sdl2::Input &input) override
{
switch (m_state)
{
case State::Opening: ConfirmState::update_dimensions(); break;
case State::Displaying: ConfirmState::update_handle_input(); break;
case State::Displaying: ConfirmState::update_handle_input(input); break;
case State::Closing: ConfirmState::update_dimensions(); break;
}
}
/// @brief Renders the state to screen.
void render() override
void render(sdl2::Renderer &renderer) override
{
// These are the rendering coordinates that aren't affected by the transition.
static constexpr int TEXT_X = 312;
static constexpr int TEXT_Y_OFFSET = 24;
static constexpr int TEXT_FONT_SIZE = 20;
static constexpr int TEXT_WRAP_WIDTH = 656;
// Divider line A.
@@ -204,59 +199,28 @@ class ConfirmState final : public BaseState
static constexpr int LINE_Y_OFFSET = 192;
// Yes/NO
static constexpr int OPTION_Y_OFFSET = 214;
static constexpr int OPTION_FONT_SIZE = 22;
static constexpr int OPTION_Y_OFFSET = 214;
const bool hasFocus = BaseState::has_focus();
const int y = m_transition.get_y();
// This is the dimming rectangle.
sdl::render_rect_fill(sdl::Texture::Null,
0,
0,
graphics::SCREEN_WIDTH,
graphics::SCREEN_HEIGHT,
colors::DIM_BACKGROUND);
renderer.render_rectangle(0, 0, graphics::SCREEN_WIDTH, graphics::SCREEN_HEIGHT, colors::DIM_BACKGROUND);
// Render the dialog. Only render the rest if we're in the display state.
sm_dialog->render(sdl::Texture::Null, hasFocus);
sm_dialog->render(renderer, hasFocus);
if (!m_transition.in_place() || m_state != State::Displaying) { return; }
// Main string.
sdl::text::render(sdl::Texture::Null,
TEXT_X,
y + TEXT_Y_OFFSET,
TEXT_FONT_SIZE,
TEXT_WRAP_WIDTH,
colors::WHITE,
m_query);
sm_textFont->render_text_wrapped(TEXT_X, y + TEXT_Y_OFFSET, colors::WHITE, TEXT_WRAP_WIDTH, m_query);
// Divider lines.
sdl::render_line(sdl::Texture::Null,
LINE_A_X_A,
y + LINE_Y_OFFSET,
LINE_A_X_B,
y + LINE_Y_OFFSET,
colors::DIV_COLOR);
sdl::render_line(sdl::Texture::Null, LINE_B_X, y + LINE_Y_OFFSET, LINE_B_X, y + LINE_B_Y_B, colors::DIV_COLOR);
renderer.render_line(LINE_A_X_A, y + LINE_Y_OFFSET, LINE_A_X_B, y + LINE_Y_OFFSET, colors::DIV_COLOR);
renderer.render_line(LINE_B_X, y + LINE_Y_OFFSET, LINE_B_X, y + LINE_B_Y_B, colors::DIV_COLOR);
// Yes
sdl::text::render(sdl::Texture::Null,
m_yesX,
y + OPTION_Y_OFFSET,
OPTION_FONT_SIZE,
sdl::text::NO_WRAP,
colors::WHITE,
sm_yes);
// No
sdl::text::render(sdl::Texture::Null,
m_noX,
y + OPTION_Y_OFFSET,
OPTION_FONT_SIZE,
sdl::text::NO_WRAP,
colors::WHITE,
sm_no);
sm_optionFont->render_text(m_yesX, y + OPTION_Y_OFFSET, colors::WHITE, sm_yes);
sm_optionFont->render_text(m_noX, y + OPTION_Y_OFFSET, colors::WHITE, sm_no);
}
private:
@@ -313,20 +277,26 @@ class ConfirmState final : public BaseState
/// @brief This dialog is shared between all instances.
static inline std::shared_ptr<ui::DialogBox> sm_dialog{};
/// @brief This is the font used to render the actual text.
static inline sdl2::SharedFont sm_textFont{};
/// @brief This is the font used to render the Yes or No options.
static inline sdl2::SharedFont sm_optionFont{};
/// @brief This sound is shared.
static inline sdl::SharedSound sm_dialogPop{};
static inline sdl2::SharedSound sm_dialogPop{};
void initialize_static_members()
{
// Name and path to the sound used.
static constexpr std::string_view POP_SOUND = "ConfirmPop";
static constexpr const char *POP_PATH = "romfs:/Sound/ConfirmPop.wav";
static constexpr std::string_view POP_PATH = "romfs:/Sound/ConfirmPop.wav";
// To do: Not sure about checking the holding text.
if (sm_dialog && sm_dialogPop && sm_yes && sm_no) { return; }
if (sm_dialog && sm_dialogPop && sm_yes && sm_no && sm_textFont && sm_optionFont) { return; }
// Init dialog and get it started.
sm_dialog = ui::DialogBox::create(0, 0, 0, 0);
sm_dialogPop = sdl::SoundManager::load(POP_SOUND, POP_PATH);
sm_dialogPop = sdl2::SoundManager::create_load_resource(POP_PATH, POP_PATH);
sm_dialog->set_from_transition(m_transition, true);
// Load yes and no.
@@ -336,6 +306,13 @@ class ConfirmState final : public BaseState
// Loop load the holding strings.
const char *hold{};
for (int i = 0; (hold = strings::get_by_name(strings::names::HOLDING_STRINGS, i)); i++) { sm_hold[i] = hold; }
// Fonts for rendering text.
sm_textFont = sdl2::FontManager::create_load_resource<sdl2::SystemFont>(graphics::fonts::names::TWENTY_FOUR_PIXEL,
graphics::fonts::sizes::TWENTY_PIXEL);
sm_optionFont =
sdl2::FontManager::create_load_resource<sdl2::SystemFont>(graphics::fonts::names::TWENTY_FOUR_PIXEL,
graphics::fonts::sizes::TWENTY_FOUR_PIXEL);
}
/// @brief Updates the dimensions of the dialog.
@@ -353,13 +330,13 @@ class ConfirmState final : public BaseState
}
/// @brief Handles the input and updating.
void update_handle_input() noexcept
void update_handle_input(const sdl2::Input &input) noexcept
{
// Grab our input bools.
const bool aPressed = input::button_pressed(HidNpadButton_A);
const bool bPressed = input::button_pressed(HidNpadButton_B);
const bool aHeld = input::button_held(HidNpadButton_A);
const bool aReleased = input::button_released(HidNpadButton_A);
const bool aPressed = input.button_pressed(HidNpadButton_A);
const bool bPressed = input.button_pressed(HidNpadButton_B);
const bool aHeld = input.button_held(HidNpadButton_A);
const bool aReleased = input.button_released(HidNpadButton_A);
// This is to prevent A from auto triggering the dialog.
m_triggerGuard = m_triggerGuard || (aPressed && !m_triggerGuard);
@@ -379,13 +356,13 @@ class ConfirmState final : public BaseState
// This just centers the Yes or holding text.
void center_yes()
{
const int yesWidth = sdl::text::get_width(22, sm_yes);
const int yesWidth = sm_optionFont->get_text_width(sm_yes);
m_yesX = COORD_YES_X - (yesWidth / 2);
}
void center_no()
{
const int noWidth = sdl::text::get_width(22, sm_no);
const int noWidth = sm_optionFont->get_text_width(sm_no);
m_noX = COORD_NO_X - (noWidth / 2);
}

View File

@@ -15,41 +15,45 @@ class DataLoadingState final : public BaseTask
using DestructFunction = std::function<void()>;
DataLoadingState(data::DataContext &context,
sdl2::Renderer &renderer,
DestructFunction destructFunction,
sys::threadpool::JobFunction function,
sys::Task::TaskData taskData);
static inline std::shared_ptr<DataLoadingState> create(data::DataContext &context,
sdl2::Renderer &renderer,
DestructFunction destructFunction,
sys::threadpool::JobFunction function,
sys::Task::TaskData taskData)
{
return std::make_shared<DataLoadingState>(context, destructFunction, function, taskData);
}
{ return std::make_shared<DataLoadingState>(context, renderer, destructFunction, function, taskData); }
static inline std::shared_ptr<DataLoadingState> create_and_push(data::DataContext &context,
sdl2::Renderer &renderer,
DestructFunction destructFunction,
sys::threadpool::JobFunction function,
sys::Task::TaskData taskData)
{
auto newState = DataLoadingState::create(context, destructFunction, function, taskData);
auto newState = DataLoadingState::create(context, renderer, destructFunction, function, taskData);
StateManager::push_state(newState);
return newState;
}
/// @brief Update override.
void update() override;
void update(const sdl2::Input &input) override;
/// @brief Updates the loading glyph.
void sub_update() override;
/// @brief Render override.
void render() override;
void render(sdl2::Renderer &renderer) override;
private:
/// @brief Reference to the data context to run post-init operations.
data::DataContext &m_context;
/// @brief Reference to SDL2 renderer for loading icons.
sdl2::Renderer &m_renderer;
/// @brief X coord of the status text.
int m_statusX{};
@@ -57,7 +61,10 @@ class DataLoadingState final : public BaseTask
DestructFunction m_destructFunction{};
/// @brief Icon displayed in the center of the screen.
static inline sdl::SharedTexture sm_jksvIcon{};
static inline sdl2::SharedTexture sm_jksvIcon{};
/// @brief Font used for rendering the status.
static inline sdl2::SharedFont sm_font{};
/// @brief Loads the icon if it hasn't been already.
void initialize_static_members();

View File

@@ -9,26 +9,30 @@ class ExtrasMenuState final : public BaseState
{
public:
/// @brief Constructor.
ExtrasMenuState();
ExtrasMenuState(sdl2::Renderer &renderer);
/// @brief Returns a new ExtrasMenuState
static inline std::shared_ptr<ExtrasMenuState> create() { return std::make_shared<ExtrasMenuState>(); }
static inline std::shared_ptr<ExtrasMenuState> create(sdl2::Renderer &renderer)
{ return std::make_shared<ExtrasMenuState>(renderer); }
/// @brief Updates the menu.
void update() override;
void update(const sdl2::Input &input) override;
/// @brief Sub-update routine.
void sub_update() override;
/// @brief Renders the menu to screen.
void render() override;
void render(sdl2::Renderer &renderer) override;
private:
/// @brief Reference to renderer for launching refresh.
sdl2::Renderer &m_renderer;
/// @brief Menu
std::shared_ptr<ui::Menu> m_extrasMenu{};
/// @brief Render target for menu.
sdl::SharedTexture m_renderTarget{};
sdl2::SharedTexture m_renderTarget{};
/// @brief Control guider for bottom right corner.
std::shared_ptr<ui::ControlGuide> m_controlGuide{};

View File

@@ -18,19 +18,17 @@ class FadeState final : public BaseState
/// @brief Creates a new fade in state.
/// @param nextState The next state to push after the the fade is finished.
FadeState(sdl::Color baseColor, uint8_t startAlpha, uint8_t endAlpha, std::shared_ptr<BaseState> nextState);
FadeState(SDL_Color baseColor, uint8_t startAlpha, uint8_t endAlpha, std::shared_ptr<BaseState> nextState);
/// @brief Returns a new fade in state. See constructor.
static inline std::shared_ptr<FadeState> create(sdl::Color baseColor,
static inline std::shared_ptr<FadeState> create(SDL_Color baseColor,
uint8_t startAlpha,
uint8_t endAlpha,
std::shared_ptr<BaseState> nextState)
{
return std::make_shared<FadeState>(baseColor, startAlpha, endAlpha, nextState);
}
{ return std::make_shared<FadeState>(baseColor, startAlpha, endAlpha, nextState); }
/// @brief Creates, returns and pushes a new FadeInState to the statemanager.
static std::shared_ptr<FadeState> create_and_push(sdl::Color baseColor,
static std::shared_ptr<FadeState> create_and_push(SDL_Color baseColor,
uint8_t startAlpha,
uint8_t endAlpha,
std::shared_ptr<BaseState> nextState)
@@ -41,13 +39,14 @@ class FadeState final : public BaseState
}
/// @brief Update override.
void update() override;
void update(const sdl2::Input &input) override;
/// @brief Render override.
void render() override;
void render(sdl2::Renderer &renderer) override;
private:
sdl::Color m_baseColor{};
/// @brief Base color of the fade.
SDL_Color m_baseColor{};
/// @brief Alpha value.
uint8_t m_alpha{};

View File

@@ -17,9 +17,7 @@ class FileModeState final : public BaseState
std::string_view mountB,
int64_t journalSize = 0,
bool isSystem = false)
{
return std::make_shared<FileModeState>(mountA, mountB, journalSize, isSystem);
}
{ return std::make_shared<FileModeState>(mountA, mountB, journalSize, isSystem); }
static inline std::shared_ptr<FileModeState> create_and_push(std::string_view mountA,
std::string_view mountB,
@@ -32,10 +30,10 @@ class FileModeState final : public BaseState
}
/// @brief Update override.
void update() override;
void update(const sdl2::Input &input) override;
/// @brief Render override.
void render() override;
void render(sdl2::Renderer &renderer) override;
/// @brief This thing is a headache without this.
friend class FileOptionState;
@@ -95,7 +93,7 @@ class FileModeState final : public BaseState
static inline std::shared_ptr<ui::Frame> sm_frame{};
/// @brief This is the render target the browsers are rendered to.
static inline sdl::SharedTexture sm_renderTarget{};
static inline sdl2::SharedTexture sm_renderTarget{};
/// @brief Control guide shared by all instances.
static inline std::shared_ptr<ui::ControlGuide> sm_controlGuide{};
@@ -116,7 +114,7 @@ class FileModeState final : public BaseState
void update_y() noexcept;
/// @brief Handles input.
void update_handle_input() noexcept;
void update_handle_input(const sdl2::Input &input) noexcept;
/// @brief Handles changing the current directory or opening the options.
void enter_selected(fslib::Path &path, fslib::Directory &directory, ui::Menu &menu);

View File

@@ -17,9 +17,7 @@ class FileOptionState final : public BaseState
/// @brief Inline creation function.
static inline std::shared_ptr<FileOptionState> create(FileModeState *spawningState)
{
return std::make_shared<FileOptionState>(spawningState);
}
{ return std::make_shared<FileOptionState>(spawningState); }
/// @brief Same as above. Pushes state before returning it.
static inline std::shared_ptr<FileOptionState> create_and_push(FileModeState *spawningState)
@@ -30,10 +28,10 @@ class FileOptionState final : public BaseState
}
/// @brief Update routine.
void update() override;
void update(const sdl2::Input &input) override;
/// @brief Render routine.
void render() override;
void render(sdl2::Renderer &renderer) override;
/// @brief Signals to this state to update the source/target menu on the next update() call.
void update_source();
@@ -95,7 +93,7 @@ class FileOptionState final : public BaseState
void update_dimensions() noexcept;
/// @brief Updates and handles input.
void update_handle_input() noexcept;
void update_handle_input(const sdl2::Input &input) noexcept;
/// @brief Updates the FileModeState's source data.
void update_filemode_source();

View File

@@ -13,27 +13,28 @@ class MainMenuState final : public BaseState
{
public:
/// @brief Creates and initializes the main menu.
MainMenuState();
MainMenuState(sdl2::Renderer &renderer);
/// @brief Returns a new MainMenuState
static inline std::shared_ptr<MainMenuState> create() { return std::make_shared<MainMenuState>(); }
static inline std::shared_ptr<MainMenuState> create(sdl2::Renderer &renderer)
{ return std::make_shared<MainMenuState>(renderer); }
/// @brief Creates and returns a new MainMenuState. Pushes it automatically.
static inline std::shared_ptr<MainMenuState> create_and_push()
static inline std::shared_ptr<MainMenuState> create_and_push(sdl2::Renderer &renderer)
{
auto newState = MainMenuState::create();
auto newState = MainMenuState::create(renderer);
StateManager::push_state(newState);
return newState;
}
/// @brief Runs update routine.
void update() override;
void update(const sdl2::Input &input) override;
/// @brief Runs the sub-update routine.
void sub_update() override;
/// @brief Renders menu to screen.
void render() override;
void render(sdl2::Renderer &renderer) override;
/// @brief Allows the update task to signal it found an update.
void signal_update_found();
@@ -54,16 +55,16 @@ class MainMenuState final : public BaseState
private:
/// @brief Render target this state renders to.
sdl::SharedTexture m_renderTarget{};
sdl2::SharedTexture m_renderTarget{};
/// @brief The background gradient.
sdl::SharedTexture m_background{};
sdl2::SharedTexture m_background{};
/// @brief Icon for the settings option,
sdl::SharedTexture m_settingsIcon{};
sdl2::SharedTexture m_settingsIcon{};
/// @brief Icon for the extras option.
sdl::SharedTexture m_extrasIcon{};
sdl2::SharedTexture m_extrasIcon{};
/// @brief Special menu type that uses icons.
std::shared_ptr<ui::IconMenu> m_mainMenu{};
@@ -93,7 +94,7 @@ class MainMenuState final : public BaseState
static inline std::vector<std::shared_ptr<BaseState>> sm_states{};
/// @brief Creates the settings and extras.
void initialize_settings_extras();
void initialize_settings_extras(sdl2::Renderer &renderer);
/// @brief Pushes the icons to the main menu.
void initialize_menu();

View File

@@ -21,15 +21,11 @@ class MessageState final : public BaseState
/// @brief Creates and returns a new MessageState. See constructor.
static inline std::shared_ptr<MessageState> create(std::string_view message)
{
return std::make_shared<MessageState>(message);
}
{ return std::make_shared<MessageState>(message); }
/// @brief Creates and returns a new MessageState. See constructor.
static inline std::shared_ptr<MessageState> create(std::string &message)
{
return std::make_shared<MessageState>(message);
}
{ return std::make_shared<MessageState>(message); }
/// @brief Same as above, only pushed to the StateManager before return.
static inline std::shared_ptr<MessageState> create_and_push(std::string_view message)
@@ -66,10 +62,10 @@ class MessageState final : public BaseState
}
/// @brief Update override.
void update() override;
void update(const sdl2::Input &input) override;
/// @brief Render override
void render() override;
void render(sdl2::Renderer &renderer) override;
private:
/// @brief States this state can be in.
@@ -102,7 +98,13 @@ class MessageState final : public BaseState
static inline std::shared_ptr<ui::DialogBox> sm_dialog{};
/// @brief This is the same sound that the confirmation uses.
static inline sdl::SharedSound sm_dialogPop{};
static inline sdl2::SharedSound sm_dialogPop{};
/// @brief Font used to render the message.
static inline sdl2::SharedFont sm_textFont{};
/// @brief Font used to render the OK.
static inline sdl2::SharedFont sm_optionFont{};
/// @brief Allocates and ensures ^
void initialize_static_members();
@@ -111,7 +113,7 @@ class MessageState final : public BaseState
void update_dimensions() noexcept;
/// @brief Updates and handles the input.
void update_handle_input() noexcept;
void update_handle_input(const sdl2::Input &input) noexcept;
/// @brief Closes and "hides" the dialog.
void close_dialog();

View File

@@ -20,9 +20,7 @@ class ProgressState final : public BaseTask
/// @brief Creates and returns a new ProgressState
static inline std::shared_ptr<ProgressState> create(sys::threadpool::JobFunction function, sys::Task::TaskData taskData)
{
return std::make_shared<ProgressState>(function, taskData);
}
{ return std::make_shared<ProgressState>(function, taskData); }
/// @brief Creates, pushes, then returns a new ProgressState.
static inline std::shared_ptr<ProgressState> create_and_push(sys::threadpool::JobFunction function,
@@ -42,10 +40,10 @@ class ProgressState final : public BaseTask
}
/// @brief Checks if the thread is finished and deactivates this state.
void update() override;
void update(const sdl2::Input &input) override;
/// @brief Renders the current progress to screen.
void render() override;
void render(sdl2::Renderer &renderer) override;
private:
/// @brief States this state can be in.
@@ -84,7 +82,10 @@ class ProgressState final : public BaseTask
static inline std::shared_ptr<ui::DialogBox> sm_dialog{};
/// @brief This is rendered over the edges of the bar to give it a slightly rounded look.
static inline sdl::SharedTexture sm_barEdges{};
static inline sdl2::SharedTexture sm_barEdges{};
/// @brief Font used for rendering text.
static inline sdl2::SharedFont sm_font{};
/// @brief Initializes the shared dialog box.
void initialize_static_members();

View File

@@ -19,9 +19,7 @@ class SaveCreateState final : public BaseState
/// @brief Returns a new SaveCreate state. See constructor for arguments.
static inline std::shared_ptr<SaveCreateState> create(data::User *user, TitleSelectCommon *titleSelect)
{
return std::make_shared<SaveCreateState>(user, titleSelect);
}
{ return std::make_shared<SaveCreateState>(user, titleSelect); }
/// @brief Creates, pushes, returns and new SaveCreateState.
static inline std::shared_ptr<SaveCreateState> create_and_push(data::User *user, TitleSelectCommon *titleSelect)
@@ -32,10 +30,10 @@ class SaveCreateState final : public BaseState
}
/// @brief Runs the update routine.
void update() override;
void update(const sdl2::Input &input) override;
/// @brief Runs the render routine.
void render() override;
void render(sdl2::Renderer &renderer) override;
/// @brief This signals so data and the view can be refreshed on the next update() to avoid threading shenanigans.
void refresh_required();

View File

@@ -15,9 +15,7 @@ class SaveImportState final : public BaseState
SaveImportState(data::User *user);
static inline std::shared_ptr<SaveImportState> create(data::User *user)
{
return std::make_shared<SaveImportState>(user);
}
{ return std::make_shared<SaveImportState>(user); }
static inline std::shared_ptr<SaveImportState> create_and_push(data::User *user)
{
@@ -26,9 +24,9 @@ class SaveImportState final : public BaseState
return newState;
}
void update() override;
void update(const sdl2::Input &input) override;
void render() override;
void render(sdl2::Renderer &renderer) override;
// clang-format off
// Struct used to pass data to the task.

View File

@@ -15,13 +15,13 @@ class SettingsState final : public BaseState
static inline std::shared_ptr<SettingsState> create() { return std::make_shared<SettingsState>(); }
/// @brief Runs the update routine.
void update() override;
void update(const sdl2::Input &input) override;
/// @brief Sub update routine.
void sub_update() override;
/// @brief Runs the render routine.
void render() override;
void render(sdl2::Renderer &renderer) override;
private:
/// @brief Menu for selecting and toggling settings.
@@ -35,7 +35,7 @@ class SettingsState final : public BaseState
std::shared_ptr<ui::ControlGuide> m_controlGuide{};
/// @brief Render target to render to.
sdl::SharedTexture m_renderTarget{};
sdl2::SharedTexture m_renderTarget{};
/// @brief Loads the settings menu strings.
void load_settings_menu();

View File

@@ -16,9 +16,7 @@ class TaskState final : public BaseTask
/// @brief Constructs and returns a TaskState.
static inline std::shared_ptr<TaskState> create(sys::threadpool::JobFunction function, sys::Task::TaskData taskData)
{
return std::make_shared<TaskState>(function, taskData);
}
{ return std::make_shared<TaskState>(function, taskData); }
/// @brief Constructs, pushes, then returns a new TaskState.
static inline std::shared_ptr<TaskState> create_and_push(sys::threadpool::JobFunction function,
@@ -38,13 +36,19 @@ class TaskState final : public BaseTask
}
/// @brief Runs update routine. Waits for thread function to signal finish and deactivates.
void update() override;
void update(const sdl2::Input &input) override;
/// @brief Run render routine. Prints m_task's status string to screen, basically.
/// @param
void render() override;
void render(sdl2::Renderer &renderer) override;
private:
/// @brief Font used for rendering text.
static inline sdl2::SharedFont sm_font{};
/// @brief Ensures static members are initialized.
void initialize_static_members();
/// @brief Performs some operations and marks the state for deletion.
void deactivate_state();
};

View File

@@ -15,9 +15,7 @@ class TextTitleSelectState final : public TitleSelectCommon
/// @brief Creates and returns a new TextTitleSelect. See constructor.
static inline std::shared_ptr<TextTitleSelectState> create(data::User *user)
{
return std::make_shared<TextTitleSelectState>(user);
}
{ return std::make_shared<TextTitleSelectState>(user); }
/// @brief Creates, pushes, and returns a new TextTitleSelect.
static std::shared_ptr<TextTitleSelectState> create_and_push(data::User *user)
@@ -28,10 +26,10 @@ class TextTitleSelectState final : public TitleSelectCommon
}
/// @brief Runs update routine.
void update() override;
void update(const sdl2::Input &input) override;
/// @brief Runs render routine.
void render() override;
void render(sdl2::Renderer &renderer) override;
/// @brief Refreshes view for changes.
void refresh() override;
@@ -44,7 +42,7 @@ class TextTitleSelectState final : public TitleSelectCommon
std::shared_ptr<ui::Menu> m_titleSelectMenu{};
/// @brief Target to render to.
sdl::SharedTexture m_renderTarget{};
sdl2::SharedTexture m_renderTarget{};
/// @brief Creates a new backup menu instance.
void create_backup_menu();

View File

@@ -21,9 +21,7 @@ class TitleInfoState final : public BaseState
static inline std::shared_ptr<TitleInfoState> create(data::User *user,
data::TitleInfo *titleInfo,
const FsSaveDataInfo *saveInfo)
{
return std::make_shared<TitleInfoState>(user, titleInfo, saveInfo);
}
{ return std::make_shared<TitleInfoState>(user, titleInfo, saveInfo); }
/// @brief Creates, pushes, and returns a new TitleInfoState.
static inline std::shared_ptr<TitleInfoState> create_and_push(data::User *user,
@@ -36,10 +34,10 @@ class TitleInfoState final : public BaseState
}
/// @brief Runs update routine.
void update() override;
void update(const sdl2::Input &input) override;
/// @brief Runs render routine.
void render() override;
void render(sdl2::Renderer &renderer) override;
private:
/// @brief States this state can be in.
@@ -60,7 +58,7 @@ class TitleInfoState final : public BaseState
const FsSaveDataInfo *m_saveInfo{};
/// @brief This is a pointer to the title's icon.
sdl::SharedTexture m_icon{};
sdl2::SharedTexture m_icon{};
/// @brief Transition for the open/close effect.
ui::Transition m_transition{};
@@ -84,7 +82,7 @@ class TitleInfoState final : public BaseState
static inline std::shared_ptr<ui::Frame> sm_frame{};
/// @brief This is the little chime that plays when this is opened.
static inline sdl::SharedSound sm_openChime{};
static inline sdl2::SharedSound sm_openChime{};
/// @brief Initializes the static members if they haven't been already.
void initialize_static_members();
@@ -126,10 +124,10 @@ class TitleInfoState final : public BaseState
void update_dimensions() noexcept;
/// @brief Handles input and updating.
void update_handle_input() noexcept;
void update_handle_input(const sdl2::Input &input) noexcept;
/// @brief Returns the color to clear the field with.
inline sdl::Color get_field_color() noexcept;
inline SDL_Color get_field_color() noexcept;
/// @brief Signals to close the state.
void close() noexcept;

View File

@@ -23,9 +23,7 @@ class TitleOptionState final : public BaseState
data::TitleInfo *titleInfo,
const FsSaveDataInfo *saveInfo,
TitleSelectCommon *titleSelect)
{
return std::make_shared<TitleOptionState>(user, titleInfo, saveInfo, titleSelect);
}
{ return std::make_shared<TitleOptionState>(user, titleInfo, saveInfo, titleSelect); }
/// @brief Creates, pushes, and returns a new TitleOptionState
static std::shared_ptr<TitleOptionState> create_and_push(data::User *user,
@@ -39,13 +37,13 @@ class TitleOptionState final : public BaseState
}
/// @brief Runs update routine.
void update() override;
void update(const sdl2::Input &input) override;
/// @brief Handles hiding the panel.
void sub_update() override;
/// @brief Runs the render routine.
void render() override;
void render(sdl2::Renderer &renderer) override;
/// @brief This function allows tasks to signal to the spawning state to close itself on the next update() call.
void close_on_update();

View File

@@ -14,13 +14,13 @@ class TitleSelectCommon : public BaseState
virtual ~TitleSelectCommon() {};
/// @brief Required, inherited.
virtual void update() = 0;
virtual void update(const sdl2::Input &input) = 0;
/// @brief Sub-update routine. Normally in a file, but I didn't feel like it really needed one.
void sub_update() override;
/// @brief Required, inherited.
virtual void render() = 0;
virtual void render(sdl2::Renderer &renderer) = 0;
/// @brief Both derived classes need this function.
virtual void refresh() = 0;

View File

@@ -15,9 +15,7 @@ class TitleSelectState final : public TitleSelectCommon
/// @brief Returns a new TitleSelect state.
static inline std::shared_ptr<TitleSelectState> create(data::User *user)
{
return std::make_shared<TitleSelectState>(user);
}
{ return std::make_shared<TitleSelectState>(user); }
/// @brief Creates, pushes, and returns a new TitleSelectState.
static inline std::shared_ptr<TitleSelectState> create_and_push(data::User *user)
@@ -28,10 +26,10 @@ class TitleSelectState final : public TitleSelectCommon
}
/// @brief Runs the update routine.
void update() override;
void update(const sdl2::Input &input) override;
/// @brief Runs the render routine.
void render() override;
void render(sdl2::Renderer &renderer) override;
/// @brief Refreshes the view.
void refresh() override;
@@ -41,7 +39,7 @@ class TitleSelectState final : public TitleSelectCommon
data::User *m_user{};
/// @brief Target to render to.
sdl::SharedTexture m_renderTarget{};
sdl2::SharedTexture m_renderTarget{};
/// @brief Tiled title selection view.
std::shared_ptr<ui::TitleView> m_titleView{};

View File

@@ -18,9 +18,7 @@ class UserOptionState final : public BaseState
/// @brief Returns a new UserOptionState. See constructor.
static inline std::shared_ptr<UserOptionState> create(data::User *user, TitleSelectCommon *titleSelect)
{
return std::make_shared<UserOptionState>(user, titleSelect);
}
{ return std::make_shared<UserOptionState>(user, titleSelect); }
/// @brief Creates, pushes, and returns a new UserOptionState.
static inline std::shared_ptr<UserOptionState> create_and_push(data::User *user, TitleSelectCommon *titleSelect)
@@ -31,13 +29,13 @@ class UserOptionState final : public BaseState
}
/// @brief Runs the render routine.
void update() override;
void update(const sdl2::Input &input) override;
/// @brief Handles hiding the panel.
void sub_update() override;
/// @brief Runs the render routine.
void render() override;
void render(sdl2::Renderer &renderer) override;
/// @brief Signals to the main update() function that a refresh is needed.
/// @note Like this to prevent threading headaches.

View File

@@ -10,16 +10,16 @@ namespace data
DataCommon() = default;
/// @brief Function to load the icon to a texture.
virtual void load_icon() = 0;
virtual void load_icon(sdl2::Renderer &renderer) = 0;
/// @brief Returns the icon.
sdl::SharedTexture get_icon() { return m_icon; };
sdl2::SharedTexture &get_icon() { return m_icon; };
/// @brief Sets the icon.
void set_icon(sdl::SharedTexture &icon) { m_icon = icon; };
void set_icon(sdl2::SharedTexture &icon) { m_icon = icon; };
protected:
/// @brief Shared texture of the icon.
sdl::SharedTexture m_icon{};
sdl2::SharedTexture m_icon{};
};
}

View File

@@ -2,6 +2,7 @@
#include "data/DataCommon.hpp"
#include "data/TitleInfo.hpp"
#include "data/User.hpp"
#include "sdl.hpp"
#include "sys/Task.hpp"
#include <mutex>
@@ -56,7 +57,7 @@ namespace data
bool write_cache(sys::Task *task);
/// @brief Processes the icon queue.
void process_icon_queue();
void process_icon_queue(sdl2::Renderer &renderer);
private:
/// @brief User vector.

View File

@@ -83,16 +83,12 @@ namespace data
/// @return True on success. False on failure.
bool has_save_data_type(uint8_t saveType) const noexcept;
/// @brief Returns a pointer to the icon texture.
/// @return Icon
sdl::SharedTexture get_icon() const noexcept;
/// @brief Allows the path safe title to be set to a new path.
/// @param newPathSafe Buffer containing the new safe path to use.
void set_path_safe_title(const char *newPathSafe) noexcept;
/// @brief Loads the icon from the nacp.
void load_icon() override;
void load_icon(sdl2::Renderer &renderer) override;
private:
/// @brief This defines how long the buffer is for the path safe version of the title.
@@ -114,7 +110,7 @@ namespace data
char m_pathSafeTitle[TitleInfo::SIZE_PATH_SAFE]{};
/// @brief Shared icon texture.
sdl::SharedTexture m_icon{};
sdl2::SharedTexture m_icon{};
/// @brief Private function to get/create the path safe title.
void get_create_path_safe_title() noexcept;

View File

@@ -109,7 +109,7 @@ namespace data
void load_user_data();
/// @brief Loads the icon from the system and converts it to a texture.
void load_icon() override;
void load_icon(sdl2::Renderer &renderer) override;
private:
/// @brief Account's ID

View File

@@ -2,6 +2,7 @@
#include "data/TitleInfo.hpp"
#include "data/User.hpp"
#include "data/accountUID.hpp"
#include "sdl.hpp"
#include "sys/sys.hpp"
#include <unordered_map>
@@ -13,7 +14,7 @@ namespace data
/// @brief Launches the data loading/initialization state.
/// @param clear Whether or not the cache should be cleared.
/// @param onDestruction Function that is executed upon destruction of the data loading screen.
void launch_initialization(bool clear, std::function<void()> onDestruction);
void launch_initialization(bool clear, sdl2::Renderer &renderer, std::function<void()> onDestruction);
/// @brief Writes pointers to users to vectorOut
/// @param userList List to push the pointers to.

View File

@@ -0,0 +1,43 @@
#pragma once
#include "sdl.hpp"
#include <stack>
namespace graphics
{
/// @brief This is a workaround class because of SDLLib changes and I'm not willing to sink a ton of time into JKSV anymore.
class ScopedRender final
{
public:
/// @brief Constructs a new scoped rendering sequence.
/// @param renderer Reference to the renderer.
/// @param target Render target.
ScopedRender(sdl2::Renderer &renderer, sdl2::SharedTexture target)
: m_renderer{renderer}
{
// Push the target.
sm_renderTargets.push(target);
// Set the target.
renderer.set_render_target(sm_renderTargets.top());
}
/// @brief Ends the ScopedRender'ing.
~ScopedRender()
{
// Pop.
sm_renderTargets.pop();
// Set.
m_renderer.set_render_target(sm_renderTargets.top());
}
private:
/// @brief Reference to the renderer.
sdl2::Renderer &m_renderer;
/// @brief Stack of render targets. Init'd with null as the base.
static inline std::stack<sdl2::SharedTexture> sm_renderTargets =
std::stack<sdl2::SharedTexture>({sdl2::Texture::null});
};
}

View File

@@ -3,26 +3,26 @@
namespace colors
{
inline constexpr sdl::Color WHITE = {0xFFFFFFFF};
inline constexpr sdl::Color BLACK = {0x000000FF};
inline constexpr sdl::Color RED = {0xFF0000FF};
inline constexpr sdl::Color DARK_RED = {0xDD0000FF};
inline constexpr sdl::Color GREEN = {0x00FF00FF};
inline constexpr sdl::Color BLUE = {0x0099EEFF};
inline constexpr sdl::Color YELLOW = {0xF8FC00FF};
inline constexpr sdl::Color PINK = {0xFF4444FF};
inline constexpr sdl::Color BLUE_GREEN = {0x00FFC5FF};
inline constexpr sdl::Color CLEAR_COLOR = {0x2D2D2DFF};
inline constexpr sdl::Color CLEAR_PANEL = {0x0D0D0DFF};
inline constexpr sdl::Color DIALOG_DARK = {0x505050FF};
inline constexpr sdl::Color DIALOG_LIGHT = {0xDCDCDCFF};
inline constexpr sdl::Color DIM_BACKGROUND = {0x00061180};
inline constexpr sdl::Color TRANSPARENT = {0x00000000};
inline constexpr sdl::Color SLIDE_PANEL_CLEAR = {0x000000CC};
inline constexpr sdl::Color DIV_COLOR = {0x707070FF};
inline constexpr sdl::Color GUIDE_COLOR = {0x0000007F};
inline constexpr sdl::Color BAR_GREEN = {0x11CC33FF};
inline constexpr sdl::Color GOLD = {0xFFD700FF};
inline constexpr SDL_Color WHITE = {0xFF, 0xFF, 0xFF, 0xFF};
inline constexpr SDL_Color BLACK = {0x00, 0x00, 0x00, 0xFF};
inline constexpr SDL_Color RED = {0xFF, 0x00, 0x00, 0xFF};
inline constexpr SDL_Color DARK_RED = {0xDD, 0x00, 0x00, 0xFF};
inline constexpr SDL_Color GREEN = {0x00, 0xFF, 0x00, 0xFF};
inline constexpr SDL_Color BLUE = {0x00, 0x99, 0xEE, 0xFF};
inline constexpr SDL_Color YELLOW = {0xF8, 0xFC, 0x00, 0xFF};
inline constexpr SDL_Color PINK = {0xFF, 0x44, 0x44, 0xFF};
inline constexpr SDL_Color BLUE_GREEN = {0x00, 0xFF, 0xC5, 0xFF};
inline constexpr SDL_Color CLEAR_COLOR = {0x2D, 0x2D, 0x2D, 0xFF};
inline constexpr SDL_Color CLEAR_PANEL = {0x0D, 0x0D, 0x0D, 0xFF};
inline constexpr SDL_Color DIALOG_DARK = {0x50, 0x50, 0x50, 0xFF};
inline constexpr SDL_Color DIALOG_LIGHT = {0xDC, 0xDC, 0xDC, 0xFF};
inline constexpr SDL_Color DIM_BACKGROUND = {0x00, 0x06, 0x11, 0x80};
inline constexpr SDL_Color TRANSPARENT = {0x00, 0x00, 0x00, 0x00};
inline constexpr SDL_Color SLIDE_PANEL_CLEAR = {0x00, 0x00, 0x00, 0xCC};
inline constexpr SDL_Color DIV_COLOR = {0x70, 0x70, 0x70, 0xFF};
inline constexpr SDL_Color GUIDE_COLOR = {0x00, 0x00, 0x00, 0x7F};
inline constexpr SDL_Color BAR_GREEN = {0x11, 0xCC, 0x33, 0xFF};
inline constexpr SDL_Color GOLD = {0xFF, 0xD7, 0x00, 0xFF};
inline constexpr uint8_t ALPHA_FADE_BEGIN = 0x00;
inline constexpr uint8_t ALPHA_FADE_END = 0x80;

View File

@@ -0,0 +1,28 @@
#pragma once
#include <string_view>
namespace graphics::fonts
{
namespace names
{
// These are all the internal names of the fonts so the mananger pulls and reuses them.
inline constexpr std::string_view FOURTEEN_PIXEL = "FourteenPixel";
inline constexpr std::string_view TWENTY_PIXEL = "TwentyPixel";
inline constexpr std::string_view TWENTY_TWO_PIXEL = "TwentyTwoPixel";
inline constexpr std::string_view TWENTY_FOUR_PIXEL = "TwentyFourPixel";
inline constexpr std::string_view THIRTY_TWO_PIXEL = "ThirtyTwoPixel";
inline constexpr std::string_view THIRTY_FOUR_PIXEL = "ThirtyFourPixel";
}
namespace sizes
{
// These are the pixel sizes.
inline constexpr int FOURTEEN_PIXEL = 14;
inline constexpr int TWENTY_PIXEL = 20;
inline constexpr int TWENTY_TWO_PIXEL = 22;
inline constexpr int TWENTY_FOUR_PIXEL = 24;
inline constexpr int THIRTY_TWO_PIXEL = 32;
inline constexpr int THIRTY_FOUR_PIXEL = 34;
}
}

View File

@@ -12,5 +12,9 @@ namespace gfxutil
/// @param background Background color to use.
/// @param foreground Color to use to render the text.
/// @return sdl::SharedTexture of the icon.
sdl::SharedTexture create_generic_icon(std::string_view text, int fontSize, sdl::Color background, sdl::Color foreground);
sdl2::SharedTexture create_generic_icon(sdl2::Renderer &renderer,
std::string_view text,
int fontSize,
SDL_Color background,
SDL_Color textColor);
} // namespace gfxutil

View File

@@ -0,0 +1,17 @@
#pragma once
#include <string_view>
namespace graphics::targets
{
namespace names
{
inline constexpr std::string_view SECONDARY = "SecondaryTarget";
}
namespace dims
{
// Dimensions of the secondary render target.
inline constexpr int SECONDARY_WIDTH = 1080;
inline constexpr int SECONDARY_HEIGHT = 555;
}
}

View File

@@ -1,23 +0,0 @@
#pragma once
#include <switch.h>
namespace input
{
/// @brief Initializes PadState and input.
void initialize();
/// @brief Updates the PadState.
void update() noexcept;
/// @brief Returns if a button was pressed the current frame, but not the previous.
/// @param button Button to check.
bool button_pressed(HidNpadButton button) noexcept;
/// @brief Returns if the button was pressed or held the previous and current frame.
/// @param button Button to check.
bool button_held(HidNpadButton button) noexcept;
/// @brief Returns if the button was pressed or held the previous frame, but not the current.
/// @param button Button to check.
bool button_released(HidNpadButton button) noexcept;
} // namespace input

View File

@@ -7,7 +7,11 @@ namespace math
class Util
{
public:
static inline Type absolute_distance(Type a, Type b) noexcept { return a > b ? a - b : b - a; }
/// @brief Calculates the distance between two Types and returns the result as a positive Type.
static inline constexpr Type absolute_distance(Type a, Type b) noexcept { return a > b ? a - b : b - a; }
/// @brief Returns size centered within area.
static inline constexpr Type center_within(Type area, Type size) noexcept { return (area / 2) - (size / 2); }
};
}

View File

@@ -19,15 +19,13 @@ namespace ui
/// @brief Creates a returns a new BoundingBox. See constructor.
static inline std::shared_ptr<ui::BoundingBox> create(int x, int y, int width, int height)
{
return std::make_shared<ui::BoundingBox>(x, y, width, height);
}
{ return std::make_shared<ui::BoundingBox>(x, y, width, height); }
/// @brief Update override.
void update(bool hasFocus) override;
void update(const sdl2::Input &input, bool hasFocus) override;
/// @brief Render override.
void render(sdl::SharedTexture &target, bool hasFocus) override;
void render(sdl2::Renderer &renderer, bool hasFocus) override;
/// @brief Sets the X coord.
void set_x(int x) noexcept;
@@ -58,7 +56,7 @@ namespace ui
ui::ColorMod m_colorMod{};
/// @brief This is shared by all instances.
static inline sdl::SharedTexture sm_corners{};
static inline sdl2::SharedTexture sm_corners{};
/// @brief Loads ^
void initialize_static_members();

View File

@@ -17,7 +17,7 @@ namespace ui
/// @brief Operator that allows using this as an sdl::Color directly.
/// @note Since all of these pulse the same color, no sense in not doing this.
operator sdl::Color() const noexcept;
operator SDL_Color() const noexcept;
private:
/// @brief Whether we're adding or subtracting from the color value.

View File

@@ -14,18 +14,16 @@ namespace ui
/// @brief Factory function to return a control guide.
static inline std::shared_ptr<ControlGuide> create(const char *guide)
{
return std::make_shared<ControlGuide>(guide);
}
{ return std::make_shared<ControlGuide>(guide); }
/// @brief Update routine. Opens the guide.
void update(bool hasFocus) override;
void update(const sdl2::Input &input, bool hasFocus) override;
/// @brief Sub update routine. Handles hiding the control guide.
void sub_update();
/// @brief Renders the control guide. Both arguments are ignored in this case.
void render(sdl::SharedTexture &target, bool hasFocus) override;
void render(sdl2::Renderer &renderer, bool hasFocus) override;
/// @brief This is a workaround for states where the guide can't really be hidden correctly. Ex: FileMode.
void reset() noexcept;
@@ -59,7 +57,10 @@ namespace ui
ControlGuide::State m_state{};
/// @brief This is shared by all instances.
static inline sdl::SharedTexture sm_controlCap{};
static inline sdl2::SharedTexture sm_controlCap{};
/// @brief Font used to render text.
static inline sdl2::SharedFont sm_font{};
/// @brief Ensures the control guide cap is loaded for all instances.
void initialize_static_members();

View File

@@ -29,17 +29,15 @@ namespace ui
int width,
int height,
DialogBox::Type type = DialogBox::Type::Dark)
{
return std::make_shared<ui::DialogBox>(x, y, width, height, type);
}
{ return std::make_shared<ui::DialogBox>(x, y, width, height, type); }
/// @brief Update override. This does NOTHING!
void update(bool hasFocus) override {};
void update(const sdl2::Input &input, bool hasFocus) override {};
/// @brief Renders the dialog box to screen.
/// @param target Render target to render to.
/// @param hasFocus This is ignored.
void render(sdl::SharedTexture &target, bool hasFocus) override;
void render(sdl2::Renderer &renderer, bool hasFocus) override;
/// @brief Sets the X render coord.
void set_x(int x) noexcept;
@@ -75,10 +73,10 @@ namespace ui
DialogBox::Type m_type{};
/// @brief All instances shared this and the other.
static inline sdl::SharedTexture sm_darkCorners{};
static inline sdl2::SharedTexture sm_darkCorners{};
/// @brief This is the light cer
static inline sdl::SharedTexture sm_lightCorners{};
static inline sdl2::SharedTexture sm_lightCorners{};
/// @brief Initializes and loads the corners texture.
void initialize_static_members();

View File

@@ -15,11 +15,11 @@ namespace ui
/// @brief Virtual update method. All derived classes must have this.
/// @param HasFocus Whether or not the state containing the element currently has focus.
virtual void update(bool HasFocus) = 0;
virtual void update(const sdl2::Input &input, bool HasFocus) = 0;
/// @brief Virtual render method. All derived classes must have this.
/// @param target Target to render to.
/// @param hasFocus Whether or not the containing state has focus.
virtual void render(sdl::SharedTexture &target, bool hasFocus) = 0;
virtual void render(sdl2::Renderer &renderer, bool hasFocus) = 0;
};
} // namespace ui

View File

@@ -15,15 +15,13 @@ namespace ui
/// @brief Inline function to make constructing nicer.
static inline std::shared_ptr<ui::Frame> create(int x, int y, int width, int height)
{
return std::make_shared<ui::Frame>(x, y, width, height);
}
{ return std::make_shared<ui::Frame>(x, y, width, height); }
/// @brief Doesn't need to do anything for this.
void update(bool hasFocus) override {};
void update(const sdl2::Input &input, bool hasFocus) override {};
/// @brief Renders the frame to the target passed.
void render(sdl::SharedTexture &target, bool hasFocus) override;
void render(sdl2::Renderer &renderer, bool hasFocus) override;
/// @brief Sets the X coord.
void set_x(int x) noexcept;
@@ -54,7 +52,7 @@ namespace ui
int m_height{};
/// @brief This texture is shared by all instances.
static inline sdl::SharedTexture sm_frameCorners{};
static inline sdl2::SharedTexture sm_frameCorners{};
/// @brief Ensures the texture is loading if it hasn't been.
void initialize_static_members();

View File

@@ -20,9 +20,7 @@ namespace ui
/// @brief Creates and returns a new IconMenu instance.
static inline std::shared_ptr<ui::IconMenu> create(int x, int y, int renderTargetHeight)
{
return std::make_shared<ui::IconMenu>(x, y, renderTargetHeight);
}
{ return std::make_shared<ui::IconMenu>(x, y, renderTargetHeight); }
/// @brief Initializes the menu.
/// @param x X coordinate to render the menu to.
@@ -33,19 +31,19 @@ namespace ui
/// @brief Runs the update routine.
/// @param hasFocus Whether or not the containing state has focus.
void update(bool hasFocus) override;
void update(const sdl2::Input &input, bool hasFocus) override;
/// @brief Runs the render routine.
/// @param target Target to render to.
/// @param hasFocus Whether or not the containing state has focus.
void render(sdl::SharedTexture &target, bool hasFocus) override;
void render(sdl2::Renderer &renderer, bool hasFocus) override;
/// @brief Adds a new icon to the menu.
/// @param newOption Icon to add.
void add_option(sdl::SharedTexture newOption);
void add_option(sdl2::SharedTexture newOption);
private:
/// @brief Vector of shared texture pointers to textures used.
std::vector<sdl::SharedTexture> m_options;
std::vector<sdl2::SharedTexture> m_options;
};
} // namespace ui

View File

@@ -26,18 +26,16 @@ namespace ui
/// @brief Creates and returns a new ui::Menu instance.
static inline std::shared_ptr<ui::Menu> create(int x, int y, int width, int fontSize, int renderTargetHeight)
{
return std::make_shared<ui::Menu>(x, y, width, fontSize, renderTargetHeight);
}
{ return std::make_shared<ui::Menu>(x, y, width, fontSize, renderTargetHeight); }
/// @brief Runs the update routine.
/// @param hasFocus Whether or not the calling state has focus.
void update(bool HasFocus) override;
void update(const sdl2::Input &input, bool HasFocus) override;
/// @brief Renders the menu.
/// @param target Target to render to.
/// @param hasFocus Whether or not the calling state has focus.
void render(sdl::SharedTexture &target, bool hasFocus) override;
void render(sdl2::Renderer &renderer, bool hasFocus) override;
/// @brief Adds an option to the menu.
/// @param newOption Option to add to menu.
@@ -94,7 +92,7 @@ namespace ui
int m_optionHeight{};
/// @brief Target options are rendered to.
sdl::SharedTexture m_optionTarget{};
sdl2::SharedTexture m_optionTarget{};
/// @brief Bounding box for the selected option.
std::shared_ptr<ui::BoundingBox> m_boundingBox{};
@@ -127,8 +125,11 @@ namespace ui
/// @brief Text scroll for when the current option is too long to on screen.
std::shared_ptr<ui::TextScroll> m_optionScroll{};
/// @brief Font used to render the text.
sdl2::SharedFont m_font{};
/// @brief The sound played when the selected/cursor moves.
static inline sdl::SharedSound sm_cursor{};
static inline sdl2::SharedSound sm_cursor{};
/// @brief Calculates the alignment variables.
void calculate_alignments() noexcept;
@@ -152,6 +153,6 @@ namespace ui
void update_scrolling();
/// @brief Handles the menu's input routine.
void handle_input();
void handle_input(const sdl2::Input &input);
};
} // namespace ui

View File

@@ -7,7 +7,7 @@
namespace ui
{
class PopMessage
class PopMessage final
{
public:
/// @brief PopMessage constructor.
@@ -20,7 +20,7 @@ namespace ui
void update(double targetY);
/// @brief Renders the dialog and text.
void render();
void render(sdl2::Renderer &renderer);
/// @brief Returns whether or not the message can be purged.
bool finished() const noexcept;
@@ -65,7 +65,10 @@ namespace ui
sys::Timer m_typeTimer{};
/// @brief This is the texture used for the ends of the messages.
static inline sdl::SharedTexture sm_endCaps{};
static inline sdl2::SharedTexture sm_endCaps{};
/// @brief Font used to render text.
static inline sdl2::SharedFont sm_font{};
/// @brief Ensures ^ is loaded and ready to go.
void initialize_static_members();
@@ -83,6 +86,6 @@ namespace ui
void update_display_timer() noexcept;
/// @brief Renders the container around the message.
void render_container() noexcept;
void render_container(sdl2::Renderer &renderer) noexcept;
};
}

View File

@@ -23,7 +23,7 @@ namespace ui
static void update();
/// @brief Renders messages to screen.
static void render();
static void render(sdl2::Renderer &renderer);
/// @brief Pushes a new message to the queue for processing.
static void push_message(int displayTicks, std::string_view message);
@@ -57,7 +57,7 @@ namespace ui
std::mutex m_queueMutex{};
/// @brief The little chirp that's played when messages pop.
sdl::SharedSound m_popSound{};
sdl2::SharedSound m_popSound{};
/// @brief Loads the pop message sound into memory.
void initialize_pop_sound();

View File

@@ -29,13 +29,11 @@ namespace ui
/// @brief Creates and returns and new ui::SlideOutPanel instance.
static inline std::shared_ptr<ui::SlideOutPanel> create(int width, SlideOutPanel::Side side)
{
return std::make_shared<ui::SlideOutPanel>(width, side);
}
{ return std::make_shared<ui::SlideOutPanel>(width, side); }
/// @brief Runs the update routine.
/// @param hasFocus Whether or not the calling state has focus.
void update(bool hasFocus) override;
void update(const sdl2::Input &input, bool hasFocus) override;
/// @brief Sub update routine. Allows the panel to hide and unhide itself even when not in focus.
void sub_update();
@@ -43,10 +41,10 @@ namespace ui
/// @brief Runs the render routine.
/// @param target Target to render to.
/// @param hasFocus Whether or the the calling state has focus.
void render(sdl::SharedTexture &target, bool hasFocus) override;
void render(sdl2::Renderer &renderer, bool hasFocus) override;
/// @brief Clears the target to a semi-transparent black. To do: Maybe not hard coded color.
void clear_target();
void clear_target(sdl2::Renderer &renderer);
/// @brief Resets the panel back to its default state.
void reset() noexcept;
@@ -83,7 +81,7 @@ namespace ui
/// @brief Returns a pointer to the render target of the panel.
/// @return Raw SDL_Texture pointer to target.
sdl::SharedTexture &get_target() noexcept;
sdl2::SharedTexture &get_target() noexcept;
private:
/// @brief States the panel can be in.
@@ -113,7 +111,7 @@ namespace ui
SlideOutPanel::State m_state{};
/// @brief Render target if panel.
sdl::SharedTexture m_renderTarget{};
sdl2::SharedTexture m_renderTarget{};
/// @brief Vector of elements.
std::vector<std::shared_ptr<ui::Element>> m_elements{};
@@ -131,6 +129,6 @@ namespace ui
void update_position_state() noexcept;
/// @brief Updates sub-elements.
void update_sub_elements(bool hasFocus) noexcept;
void update_sub_elements(const sdl2::Input &input, bool hasFocus) noexcept;
};
} // namespace ui

View File

@@ -28,8 +28,8 @@ namespace ui
int width,
int height,
int fontSize,
sdl::Color textColor,
sdl::Color clearColor,
SDL_Color textColor,
SDL_Color clearColor,
bool center = true);
TextScroll(std::string &text,
@@ -38,8 +38,8 @@ namespace ui
int width,
int height,
int fontSize,
sdl::Color textColor,
sdl::Color clearColor,
SDL_Color textColor,
SDL_Color clearColor,
bool center = true);
/// @brief Creates and returns a new TextScroll. See constructor.
@@ -49,12 +49,10 @@ namespace ui
int width,
int height,
int fontSize,
sdl::Color textColor,
sdl::Color clearColor,
SDL_Color textColor,
SDL_Color clearColor,
bool center = true)
{
return std::make_shared<ui::TextScroll>(text, x, y, width, height, fontSize, textColor, clearColor, center);
}
{ return std::make_shared<ui::TextScroll>(text, x, y, width, height, fontSize, textColor, clearColor, center); }
static inline std::shared_ptr<ui::TextScroll> create(std::string &text,
int x,
@@ -62,12 +60,10 @@ namespace ui
int width,
int height,
int fontSize,
sdl::Color textColor,
sdl::Color clearColor,
SDL_Color textColor,
SDL_Color clearColor,
bool center = true)
{
return std::make_shared<ui::TextScroll>(text, x, y, width, height, fontSize, textColor, clearColor, center);
}
{ return std::make_shared<ui::TextScroll>(text, x, y, width, height, fontSize, textColor, clearColor, center); }
/// @brief Creates/sets the text and parameters for TextScroll.
/// @param text Text to display/scroll.
@@ -82,8 +78,8 @@ namespace ui
int width,
int height,
int fontSize,
sdl::Color textColor,
sdl::Color clearColor,
SDL_Color textColor,
SDL_Color clearColor,
bool center = true);
void initialize(std::string &text,
@@ -92,18 +88,18 @@ namespace ui
int width,
int height,
int fontSize,
sdl::Color textColor,
sdl::Color clearColor,
SDL_Color textColor,
SDL_Color clearColor,
bool center = true);
/// @brief Runs the update routine.
/// @param hasFocus Whether or not the calling state has focus.
void update(bool hasFocus) override;
void update(const sdl2::Input &input, bool hasFocus) override;
/// @brief Runs the render routine.
/// @param target Target to render to.
/// @param hasFocus Whether or not the calling state has focus.
void render(sdl::SharedTexture &target, bool hasFocus) override;
void render(sdl2::Renderer &renderer, bool hasFocus) override;
/// @brief Returns the current text being used for scrolling.
std::string_view get_text() const noexcept;
@@ -133,11 +129,14 @@ namespace ui
/// @brief Font size used to calculate and render text.
int m_fontSize{};
/// @brief Font used to render text.
sdl2::SharedFont m_font{};
/// @brief Color used to render the text.
sdl::Color m_textColor{};
SDL_Color m_textColor{};
/// @brief Color used to clear the render target.
sdl::Color m_clearColor{};
SDL_Color m_clearColor{};
/// @brief Width of text in pixels.
int m_textWidth{};
@@ -155,9 +154,16 @@ namespace ui
bool m_textScrollTriggered{};
/// @brief Render target for the text so it can't be rendered outside of it.
sdl::SharedTexture m_renderTarget{};
sdl2::SharedTexture m_renderTarget{};
/// @brief Timer for scrolling text.
sys::Timer m_scrollTimer;
/// @brief Generates and returns the name of the render target for the text scroll.
std::string generate_target_name();
/// @brief Generates a font name using the font size passed.
/// @param fontSize Size of the font.
std::string generate_font_name(int fontSize);
};
} // namespace ui
} // namespace ui

View File

@@ -11,17 +11,17 @@ namespace ui
/// @brief Constructor.
/// @param isFavorite Whether the title is a favorite and should have the little heart rendered.
/// @param icon Shared texture pointer to the icon.
TitleTile(bool isFavorite, int index, sdl::SharedTexture icon);
TitleTile(bool isFavorite, int index, sdl2::SharedTexture &icon);
/// @brief Runs the update routine.
/// @param isSelected Whether or not the tile is selected and needs to expand.
void update(int selected);
void update(bool isSelected);
/// @brief Runs the render routine.
/// @param target Target to render to.
/// @param x X coordinate to render to.
/// @param y Y coordinate to render to.
void render(sdl::SharedTexture &target, int x, int y);
void render(int x, int y);
/// @brief Resets the width and height of the tile.
void reset() noexcept;
@@ -41,10 +41,13 @@ namespace ui
/// @brief Whether or not the title is a favorite.
bool m_isFavorite{};
int m_index{};
/// @brief Title's icon texture.
sdl::SharedTexture m_icon{};
sdl2::SharedTexture m_icon{};
/// @brief Font used for rendering the heart over the icon.
static inline sdl2::SharedFont sm_heartFont{};
/// @brief Ensures the font is loaded.,
void initialize_static_members();
};
} // namespace ui

View File

@@ -20,18 +20,16 @@ namespace ui
TitleView(data::User *user);
static inline std::shared_ptr<ui::TitleView> create(data::User *user)
{
return std::make_shared<ui::TitleView>(user);
}
{ return std::make_shared<ui::TitleView>(user); }
/// @brief Runs the update routine.
/// @param hasFocus Whether the calling state has focus.
void update(bool hasFocus) override;
void update(const sdl2::Input &input, bool hasFocus) override;
/// @brief Runs the render routine.
/// @param target Target to render to.
/// @param hasFocus Whether or not the calling state has focus.
void render(sdl::SharedTexture &target, bool hasFocus) override;
void render(sdl2::Renderer &renderer, bool hasFocus) override;
/// @brief Returns index of the currently selected tile.
/// @return Index of currently selected tile.
@@ -75,13 +73,13 @@ namespace ui
std::shared_ptr<ui::BoundingBox> m_bounding{};
/// @brief Sound that is played when the selected title changes. This is shared with the menu code.
static inline sdl::SharedSound sm_cursor{};
static inline sdl2::SharedSound sm_cursor{};
/// @brief Ensures static members are initialized properly.
void initialize_static_members();
/// @brief Performs the input routine.
void handle_input();
void handle_input(const sdl2::Input &input);
/// @brief Performs the "scrolling" routine.
void handle_scrolling();