From 8170e5ce667c07df9de349e0a4847d12c625408b Mon Sep 17 00:00:00 2001 From: J-D-K Date: Thu, 30 Oct 2025 18:11:16 -0400 Subject: [PATCH] Minor revisions and cleanup. --- include/BufferQueue.hpp | 3 + include/appstates/ConfirmState.hpp | 79 +++++++++++++++++++++--- include/builddate.hpp | 2 +- include/fs/ScopedSaveMount.hpp | 7 ++- include/graphics/screen.hpp | 7 +++ include/mathutil.hpp | 2 + include/stringutil.hpp | 5 +- include/ui/SlideOutPanel.hpp | 5 +- include/ui/Transition.hpp | 4 ++ romfs/Sound/MenuCursor.wav | Bin 2528 -> 750 bytes source/JKSV.cpp | 47 +++++++++++--- source/StateManager.cpp | 1 + source/appstates/BlacklistEditState.cpp | 3 +- source/appstates/DataLoadingState.cpp | 3 +- source/appstates/FadeState.cpp | 3 +- source/appstates/FileModeState.cpp | 9 +-- source/appstates/FileOptionState.cpp | 8 ++- source/appstates/MessageState.cpp | 5 +- source/appstates/ProgressState.cpp | 5 +- source/appstates/SaveCreateState.cpp | 2 +- source/appstates/SaveImportState.cpp | 2 +- source/appstates/TaskState.cpp | 3 +- source/appstates/TitleOptionState.cpp | 2 +- source/appstates/UserOptionState.cpp | 2 +- source/data/User.cpp | 12 +--- source/fs/MiniUnzip.cpp | 4 ++ source/fs/MiniZip.cpp | 6 ++ source/fs/ScopedSaveMount.cpp | 20 ++++-- source/gfxutil.cpp | 2 +- source/remote/Form.cpp | 14 ++++- source/remote/GoogleDrive.cpp | 6 ++ source/remote/Item.cpp | 4 +- source/remote/Storage.cpp | 7 ++- source/remote/URL.cpp | 47 +++++++++++--- source/remote/WebDav.cpp | 6 ++ source/stringutil.cpp | 11 +++- source/sys/OpTimer.cpp | 4 ++ source/sys/ProgressTask.cpp | 4 ++ source/sys/Task.cpp | 4 ++ source/sys/Timer.cpp | 4 ++ source/ui/BoundingBox.cpp | 6 ++ source/ui/ColorMod.cpp | 2 + source/ui/ControlGuide.cpp | 55 ++++++++++++++--- source/ui/DialogBox.cpp | 6 ++ source/ui/Frame.cpp | 6 ++ source/ui/IconMenu.cpp | 4 ++ source/ui/Menu.cpp | 6 ++ source/ui/PopMessage.cpp | 14 +++-- source/ui/PopMessageManager.cpp | 6 ++ source/ui/SlideOutPanel.cpp | 18 +++--- source/ui/TextScroll.cpp | 4 ++ source/ui/TitleTile.cpp | 4 ++ source/ui/TitleView.cpp | 4 ++ source/ui/Transition.cpp | 6 ++ 54 files changed, 414 insertions(+), 91 deletions(-) create mode 100644 include/graphics/screen.hpp diff --git a/include/BufferQueue.hpp b/include/BufferQueue.hpp index 4de4834..04d86ad 100644 --- a/include/BufferQueue.hpp +++ b/include/BufferQueue.hpp @@ -25,6 +25,7 @@ class BufferQueue final BufferQueue(int bufferLimit) noexcept : m_bufferLimit(bufferLimit) {}; + /// @brief Attempts the push the buffer to the queue. Returns false if it fails. inline bool try_push(Buffer &buffer, size_t bufferSize) { std::lock_guard queueGuard{m_queueMutex}; @@ -34,6 +35,7 @@ class BufferQueue final return true; } + /// @brief Gets and returns the pair at the front of the queue if there is one. Returns false if this fails. inline bool get_front(QueuePair &pairOut) { std::lock_guard queueGuard{m_queueMutex}; @@ -44,6 +46,7 @@ class BufferQueue final return true; } + /// @brief This is the default delay period to use if either of the above fail. static inline void default_delay() noexcept { std::this_thread::sleep_for(std::chrono::microseconds(10)); } /// @brief This can be passed to the constructor to make is_full() return false all of the time. diff --git a/include/appstates/ConfirmState.hpp b/include/appstates/ConfirmState.hpp index 0d42230..28caeba 100644 --- a/include/appstates/ConfirmState.hpp +++ b/include/appstates/ConfirmState.hpp @@ -5,6 +5,7 @@ #include "appstates/ProgressState.hpp" #include "appstates/TaskState.hpp" #include "graphics/colors.hpp" +#include "graphics/screen.hpp" #include "input.hpp" #include "logging/logger.hpp" #include "sdl.hpp" @@ -22,6 +23,13 @@ namespace constexpr int COORD_YES_X = 460; // ^ but for no. constexpr int COORD_NO_X = 820; + + // Transition starting vars. + constexpr int TRANS_X = 280; + constexpr int TRANS_Y = 229; + constexpr int TRANS_BEGIN_WIDTH_HEIGHT = 32; + constexpr int TRANS_END_WIDTH = 720; + constexpr int TRANS_END_HEIGHT = 256; } // namespace /// @brief Templated class to create confirmation dialogs. @@ -47,7 +55,15 @@ class ConfirmState final : public BaseState , m_yesText(strings::get_by_name(strings::names::YES_NO_OK, 0)) , m_noText(strings::get_by_name(strings::names::YES_NO_OK, 1)) , m_holdRequired(holdRequired) - , m_transition(280, 229, 32, 32, 280, 229, 720, 256, 4) + , m_transition(TRANS_X, + TRANS_Y, + TRANS_BEGIN_WIDTH_HEIGHT, + TRANS_BEGIN_WIDTH_HEIGHT, + TRANS_X, + TRANS_Y, + TRANS_END_WIDTH, + TRANS_END_HEIGHT, + ui::Transition::DEFAULT_THRESHOLD) , m_onConfirm(onConfirm) , m_onCancel(onCancel) , m_taskData(taskData) @@ -122,20 +138,69 @@ class ConfirmState final : public BaseState /// @brief Renders the state to screen. void render() 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. + static constexpr int LINE_A_X_A = 280; + static constexpr int LINE_A_X_B = 999; + + // Divider line B. + static constexpr int LINE_B_X = 640; + static constexpr int LINE_B_Y_B = 255; + + // Shared line stuff. + static constexpr int LINE_Y_OFFSET = 192; + + // Yes/NO + static constexpr int OPTION_Y_OFFSET = 214; + static constexpr int OPTION_FONT_SIZE = 22; + const bool hasFocus = BaseState::has_focus(); const int y = m_transition.get_y(); - sdl::render_rect_fill(sdl::Texture::Null, 0, 0, 1280, 720, colors::DIM_BACKGROUND); + sdl::render_rect_fill(sdl::Texture::Null, + 0, + 0, + graphics::SCREEN_WIDTH, + graphics::SCREEN_HEIGHT, + colors::DIM_BACKGROUND); sm_dialog->render(sdl::Texture::Null, hasFocus); if (!m_transition.in_place() || m_close) { return; } - sdl::text::render(sdl::Texture::Null, 312, y + 24, 20, 656, colors::WHITE, m_query); + sdl::text::render(sdl::Texture::Null, + TEXT_X, + y + TEXT_Y_OFFSET, + TEXT_FONT_SIZE, + TEXT_WRAP_WIDTH, + colors::WHITE, + m_query); - sdl::render_line(sdl::Texture::Null, 280, y + 192, 999, y + 192, colors::DIV_COLOR); - sdl::render_line(sdl::Texture::Null, 640, y + 192, 640, y + 255, colors::DIV_COLOR); + 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); - sdl::text::render(sdl::Texture::Null, m_yesX, y + 214, 22, sdl::text::NO_WRAP, colors::WHITE, m_yesText); - sdl::text::render(sdl::Texture::Null, m_noX, y + 214, 22, sdl::text::NO_WRAP, colors::WHITE, m_noText); + sdl::text::render(sdl::Texture::Null, + m_yesX, + y + OPTION_Y_OFFSET, + OPTION_FONT_SIZE, + sdl::text::NO_WRAP, + colors::WHITE, + m_yesText); + sdl::text::render(sdl::Texture::Null, + m_noX, + y + OPTION_Y_OFFSET, + OPTION_FONT_SIZE, + sdl::text::NO_WRAP, + colors::WHITE, + m_noText); } private: diff --git a/include/builddate.hpp b/include/builddate.hpp index 5aac9cd..80e8431 100644 --- a/include/builddate.hpp +++ b/include/builddate.hpp @@ -3,6 +3,6 @@ namespace builddate { inline constexpr int MONTH = 10; - inline constexpr int DAY = 10; + inline constexpr int DAY = 30; inline constexpr int YEAR = 2025; } diff --git a/include/fs/ScopedSaveMount.hpp b/include/fs/ScopedSaveMount.hpp index 91c18ee..6d9bf16 100644 --- a/include/fs/ScopedSaveMount.hpp +++ b/include/fs/ScopedSaveMount.hpp @@ -13,15 +13,15 @@ namespace fs /// @param log Optional. Whether or not logging errors is wanted. True by default. ScopedSaveMount(std::string_view mount, const FsSaveDataInfo *saveInfo, bool log = true); + /// @brief Closes the save mounted. + ~ScopedSaveMount(); + ScopedSaveMount(ScopedSaveMount &&scopedSaveMount) noexcept; ScopedSaveMount &operator=(ScopedSaveMount &&scopedSaveMount) noexcept; ScopedSaveMount(const ScopedSaveMount &) = delete; ScopedSaveMount &operator=(const ScopedSaveMount &) = delete; - /// @brief Closes the save mounted. - ~ScopedSaveMount(); - /// @brief Returns whether or not mounting the data was successful. bool is_open() const noexcept; @@ -32,6 +32,7 @@ namespace fs /// @brief Stores whether or not mounting the save was successful. bool m_isOpen{}; + /// @brief Stores whether or not to log errors with the mount. bool m_log{}; }; } diff --git a/include/graphics/screen.hpp b/include/graphics/screen.hpp new file mode 100644 index 0000000..5825823 --- /dev/null +++ b/include/graphics/screen.hpp @@ -0,0 +1,7 @@ +#pragma once + +namespace graphics +{ + inline constexpr int SCREEN_WIDTH = 1280; + inline constexpr int SCREEN_HEIGHT = 720; +} \ No newline at end of file diff --git a/include/mathutil.hpp b/include/mathutil.hpp index bfcb06f..8d1689c 100644 --- a/include/mathutil.hpp +++ b/include/mathutil.hpp @@ -3,9 +3,11 @@ namespace math { template + requires std::integral || std::floating_point class Util { public: static inline Type absolute_distance(Type a, Type b) noexcept { return a > b ? a - b : b - a; } }; + } diff --git a/include/stringutil.hpp b/include/stringutil.hpp index 26080e5..84725de 100644 --- a/include/stringutil.hpp +++ b/include/stringutil.hpp @@ -10,13 +10,14 @@ namespace stringutil YearDayMonth }; - /// @brief Returns a formatted string as a C++ string. + /// @brief Returns a formatted string as a C++ string. This uses C instead of std::format because std::format bloats the NRO + /// up another whole MB. /// @param format Format of string. /// @param arguments Arguments for string. /// @return Formatted C++ string. std::string get_formatted_string(const char *format, ...); - /// @brief Replaces and sequence of characters in a string. + /// @brief Replaces a sequence of characters in a string. /// @param target Target string. /// @param find Sequence to search for. /// @param replace What to replace the sequence with. diff --git a/include/ui/SlideOutPanel.hpp b/include/ui/SlideOutPanel.hpp index d2a6ab7..f05459a 100644 --- a/include/ui/SlideOutPanel.hpp +++ b/include/ui/SlideOutPanel.hpp @@ -1,4 +1,5 @@ #pragma once +#include "graphics/screen.hpp" #include "sdl.hpp" #include "ui/Element.hpp" #include "ui/Transition.hpp" @@ -113,9 +114,9 @@ namespace ui static inline int sm_targetID{}; /// @brief Returns the target X to open the panel. - inline int get_target_open_x() { return m_side == Side::Left ? 0 : 1280 - m_width; } + inline int get_target_open_x() { return m_side == Side::Left ? 0 : graphics::SCREEN_WIDTH - m_width; } /// @brief Returns the target X to close/hide the panel. - inline int get_target_close_x() { return m_side == Side::Left ? -m_width : 1280; } + inline int get_target_close_x() { return m_side == Side::Left ? -m_width : graphics::SCREEN_WIDTH; } }; } // namespace ui diff --git a/include/ui/Transition.hpp b/include/ui/Transition.hpp index 1a5343c..98ee8c7 100644 --- a/include/ui/Transition.hpp +++ b/include/ui/Transition.hpp @@ -135,12 +135,16 @@ namespace ui /// @brief Scaling from config. static inline double sm_scaling{}; + /// @brief Updates the x coordinate. void update_x_coord() noexcept; + /// @brief Updates the y coordinate. void update_y_coord() noexcept; + /// @brief Updates the width. void update_width() noexcept; + /// @brief Updates the height. void update_height() noexcept; }; } diff --git a/romfs/Sound/MenuCursor.wav b/romfs/Sound/MenuCursor.wav index 2ccb1ebc576323d7e0fb6a9817c5153107008967..9bb80b40e7304376792a1c80b6243d9f4220ce16 100644 GIT binary patch literal 750 zcmY*X&uddb5Z;yw9u(@yYv@TS4Q-03cu+wDfncEtX*^VTZJH3<8q81LE;GBc?2|SG zv5mGRs*kc0V$Yuc66M(_YY3ndRO5~&gH$oyraNfzEUCRWtPQuPw1jf7}ZVZVp z=UdP?pULvgje|m#MYfqJ_-`JW~T>q(flTVwrsw%6$#{<_weyOkMS{e0a_-+cQz zJZl|H&$3Ua??0rIk14_+3mDQ-ARn}G;JqW@M#Rc_wB8^XZz-@MhKLC!@U}60Ru2$$ zv;c&b?+k%eWyG=(heTt?i09@B78A+fGLM!2d{j|2>Lu#S8(<_(oL#a-$bY1XN{hat zj!4IAEHJ;1a;Z|y^II#uD(;jj#p)XS}@3K`o&HgCq9{pca{Q;uOLw*1N literal 2528 zcmai0TW=gS7@Z=JKmrM#c#Zl5sv7ko1PBSJ1d$?DAd#x{H7Jb~sa)D7dzsmp@!ezZ z?96Vm2~7~C5Bw;84(GFHHe0A*Cf@b&`M%@N$M!1UZEtP;^;VL6f9L+!`#&CTyqhG+ zmE^VLy=zHw^?riho5|kp;qK>%sqDP zrs?71Nw#=)yu5g!%E{>Hmu%dgot$30&^#Xvo}|Nexj4RfZd5)V4#uO|vN=BeP04IL z8lTJj?!U0Zx$!#*5+xJjfc}k-7L+`Fwe$EzL_oB6IW-$90gcEoz< z3s#maXQgdSWm^G~m4vY8GszGK*3`xTiLzh}Xljh9r7R21Spm+Pse+|Ixvn*kR7J*k zInf@-gG)IpQ|)k+Fv4=2mmKHOnTP~0z}CkLnISg`+ztQk4QPJfa45F<#0qRAR2&C(kKTF$>}J1X#*0RBeIGd z13)C93RMC?#^R`3(*Fm-{1W#94LzzGJtd7)0fCc1Pzjs>C$v!52@Y3reel9x#!C2s z>!hWQd33QT7Dbb;q%7hhT5+%&H!^b2WM!xXGh#Q16LEg@I8r5UqEZISSs{6eD)K3E z!8P(JItrf@d?E)SOCC}rG^kb}>=JfbkgJ`e!L`mqxQz+XI!9GRa8#pFBzf2)@~L;U zb1kl+cLqq48=a%n2U>F!KSV1>JJ(2a%~4doat&Qlf+jqs1>p~c3!ILKXo+-IXtj7E zLS^xZT=aq*CJ%_g)xyreKcJFsC7s)_QtGb|N8J<|9YPOz1!|x-=B*H2X588EpqC@I zL#xP0_Idw-XjXbqSyARehw31NUxjeQaeCs5LSiJ%7tRqP=|Me#3VEoGs-a~U)F(uX ziJBcpc^!wyh%nOWAu;3zaSZ1WqE(X0WgblupYZz?Ao)uuQelQJCTe1Z6ahdzym4jS zXt&PDtZ^?#1{73!rB3Trc~KvQ#w>Db&5JNf=244fuYHHn!2S={CHFd=S_gai)eNCS zB&O=;>}R3jNOfPU%KjBi18dqH#0adR79U#eCF)0C^&KN)>{`EbyHn|13_en!>#Z;7 za=7R3ZtvXN#D7=Y-)w!my|Z=iD*AVK2m2p=x_Rs4&6_uFY<%$O;D@I_?d=~tdU*Zj z=B>?JA12Ac-tCP~DC?`+uP0xka~render(sdl::Texture::Null, 66, 27); + m_headerIcon->render(sdl::Texture::Null, HEADER_X, HEADER_Y); // "JKSV" - sdl::text::render(sdl::Texture::Null, 130, 32, 34, sdl::text::NO_WRAP, colors::WHITE, TITLE_TEXT); + sdl::text::render(sdl::Texture::Null, TITLE_X, TITLE_Y, TITLE_SIZE, sdl::text::NO_WRAP, colors::WHITE, TITLE_TEXT); // Translation info in bottom left. if (m_showTranslationInfo) { - sdl::text::render(sdl::Texture::Null, 8, 680, 14, sdl::text::NO_WRAP, colors::WHITE, m_translationInfo); + sdl::text::render(sdl::Texture::Null, + BUILD_X, + TRANS_Y, + BUILD_SIZE, + sdl::text::NO_WRAP, + colors::WHITE, + m_translationInfo); } // Build date - sdl::text::render(sdl::Texture::Null, 8, 700, 14, sdl::text::NO_WRAP, colors::WHITE, m_buildString); + sdl::text::render(sdl::Texture::Null, BUILD_X, BUILD_Y, BUILD_SIZE, sdl::text::NO_WRAP, colors::WHITE, m_buildString); } void JKSV::exit_services() diff --git a/source/StateManager.cpp b/source/StateManager.cpp index 6a568ad..7060db9 100644 --- a/source/StateManager.cpp +++ b/source/StateManager.cpp @@ -33,6 +33,7 @@ void StateManager::update() for (auto iter = stateVector.begin(); iter < stateVector.end() - 1; iter++) { (*iter)->sub_update(); } { + // Double check to make sure the back has focus. auto &back = stateVector.back(); if (!back->has_focus()) { back->give_focus(); } } diff --git a/source/appstates/BlacklistEditState.cpp b/source/appstates/BlacklistEditState.cpp index 0cc1fab..db1296a 100644 --- a/source/appstates/BlacklistEditState.cpp +++ b/source/appstates/BlacklistEditState.cpp @@ -5,6 +5,7 @@ #include "config/config.hpp" #include "data/data.hpp" #include "error.hpp" +#include "graphics/screen.hpp" #include "input.hpp" // ---- Construction ---- @@ -52,7 +53,7 @@ void BlacklistEditState::load_blacklist() { config::get_blacklisted_titles(m_bla void BlacklistEditState::initialize_menu() { - m_blacklistMenu = std::make_shared(8, 8, 460, 22, 720); + m_blacklistMenu = std::make_shared(8, 8, 460, 22, graphics::SCREEN_HEIGHT); sm_slidePanel->push_new_element(m_blacklistMenu); } diff --git a/source/appstates/DataLoadingState.cpp b/source/appstates/DataLoadingState.cpp index 7255d5c..d174531 100644 --- a/source/appstates/DataLoadingState.cpp +++ b/source/appstates/DataLoadingState.cpp @@ -1,6 +1,7 @@ #include "appstates/DataLoadingState.hpp" #include "graphics/colors.hpp" +#include "graphics/screen.hpp" #include "logging/logger.hpp" namespace @@ -42,7 +43,7 @@ void DataLoadingState::render() const int statusWidth = sdl::text::get_width(BaseTask::FONT_SIZE, status); m_statusX = SCREEN_CENTER - (statusWidth / 2); - sdl::render_rect_fill(sdl::Texture::Null, 0, 0, 1280, 720, colors::CLEAR_COLOR); + sdl::render_rect_fill(sdl::Texture::Null, 0, 0, graphics::SCREEN_WIDTH, graphics::SCREEN_HEIGHT, colors::CLEAR_COLOR); sm_jksvIcon->render(sdl::Texture::Null, ICON_X_COORD, ICON_Y_COORD); sdl::text::render(sdl::Texture::Null, m_statusX, 673, BaseTask::FONT_SIZE, sdl::text::NO_WRAP, colors::WHITE, status); BaseTask::render_loading_glyph(); diff --git a/source/appstates/FadeState.cpp b/source/appstates/FadeState.cpp index f8e242a..51cca3f 100644 --- a/source/appstates/FadeState.cpp +++ b/source/appstates/FadeState.cpp @@ -1,6 +1,7 @@ #include "appstates/FadeState.hpp" #include "StateManager.hpp" +#include "graphics/screen.hpp" #include "logging/logger.hpp" #include "mathutil.hpp" #include "sdl.hpp" @@ -42,7 +43,7 @@ void FadeState::render() const uint32_t rawColor = (m_baseColor.raw & 0xFFFFFF00) | m_alpha; const sdl::Color fadeColor{rawColor}; - sdl::render_rect_fill(sdl::Texture::Null, 0, 0, 1280, 720, fadeColor); + sdl::render_rect_fill(sdl::Texture::Null, 0, 0, graphics::SCREEN_WIDTH, graphics::SCREEN_HEIGHT, fadeColor); } // ---- Private functions ---- diff --git a/source/appstates/FileModeState.cpp b/source/appstates/FileModeState.cpp index 34fa3af..a7e6dbc 100644 --- a/source/appstates/FileModeState.cpp +++ b/source/appstates/FileModeState.cpp @@ -3,6 +3,7 @@ #include "appstates/FileOptionState.hpp" #include "config/config.hpp" #include "graphics/colors.hpp" +#include "graphics/screen.hpp" #include "input.hpp" #include "logging/logger.hpp" #include "mathutil.hpp" @@ -17,7 +18,7 @@ FileModeState::FileModeState(std::string_view mountA, std::string_view mountB, i : m_mountA(mountA) , m_mountB(mountB) , m_journalSize(journalSize) - , m_transition(15, 720, 0, 0, 15, 90, 0, 0, ui::Transition::DEFAULT_THRESHOLD) + , m_transition(15, graphics::SCREEN_HEIGHT, 0, 0, 15, 90, 0, 0, ui::Transition::DEFAULT_THRESHOLD) , m_isSystem(isSystem) , m_allowSystem(config::get_by_key(config::keys::ALLOW_WRITING_TO_SYSTEM)) { @@ -90,7 +91,7 @@ void FileModeState::initialize_static_members() if (sm_frame && sm_renderTarget && sm_controlGuide) { return; } - sm_frame = ui::Frame::create(15, 720, 1250, 555); + sm_frame = ui::Frame::create(15, graphics::SCREEN_HEIGHT, 1250, 555); sm_renderTarget = sdl::TextureManager::load(RENDER_TARGET_NAME, 1234, 538, SDL_TEXTUREACCESS_TARGET); sm_controlGuide = ui::ControlGuide::create(strings::get_by_name(strings::names::CONTROL_GUIDES, 4)); } @@ -137,7 +138,7 @@ void FileModeState::hide_dialog() noexcept { if (!m_transition.in_place()) { return; } sm_controlGuide->reset(); - m_transition.set_target_y(720); + m_transition.set_target_y(graphics::SCREEN_HEIGHT); m_close = true; } @@ -208,7 +209,7 @@ fslib::Directory &FileModeState::get_destination_directory() noexcept { return m void FileModeState::deactivate_state() noexcept { - sm_frame->set_y(720); + sm_frame->set_y(graphics::SCREEN_HEIGHT); fslib::close_file_system(m_mountA); fslib::close_file_system(m_mountB); BaseState::deactivate(); diff --git a/source/appstates/FileOptionState.cpp b/source/appstates/FileOptionState.cpp index de4d661..a4f16fe 100644 --- a/source/appstates/FileOptionState.cpp +++ b/source/appstates/FileOptionState.cpp @@ -134,8 +134,12 @@ void FileOptionState::initialize_static_members() return; } - sm_copyMenu = ui::Menu::create(m_target ? RIGHT_X + 9 : LEFT_X + 9, 253, 234, 20, 720); // Target height is a workaround. - sm_dialog = ui::DialogBox::create(2000, 1000, 32, 32); // Create this off screen at first. + sm_copyMenu = ui::Menu::create(m_target ? RIGHT_X + 9 : LEFT_X + 9, + 253, + 234, + 20, + graphics::SCREEN_HEIGHT); // Target height is a workaround. + sm_dialog = ui::DialogBox::create(2000, 1000, 32, 32); // Create this off screen at first. // This never changes, so... for (int i = 0; const char *menuOption = strings::get_by_name(strings::names::FILEOPTION_MENU, i); i++) diff --git a/source/appstates/MessageState.cpp b/source/appstates/MessageState.cpp index ca646db..f9718e4 100644 --- a/source/appstates/MessageState.cpp +++ b/source/appstates/MessageState.cpp @@ -3,6 +3,7 @@ #include "StateManager.hpp" #include "appstates/FadeState.hpp" #include "graphics/colors.hpp" +#include "graphics/screen.hpp" #include "input.hpp" #include "strings/strings.hpp" @@ -10,7 +11,7 @@ MessageState::MessageState(std::string_view message) : m_message(message) - , m_transition(0, 0, 32, 32, 0, 0, 720, 256, ui::Transition::DEFAULT_THRESHOLD) + , m_transition(0, 0, 32, 32, 0, 0, graphics::SCREEN_HEIGHT, 256, ui::Transition::DEFAULT_THRESHOLD) { MessageState::initialize_static_members(); sm_dialogPop->play(); @@ -38,7 +39,7 @@ void MessageState::render() static constexpr int y = 229; const bool hasFocus = BaseState::has_focus(); - sdl::render_rect_fill(sdl::Texture::Null, 0, 0, 1280, 720, colors::DIM_BACKGROUND); + sdl::render_rect_fill(sdl::Texture::Null, 0, 0, graphics::SCREEN_WIDTH, graphics::SCREEN_HEIGHT, colors::DIM_BACKGROUND); sm_dialog->render(sdl::Texture::Null, hasFocus); if (!m_transition.in_place()) { return; } diff --git a/source/appstates/ProgressState.cpp b/source/appstates/ProgressState.cpp index 2bdc5d4..1e9c384 100644 --- a/source/appstates/ProgressState.cpp +++ b/source/appstates/ProgressState.cpp @@ -2,6 +2,7 @@ #include "appstates/FadeState.hpp" #include "graphics/colors.hpp" +#include "graphics/screen.hpp" #include "input.hpp" #include "sdl.hpp" #include "strings/strings.hpp" @@ -24,7 +25,7 @@ namespace // ---- Construction ---- ProgressState::ProgressState(sys::threadpool::JobFunction function, sys::Task::TaskData taskData) - : m_transition(0, 0, 32, 32, 0, 0, 720, 256, ui::Transition::DEFAULT_THRESHOLD) + : m_transition(0, 0, 32, 32, 0, 0, graphics::SCREEN_HEIGHT, 256, ui::Transition::DEFAULT_THRESHOLD) { initialize_static_members(); m_task = std::make_unique(function, taskData); @@ -59,7 +60,7 @@ void ProgressState::render() static constexpr int RIGHT_EDGE_X = (COORD_BAR_X + SIZE_BAR_WIDTH) - 16; const bool hasFocus = BaseState::has_focus(); - sdl::render_rect_fill(sdl::Texture::Null, 0, 0, 1280, 720, colors::DIM_BACKGROUND); + sdl::render_rect_fill(sdl::Texture::Null, 0, 0, graphics::SCREEN_WIDTH, graphics::SCREEN_HEIGHT, colors::DIM_BACKGROUND); sm_dialog->render(sdl::Texture::Null, hasFocus); BaseTask::render_loading_glyph(); if (!m_transition.in_place()) { return; } diff --git a/source/appstates/SaveCreateState.cpp b/source/appstates/SaveCreateState.cpp index 0471084..d514ce9 100644 --- a/source/appstates/SaveCreateState.cpp +++ b/source/appstates/SaveCreateState.cpp @@ -27,7 +27,7 @@ static bool compare_info(data::TitleInfo *infoA, data::TitleInfo *infoB); SaveCreateState::SaveCreateState(data::User *user, TitleSelectCommon *titleSelect) : m_user(user) , m_titleSelect(titleSelect) - , m_saveMenu(ui::Menu::create(8, 8, 624, 23, 720)) + , m_saveMenu(ui::Menu::create(8, 8, 624, 23, graphics::SCREEN_HEIGHT)) , m_dataStruct(std::make_shared()) { SaveCreateState::initialize_static_members(); diff --git a/source/appstates/SaveImportState.cpp b/source/appstates/SaveImportState.cpp index 60c8e29..2842d4d 100644 --- a/source/appstates/SaveImportState.cpp +++ b/source/appstates/SaveImportState.cpp @@ -53,7 +53,7 @@ void SaveImportState::initialize_static_members() sm_taskData = std::make_shared(); - sm_saveMenu = ui::Menu::create(8, 8, 492, 22, 720); + sm_saveMenu = ui::Menu::create(8, 8, 492, 22, graphics::SCREEN_HEIGHT); sm_slidePanel = ui::SlideOutPanel::create(SIZE_PANEL_WIDTH, ui::SlideOutPanel::Side::Right); sm_slidePanel->push_new_element(sm_saveMenu); diff --git a/source/appstates/TaskState.cpp b/source/appstates/TaskState.cpp index 4906ea9..09bbc6c 100644 --- a/source/appstates/TaskState.cpp +++ b/source/appstates/TaskState.cpp @@ -2,6 +2,7 @@ #include "appstates/FadeState.hpp" #include "graphics/colors.hpp" +#include "graphics/screen.hpp" #include "input.hpp" #include "sdl.hpp" #include "strings/strings.hpp" @@ -28,7 +29,7 @@ void TaskState::render() const std::string status = m_task->get_status(); const int statusX = 640 - (sdl::text::get_width(BaseTask::FONT_SIZE, status.c_str()) / 2); - sdl::render_rect_fill(sdl::Texture::Null, 0, 0, 1280, 720, colors::DIM_BACKGROUND); + sdl::render_rect_fill(sdl::Texture::Null, 0, 0, graphics::SCREEN_WIDTH, graphics::SCREEN_HEIGHT, colors::DIM_BACKGROUND); sdl::text::render(sdl::Texture::Null, statusX, 351, BaseTask::FONT_SIZE, sdl::text::NO_WRAP, colors::WHITE, status); BaseTask::render_loading_glyph(); diff --git a/source/appstates/TitleOptionState.cpp b/source/appstates/TitleOptionState.cpp index a0d2af0..238bed0 100644 --- a/source/appstates/TitleOptionState.cpp +++ b/source/appstates/TitleOptionState.cpp @@ -121,7 +121,7 @@ void TitleOptionState::initialize_static_members() if (sm_slidePanel && sm_titleOptionMenu) { return; } sm_slidePanel = std::make_unique(480, ui::SlideOutPanel::Side::Right); - sm_titleOptionMenu = std::make_shared(8, 8, 460, 22, 720); + sm_titleOptionMenu = std::make_shared(8, 8, 460, 22, graphics::SCREEN_HEIGHT); for (int i = 0; const char *option = strings::get_by_name(strings::names::TITLEOPTION, i); i++) { diff --git a/source/appstates/UserOptionState.cpp b/source/appstates/UserOptionState.cpp index 1b46a3c..3c6efcc 100644 --- a/source/appstates/UserOptionState.cpp +++ b/source/appstates/UserOptionState.cpp @@ -39,7 +39,7 @@ namespace UserOptionState::UserOptionState(data::User *user, TitleSelectCommon *titleSelect) : m_user(user) , m_titleSelect(titleSelect) - , m_userOptionMenu(ui::Menu::create(8, 8, 460, 22, 720)) + , m_userOptionMenu(ui::Menu::create(8, 8, 460, 22, graphics::SCREEN_HEIGHT)) , m_dataStruct(std::make_shared()) { UserOptionState::create_menu_panel(); diff --git a/source/data/User.cpp b/source/data/User.cpp index 0a75b6d..9839fa7 100644 --- a/source/data/User.cpp +++ b/source/data/User.cpp @@ -322,18 +322,10 @@ static bool sort_user_data(const data::UserDataEntry &entryA, const data::UserDa break; // Most played. - case 1: - { - return playStatsA.playtime > playStatsB.playtime; - } - break; + case 1: return playStatsA.playtime > playStatsB.playtime; break; // Last played. - case 2: - { - return playStatsA.last_timestamp_user > playStatsB.last_timestamp_user; - } - break; + case 2: return playStatsA.last_timestamp_user > playStatsB.last_timestamp_user; break; } return false; } diff --git a/source/fs/MiniUnzip.cpp b/source/fs/MiniUnzip.cpp index fb47add..7aa3bd0 100644 --- a/source/fs/MiniUnzip.cpp +++ b/source/fs/MiniUnzip.cpp @@ -3,10 +3,14 @@ #include "error.hpp" #include "logging/logger.hpp" +// ---- Construction ---- + fs::MiniUnzip::MiniUnzip(const fslib::Path &path) { MiniUnzip::open(path); } fs::MiniUnzip::~MiniUnzip() { MiniUnzip::close(); } +// ---- Public functions ---- + bool fs::MiniUnzip::is_open() const noexcept { return m_isOpen; } bool fs::MiniUnzip::open(const fslib::Path &path) diff --git a/source/fs/MiniZip.cpp b/source/fs/MiniZip.cpp index 9e4f8b8..396aede 100644 --- a/source/fs/MiniZip.cpp +++ b/source/fs/MiniZip.cpp @@ -9,6 +9,8 @@ // Definition at bottom. static zip_fileinfo create_zip_file_info(); +// ---- Construction ---- + fs::MiniZip::MiniZip(const fslib::Path &path) : m_level(config::get_by_key(config::keys::ZIP_COMPRESSION_LEVEL)) { @@ -17,6 +19,8 @@ fs::MiniZip::MiniZip(const fslib::Path &path) fs::MiniZip::~MiniZip() { MiniZip::close(); } +// ---- Public functions ---- + bool fs::MiniZip::is_open() const noexcept { return m_isOpen; } bool fs::MiniZip::open(const fslib::Path &path) @@ -64,6 +68,8 @@ bool fs::MiniZip::write(const void *buffer, size_t dataSize) return zipWriteInFileInZip(m_zip, buffer, dataSize) == ZIP_OK; } +// ---- Static functions ---- + static zip_fileinfo create_zip_file_info() { const std::time_t currentTime = std::time(nullptr); diff --git a/source/fs/ScopedSaveMount.cpp b/source/fs/ScopedSaveMount.cpp index cc11b46..9a9b370 100644 --- a/source/fs/ScopedSaveMount.cpp +++ b/source/fs/ScopedSaveMount.cpp @@ -3,6 +3,8 @@ #include "error.hpp" #include "fslib.hpp" +// ---- Construction ---- + fs::ScopedSaveMount::ScopedSaveMount(std::string_view mount, const FsSaveDataInfo *saveInfo, bool log) : m_mountPoint(mount) , m_log(log) @@ -11,7 +13,17 @@ fs::ScopedSaveMount::ScopedSaveMount(std::string_view mount, const FsSaveDataInf else { m_isOpen = fslib::open_save_data_with_save_info(m_mountPoint, *saveInfo); } } -fs::ScopedSaveMount::ScopedSaveMount(ScopedSaveMount &&scopedSaveMount) noexcept { *this = std::move(scopedSaveMount); } +fs::ScopedSaveMount::~ScopedSaveMount() +{ + if (m_log) { error::fslib(fslib::close_file_system(m_mountPoint)); } + else { fslib::close_file_system(m_mountPoint); } +} + +// ---- Move constructor & operator ---- + +fs::ScopedSaveMount::ScopedSaveMount(ScopedSaveMount &&scopedSaveMount) noexcept + : m_mountPoint(std::move(scopedSaveMount.m_mountPoint)) + , m_isOpen(scopedSaveMount.m_isOpen) {}; fs::ScopedSaveMount &fs::ScopedSaveMount::operator=(ScopedSaveMount &&scopedSaveMount) noexcept { @@ -21,10 +33,6 @@ fs::ScopedSaveMount &fs::ScopedSaveMount::operator=(ScopedSaveMount &&scopedSave return *this; } -fs::ScopedSaveMount::~ScopedSaveMount() -{ - if (m_log) { error::fslib(fslib::close_file_system(m_mountPoint)); } - else { fslib::close_file_system(m_mountPoint); } -} +// ---- Public functions ---- bool fs::ScopedSaveMount::is_open() const noexcept { return m_isOpen; } diff --git a/source/gfxutil.cpp b/source/gfxutil.cpp index 6d6d68e..30da592 100644 --- a/source/gfxutil.cpp +++ b/source/gfxutil.cpp @@ -15,7 +15,7 @@ sdl::SharedTexture gfxutil::create_generic_icon(std::string_view text, sdl::Color foreground) { // Create base icon texture. - sdl::SharedTexture icon = sdl::TextureManager::load(text, 256, 256, SDL_TEXTUREACCESS_TARGET); + sdl::SharedTexture icon = sdl::TextureManager::load(text, SIZE_ICON_WIDTH, SIZE_ICON_HEIGHT, SDL_TEXTUREACCESS_TARGET); // Get the centered X and Y coordinates. const int textX = (SIZE_ICON_WIDTH / 2) - (sdl::text::get_width(fontSize, text) / 2); diff --git a/source/remote/Form.cpp b/source/remote/Form.cpp index 67de1e6..ce1f650 100644 --- a/source/remote/Form.cpp +++ b/source/remote/Form.cpp @@ -2,6 +2,9 @@ #include #include +#include + +// ---- Public functions ---- remote::Form &remote::Form::append_parameter(std::string_view param, std::string_view value) noexcept { @@ -12,12 +15,19 @@ remote::Form &remote::Form::append_parameter(std::string_view param, std::string if (m_offset > 0 && m_formBuffer[m_offset - 1] != '&') { m_formBuffer[m_offset++] = '&'; } - std::copy(param.begin(), param.end(), &m_formBuffer[m_offset]); + // Append the parameter first. + size_t remainingLength = SIZE_FORM_BUFFER - m_offset; + std::span bufferSpan{&m_formBuffer[m_offset], remainingLength}; + std::copy(param.begin(), param.end(), bufferSpan.begin()); m_offset += paramLength; + // Add the = m_formBuffer[m_offset++] = '='; - std::copy(value.begin(), value.end(), &m_formBuffer[m_offset]); + // Recalc, append value. + remainingLength = SIZE_FORM_BUFFER - m_offset; + bufferSpan = std::span{&m_formBuffer[m_offset], remainingLength}; + std::copy(value.begin(), value.end(), bufferSpan.begin()); m_offset += valueLength; return *this; diff --git a/source/remote/GoogleDrive.cpp b/source/remote/GoogleDrive.cpp index cf6fa08..6faff8a 100644 --- a/source/remote/GoogleDrive.cpp +++ b/source/remote/GoogleDrive.cpp @@ -45,6 +45,8 @@ namespace constexpr const char *MIME_TYPE_DIRECTORY = "application/vnd.google-apps.folder"; } // namespace +// ---- Construction ---- + remote::GoogleDrive::GoogleDrive() : Storage("[GD]", true) { @@ -89,6 +91,8 @@ remote::GoogleDrive::GoogleDrive() else if (GoogleDrive::get_root_id() && GoogleDrive::request_listing()) { m_isInitialized = true; } } +// ---- Public functions ---- + bool remote::GoogleDrive::create_directory(std::string_view name) { if (!GoogleDrive::token_is_valid() && !GoogleDrive::refresh_token()) { return false; } @@ -519,6 +523,8 @@ bool remote::GoogleDrive::poll_sign_in(std::string_view code) return true; } +// ---- Private functions ---- + bool remote::GoogleDrive::get_root_id() { // This is the only place this is used. V3 of the API doesn't allow you to retrieve this for some reason? diff --git a/source/remote/Item.cpp b/source/remote/Item.cpp index b657299..416f1cf 100644 --- a/source/remote/Item.cpp +++ b/source/remote/Item.cpp @@ -1,6 +1,6 @@ #include "remote/Item.hpp" -#include "logging/logger.hpp" +// ---- Construction ---- remote::Item::Item(std::string_view name, std::string_view id, std::string_view parent, size_t size, bool directory) : m_name{name} @@ -9,6 +9,8 @@ remote::Item::Item(std::string_view name, std::string_view id, std::string_view , m_size{size} , m_isDirectory{directory} {}; +// ---- Public functions ---- + std::string_view remote::Item::get_name() const noexcept { return m_name; } std::string_view remote::Item::get_id() const noexcept { return m_id; } diff --git a/source/remote/Storage.cpp b/source/remote/Storage.cpp index 3c32107..5ae4176 100644 --- a/source/remote/Storage.cpp +++ b/source/remote/Storage.cpp @@ -5,12 +5,15 @@ #include #include -// Declarations here. Defined at bottom. +// ---- Construction ---- + remote::Storage::Storage(std::string_view prefix, bool supportsUtf8) : m_curl(curl::new_handle()) , m_utf8Paths(supportsUtf8) , m_prefix(prefix) {}; +// ---- Public functions ---- + bool remote::Storage::is_initialized() const noexcept { return m_isInitialized; } bool remote::Storage::directory_exists(std::string_view name) const noexcept @@ -82,6 +85,8 @@ bool remote::Storage::supports_utf8() const noexcept { return m_utf8Paths; } std::string_view remote::Storage::get_prefix() const noexcept { return m_prefix; } +// ---- Private functions ---- + remote::Storage::List::iterator remote::Storage::find_directory_by_name(std::string_view name) noexcept { auto is_match = [&](const Item &item) noexcept diff --git a/source/remote/URL.cpp b/source/remote/URL.cpp index b2869dc..b410a12 100644 --- a/source/remote/URL.cpp +++ b/source/remote/URL.cpp @@ -1,16 +1,28 @@ #include "remote/URL.hpp" #include +#include + +// ---- Construction ---- remote::URL::URL(std::string_view base) noexcept { const size_t baseLength = base.length(); if (baseLength >= SIZE_URL_BUFFER) { return; } - std::copy(base.begin(), base.end(), &m_urlBuffer[m_offset]); - m_offset += base.length(); + // Create span for this stuff since it's cleaner. + const std::span bufferSpan{m_urlBuffer, SIZE_URL_BUFFER}; + + // Fill and copy. + std::fill(bufferSpan.begin(), bufferSpan.end(), 0x00); + std::copy(base.begin(), base.end(), bufferSpan.begin()); + + // Update the offset to match. + m_offset = base.length(); } +// ---- Public functions ---- + remote::URL &remote::URL::append_path(std::string_view path) noexcept { if (path.empty()) { return *this; } @@ -18,9 +30,16 @@ remote::URL &remote::URL::append_path(std::string_view path) noexcept const size_t pathLength = path.length(); if (m_offset + pathLength >= SIZE_URL_BUFFER) { return *this; } - if (m_urlBuffer[m_offset - 1] != '/' && path.front() != '/') { m_urlBuffer[m_offset++] = '/'; } + // Gonna use string view to compare this. + const std::string_view bufferView{m_urlBuffer}; + if (bufferView.back() != '/' && path.front() != '/') { m_urlBuffer[m_offset++] = '/'; } - std::copy(path.begin(), path.end(), &m_urlBuffer[m_offset]); + // Gonna use span to copy. + const size_t remainingSpace = SIZE_URL_BUFFER - m_offset; + const std::span bufferSpan{&m_urlBuffer[m_offset], remainingSpace}; + std::copy(path.begin(), path.end(), bufferSpan.begin()); + + // Update offset. m_offset += pathLength; return *this; @@ -33,16 +52,24 @@ remote::URL &remote::URL::append_parameter(std::string_view param, std::string_v const size_t endLength = m_offset + paramLength + valueLength + 2; if (endLength >= SIZE_URL_BUFFER) { return *this; } + // Going to assume if a ? isn't found, we need to append it. const char *find = std::char_traits::find(m_urlBuffer, m_offset, '?'); if (!find) { m_urlBuffer[m_offset++] = '?'; } else { m_urlBuffer[m_offset++] = '&'; } - std::copy(param.begin(), param.end(), &m_urlBuffer[m_offset]); + // Append the parameter first. + size_t remainingLength = SIZE_URL_BUFFER - m_offset; + std::span bufferSpan{&m_urlBuffer[m_offset], remainingLength}; + std::copy(param.begin(), param.end(), bufferSpan.begin()); m_offset += paramLength; + // Equals. m_urlBuffer[m_offset++] = '='; - std::copy(value.begin(), value.end(), &m_urlBuffer[m_offset]); + // Recalc and align. + remainingLength = SIZE_URL_BUFFER - m_offset; + bufferSpan = std::span{&m_urlBuffer[m_offset], remainingLength}; + std::copy(value.begin(), value.end(), bufferSpan.begin()); m_offset += valueLength; return *this; @@ -51,7 +78,13 @@ remote::URL &remote::URL::append_parameter(std::string_view param, std::string_v remote::URL &remote::URL::append_slash() noexcept { if (m_offset >= SIZE_URL_BUFFER) { return *this; } - else if (m_urlBuffer[m_offset - 1] != '/') { m_urlBuffer[m_offset++] = '/'; } + + // Do a quick check to ensure only one. + std::string_view urlView{m_urlBuffer}; + if (urlView.back() == '/') { return *this; } + + // Now we append it. + m_urlBuffer[m_offset++] = '/'; return *this; } diff --git a/source/remote/WebDav.cpp b/source/remote/WebDav.cpp index be39d36..c6f081e 100644 --- a/source/remote/WebDav.cpp +++ b/source/remote/WebDav.cpp @@ -31,6 +31,8 @@ static std::string ensure_valid_dir_path(std::string_view parent); /// @note This seemed like a better alternative than relying on servers having displayname. static std::string slice_name_from_href(curl::Handle &handle, std::string_view href); +// ---- Construction ---- + remote::WebDav::WebDav() : Storage("[WD]") { @@ -300,6 +302,8 @@ bool remote::WebDav::rename_item(remote::Item *item, std::string_view newName) return false; } +// ---- Private functions ---- + void remote::WebDav::append_credentials() { if (!m_username.empty()) { curl::set_option(m_curl, CURLOPT_USERNAME, m_username.c_str()); } @@ -392,6 +396,8 @@ bool remote::WebDav::process_listing(std::string_view xml) return true; } +// ---- Static functions ---- + static tinyxml2::XMLElement *get_element_by_name(tinyxml2::XMLElement *parent, std::string_view name) { tinyxml2::XMLElement *current = parent->FirstChildElement(); diff --git a/source/stringutil.cpp b/source/stringutil.cpp index 6fbce8f..ee50033 100644 --- a/source/stringutil.cpp +++ b/source/stringutil.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -92,7 +93,9 @@ bool stringutil::sanitize_string_for_path(const char *stringIn, char *stringOut, const auto &[tablePoint, replacement] = *replace; const size_t replacementLength = replacement.length(); - std::copy(replacement.data(), replacement.data() + replacementLength, &stringOut[outOffset]); + const size_t remainingSize = stringOutSize - outOffset; + const std::span stringSpan{&stringOut[outOffset], remainingSize}; + std::copy(replacement.data(), replacement.data() + replacementLength, stringSpan.begin()); outOffset += replacementLength; i += count; @@ -104,7 +107,11 @@ bool stringutil::sanitize_string_for_path(const char *stringIn, char *stringOut, if (asciiCheck) { return false; } // Just copy it over. - std::copy(&stringIn[i], &stringIn[i] + count, &stringOut[outOffset]); + const size_t remainingSpace = stringOutSize - outOffset; + const std::span stringSpan{&stringIn[i], static_cast(count)}; + const std::span stringOutSpan{&stringOut[outOffset], remainingSpace}; + std::copy(stringSpan.begin(), stringSpan.end(), stringOutSpan.begin()); + outOffset += count; i += count; } diff --git a/source/sys/OpTimer.cpp b/source/sys/OpTimer.cpp index fd80792..888d729 100644 --- a/source/sys/OpTimer.cpp +++ b/source/sys/OpTimer.cpp @@ -2,6 +2,8 @@ #include "logging/logger.hpp" +// ---- Construction ---- + sys::OpTimer::OpTimer(const std::source_location &location) noexcept : m_location(location) , m_begin(std::chrono::high_resolution_clock::now()) {}; @@ -15,6 +17,8 @@ sys::OpTimer::~OpTimer() noexcept logger::log("%s took %lli microseconds.", functionName.data(), diff.count()); } +// ---- Public functions ---- + std::string_view sys::OpTimer::get_function_name() const noexcept { std::string_view function = m_location.function_name(); diff --git a/source/sys/ProgressTask.cpp b/source/sys/ProgressTask.cpp index 00a9d33..6a420e5 100644 --- a/source/sys/ProgressTask.cpp +++ b/source/sys/ProgressTask.cpp @@ -2,6 +2,8 @@ #include "logging/logger.hpp" +// ---- Construction ---- + sys::ProgressTask::ProgressTask(sys::threadpool::JobFunction function, sys::ProgressTask::TaskData taskData) : Task() { @@ -9,6 +11,8 @@ sys::ProgressTask::ProgressTask(sys::threadpool::JobFunction function, sys::Prog threadpool::push_job(function, taskData); } +// ---- Public functions ---- + void sys::ProgressTask::reset(double goal) noexcept { m_current = 0; diff --git a/source/sys/Task.cpp b/source/sys/Task.cpp index f90ca3f..fd8586f 100644 --- a/source/sys/Task.cpp +++ b/source/sys/Task.cpp @@ -2,6 +2,8 @@ #include "logging/logger.hpp" +// ---- Construction ---- + sys::Task::Task() : m_isRunning(true) {}; @@ -12,6 +14,8 @@ sys::Task::Task(sys::threadpool::JobFunction function, sys::Task::TaskData taskD sys::threadpool::push_job(function, taskData); } +// ---- Public functions ---- + bool sys::Task::is_running() const noexcept { return m_isRunning; } void sys::Task::complete() noexcept { m_isRunning = false; } diff --git a/source/sys/Timer.cpp b/source/sys/Timer.cpp index a7078c6..8144c35 100644 --- a/source/sys/Timer.cpp +++ b/source/sys/Timer.cpp @@ -4,8 +4,12 @@ #include +// ---- Construction ---- + sys::Timer::Timer(uint64_t triggerTicks) noexcept { Timer::start(triggerTicks); } +// ---- Public functions ---- + void sys::Timer::start(uint64_t triggerTicks) noexcept { m_triggerTicks = triggerTicks; diff --git a/source/ui/BoundingBox.cpp b/source/ui/BoundingBox.cpp index 2fb6273..ed4ec7b 100644 --- a/source/ui/BoundingBox.cpp +++ b/source/ui/BoundingBox.cpp @@ -9,6 +9,8 @@ namespace constexpr int RECT_HEIGHT = 4; } +// ---- Construction ---- + ui::BoundingBox::BoundingBox(int x, int y, int width, int height) : m_x(x) , m_y(y) @@ -18,6 +20,8 @@ ui::BoundingBox::BoundingBox(int x, int y, int width, int height) BoundingBox::initialize_static_members(); } +// ---- Public functions ---- + void ui::BoundingBox::update(bool hasFocus) { m_colorMod.update(); } void ui::BoundingBox::render(sdl::SharedTexture &target, bool hasFocus) @@ -54,6 +58,8 @@ void ui::BoundingBox::set_width(int width) noexcept { m_width = width; } void ui::BoundingBox::set_height(int height) noexcept { m_height = height; } +// ---- Private functions ---- + void ui::BoundingBox::initialize_static_members() { if (sm_corners) { return; } diff --git a/source/ui/ColorMod.cpp b/source/ui/ColorMod.cpp index 5c4e5d5..1da05b0 100644 --- a/source/ui/ColorMod.cpp +++ b/source/ui/ColorMod.cpp @@ -1,5 +1,7 @@ #include "ui/ColorMod.hpp" +// ---- Public functions ---- + void ui::ColorMod::update() noexcept { const bool changeDown = m_direction && ((m_colorMod += 6) >= 0x72); diff --git a/source/ui/ControlGuide.cpp b/source/ui/ControlGuide.cpp index beb95af..48d05ad 100644 --- a/source/ui/ControlGuide.cpp +++ b/source/ui/ControlGuide.cpp @@ -1,18 +1,35 @@ #include "ui/ControlGuide.hpp" #include "graphics/colors.hpp" +#include "graphics/screen.hpp" #include "logging/logger.hpp" +namespace +{ + /// @brief This is the X coordinate used to calculate where the guide should be. + constexpr int GUIDE_X_OFFSET = 1220; + + /// @brief This is the font size used for the guides. + constexpr int GUIDE_TEXT_SIZE = 24; + + /// @brief This is the constant Y of the transition. + constexpr int TRANS_Y = 662; +} + +// ---- Construction ---- + ui::ControlGuide::ControlGuide(const char *guide) : m_guide(guide) - , m_textWidth(sdl::text::get_width(23, m_guide)) - , m_targetX(1220 - (m_textWidth + 24)) - , m_guideWidth(1280 - m_targetX) - , m_transition(1280, 662, 0, 0, m_targetX, 662, 0, 0, ui::Transition::DEFAULT_THRESHOLD) + , m_textWidth(sdl::text::get_width(GUIDE_TEXT_SIZE, m_guide)) + , m_targetX(GUIDE_X_OFFSET - (m_textWidth + 24)) + , m_guideWidth(graphics::SCREEN_WIDTH - m_targetX) + , m_transition(graphics::SCREEN_WIDTH, TRANS_Y, 0, 0, m_targetX, TRANS_Y, 0, 0, ui::Transition::DEFAULT_THRESHOLD) { ui::ControlGuide::initialize_static_members(); } +// ---- Public functions ---- + void ui::ControlGuide::update(bool hasFocus) { m_transition.update(); @@ -25,21 +42,41 @@ void ui::ControlGuide::update(bool hasFocus) void ui::ControlGuide::sub_update() { const int targetX = m_transition.get_target_x(); - if (targetX != 1280) { m_transition.set_target_x(1280); } + if (targetX != graphics::SCREEN_WIDTH) { m_transition.set_target_x(graphics::SCREEN_WIDTH); } m_transition.update(); } void ui::ControlGuide::render(sdl::SharedTexture &target, bool hasFocus) { + static constexpr int RECT_OFFSET_X = 16; + static constexpr int RECT_HEIGHT = 48; + + static constexpr int TEXT_OFFSET_X = 24; + static constexpr int TEXT_OFFSET_Y = 10; + static constexpr int TEXT_FONT_SIZE = 24; + const int guideX = m_transition.get_x(); const int guideY = m_transition.get_y(); sm_controlCap->render(sdl::Texture::Null, guideX, guideY); - sdl::render_rect_fill(sdl::Texture::Null, guideX + 16, guideY, m_guideWidth - 16, 48, colors::GUIDE_COLOR); - sdl::text::render(sdl::Texture::Null, guideX + 24, guideY + 10, 23, sdl::text::NO_WRAP, colors::WHITE, m_guide); + sdl::render_rect_fill(sdl::Texture::Null, + guideX + RECT_OFFSET_X, + guideY, + m_guideWidth - RECT_OFFSET_X, + RECT_HEIGHT, + colors::GUIDE_COLOR); + sdl::text::render(sdl::Texture::Null, + guideX + TEXT_OFFSET_X, + guideY + TEXT_OFFSET_Y, + TEXT_FONT_SIZE, + sdl::text::NO_WRAP, + colors::WHITE, + m_guide); } +// ---- Private functions ---- + void ui::ControlGuide::initialize_static_members() { static constexpr std::string_view NAME_CAP = "ControlGuideCap"; @@ -51,6 +88,6 @@ void ui::ControlGuide::initialize_static_members() void ui::ControlGuide::reset() noexcept { - m_transition.set_target_x(1280); - m_transition.set_x(1280); + m_transition.set_target_x(graphics::SCREEN_WIDTH); + m_transition.set_x(graphics::SCREEN_WIDTH); } diff --git a/source/ui/DialogBox.cpp b/source/ui/DialogBox.cpp index 541eed2..7396623 100644 --- a/source/ui/DialogBox.cpp +++ b/source/ui/DialogBox.cpp @@ -8,6 +8,8 @@ namespace constexpr int CORNER_HEIGHT = 16; } +// ---- Construction ---- + ui::DialogBox::DialogBox(int x, int y, int width, int height, ui::DialogBox::Type type) : m_x(x) , m_y(y) @@ -18,6 +20,8 @@ ui::DialogBox::DialogBox(int x, int y, int width, int height, ui::DialogBox::Typ ui::DialogBox::initialize_static_members(); } +// ---- Public functions ---- + void ui::DialogBox::render(sdl::SharedTexture &target, bool hasFocus) { const bool darkDialog = m_type == DialogBox::Type::Dark; @@ -70,6 +74,8 @@ void ui::DialogBox::set_from_transition(ui::Transition &transition, bool centere m_height = height; } +// ---- Private functions ---- + void ui::DialogBox::initialize_static_members() { if (sm_darkCorners && sm_lightCorners) { return; } diff --git a/source/ui/Frame.cpp b/source/ui/Frame.cpp index 7577551..8a30954 100644 --- a/source/ui/Frame.cpp +++ b/source/ui/Frame.cpp @@ -2,6 +2,8 @@ #include "graphics/colors.hpp" +// ---- Construction ---- + ui::Frame::Frame(int x, int y, int width, int height) : m_x(x) , m_y(y) @@ -11,6 +13,8 @@ ui::Frame::Frame(int x, int y, int width, int height) Frame::initialize_static_members(); } +// ---- Public functions ---- + void ui::Frame::render(sdl::SharedTexture &target, bool hasFocus) { // This is the size of one of the "tiles" of the frame. @@ -59,6 +63,8 @@ void ui::Frame::set_from_transition(const ui::Transition &transition, bool cente m_height = height; } +// ---- Private functions ---- + void ui::Frame::initialize_static_members() { static constexpr std::string_view FRAME_NAME = "FrameCorners"; diff --git a/source/ui/IconMenu.cpp b/source/ui/IconMenu.cpp index 4d9880c..4975c3d 100644 --- a/source/ui/IconMenu.cpp +++ b/source/ui/IconMenu.cpp @@ -11,6 +11,8 @@ namespace constexpr int BOUND_HEIGHT = 146; } +// ---- Construction ---- + ui::IconMenu::IconMenu(int x, int y, int renderTargetHeight) : Menu(x, y, 152, 84, renderTargetHeight) { @@ -20,6 +22,8 @@ ui::IconMenu::IconMenu(int x, int y, int renderTargetHeight) m_optionHeight = 144; } +// ---- Public functions ---- + void ui::IconMenu::update(bool hasFocus) { Menu::update(hasFocus); } void ui::IconMenu::render(sdl::SharedTexture &target, bool hasFocus) diff --git a/source/ui/Menu.cpp b/source/ui/Menu.cpp index a929368..4a6128e 100644 --- a/source/ui/Menu.cpp +++ b/source/ui/Menu.cpp @@ -8,6 +8,8 @@ #include +// ---- Construction ---- + ui::Menu::Menu(int x, int y, int width, int fontSize, int renderTargetHeight) : m_x(x) , m_y(y) @@ -23,6 +25,8 @@ ui::Menu::Menu(int x, int y, int width, int fontSize, int renderTargetHeight) Menu::initialize_sounds(); } +// ---- Public functions ---- + void ui::Menu::update(bool hasFocus) { if (m_options.empty()) { return; } @@ -116,6 +120,8 @@ bool ui::Menu::is_empty() const noexcept { return m_options.empty(); } void ui::Menu::play_sound() noexcept { sm_cursor->play(); } +// ---- Private functions ---- + void ui::Menu::calculate_alignments() noexcept { m_optionHeight = std::floor(static_cast(m_fontSize) * 1.8f); diff --git a/source/ui/PopMessage.cpp b/source/ui/PopMessage.cpp index 9984bad..a4f40e8 100644 --- a/source/ui/PopMessage.cpp +++ b/source/ui/PopMessage.cpp @@ -2,20 +2,22 @@ #include "config/config.hpp" #include "graphics/colors.hpp" +#include "graphics/screen.hpp" #include "mathutil.hpp" #include "sdl.hpp" namespace { constexpr int START_X = 624; - constexpr double START_Y = 720; constexpr int START_WIDTH = 20; constexpr int PERMA_HEIGHT = 48; constexpr int TRANSITION_THRESHOLD = 2; // This is used so the easing on opening doesn't look so odd. } +// ---- Construction ---- + ui::PopMessage::PopMessage(int ticks, std::string_view message) - : m_transition(START_X, START_Y, START_WIDTH, PERMA_HEIGHT, 0, 0, 0, 0, TRANSITION_THRESHOLD) + : m_transition(START_X, graphics::SCREEN_HEIGHT, START_WIDTH, PERMA_HEIGHT, 0, 0, 0, 0, TRANSITION_THRESHOLD) , m_ticks(ticks) , m_message(message) { @@ -23,13 +25,15 @@ ui::PopMessage::PopMessage(int ticks, std::string_view message) } ui::PopMessage::PopMessage(int ticks, std::string &message) - : m_transition(START_X, START_Y, START_WIDTH, PERMA_HEIGHT, 0, 0, 0, 0, TRANSITION_THRESHOLD) + : m_transition(START_X, graphics::SCREEN_HEIGHT, START_WIDTH, PERMA_HEIGHT, 0, 0, 0, 0, TRANSITION_THRESHOLD) , m_ticks(ticks) , m_message(std::move(message)) { PopMessage::initialize_static_members(); } +// ---- Public functions ---- + void ui::PopMessage::update(double targetY) { PopMessage::update_y(targetY); @@ -55,6 +59,8 @@ bool ui::PopMessage::finished() const noexcept { return m_finished; } std::string_view ui::PopMessage::get_message() const noexcept { return m_message; } +// ---- Private functions ---- + void ui::PopMessage::initialize_static_members() { static constexpr std::string_view TEX_CAP_NAME = "PopCaps"; @@ -107,7 +113,7 @@ void ui::PopMessage::update_width() noexcept m_transition.update_width_height(); - if (m_close && m_transition.in_place_width_height()) { m_transition.set_target_y(720); } + if (m_close && m_transition.in_place_width_height()) { m_transition.set_target_y(graphics::SCREEN_HEIGHT); } } void ui::PopMessage::render_container() noexcept diff --git a/source/ui/PopMessageManager.cpp b/source/ui/PopMessageManager.cpp index c1d296c..b9b2a69 100644 --- a/source/ui/PopMessageManager.cpp +++ b/source/ui/PopMessageManager.cpp @@ -8,8 +8,12 @@ #include +// ---- Construction ---- + ui::PopMessageManager::PopMessageManager() { PopMessageManager::initialize_pop_sound(); } +// ---- Public functions ---- + void ui::PopMessageManager::update() { static constexpr double COORD_INIT_Y = 594.0f; @@ -110,6 +114,8 @@ void ui::PopMessageManager::push_message(int displayTicks, std::string &message) popSound->play(); } +// ---- Private functions ---- + void ui::PopMessageManager::initialize_pop_sound() { static constexpr std::string_view POP_NAME = "PopSound"; diff --git a/source/ui/SlideOutPanel.cpp b/source/ui/SlideOutPanel.cpp index 25fffeb..398ed7e 100644 --- a/source/ui/SlideOutPanel.cpp +++ b/source/ui/SlideOutPanel.cpp @@ -2,21 +2,19 @@ #include "config/config.hpp" #include "graphics/colors.hpp" +#include "graphics/screen.hpp" #include "mathutil.hpp" #include #include -namespace -{ - constexpr int SCREEN_WIDTH = 1280; -} +// ---- Construction ---- ui::SlideOutPanel::SlideOutPanel(int width, Side side) : m_width(width) - , m_targetX(side == Side::Left ? 0.0f : static_cast(SCREEN_WIDTH) - m_width) + , m_targetX(side == Side::Left ? 0.0f : static_cast(graphics::SCREEN_WIDTH) - m_width) , m_side(side) - , m_transition(m_side == Side::Left ? -m_width : SCREEN_WIDTH, + , m_transition(m_side == Side::Left ? -m_width : graphics::SCREEN_WIDTH, 0, 0, 0, @@ -25,8 +23,12 @@ ui::SlideOutPanel::SlideOutPanel(int width, Side side) 0, 0, ui::Transition::DEFAULT_THRESHOLD) - , m_renderTarget( - sdl::TextureManager::load("PANEL_" + std::to_string(sm_targetID++), m_width, 720, SDL_TEXTUREACCESS_TARGET)) {}; + , m_renderTarget(sdl::TextureManager::load("PANEL_" + std::to_string(sm_targetID++), + m_width, + graphics::SCREEN_HEIGHT, + SDL_TEXTUREACCESS_TARGET)) {}; + +// ---- Public functions ---- void ui::SlideOutPanel::update(bool hasFocus) { diff --git a/source/ui/TextScroll.cpp b/source/ui/TextScroll.cpp index 72eff43..65dca74 100644 --- a/source/ui/TextScroll.cpp +++ b/source/ui/TextScroll.cpp @@ -13,6 +13,8 @@ namespace int TARGET_ID{}; } // namespace +// ---- Construction ---- + ui::TextScroll::TextScroll(std::string_view text, int x, int y, @@ -39,6 +41,8 @@ ui::TextScroll::TextScroll(std::string &text, TextScroll::initialize(text, x, y, width, height, fontSize, textColor, clearColor, center); } +// ---- Public functions ---- + void ui::TextScroll::initialize(std::string_view text, int x, int y, diff --git a/source/ui/TitleTile.cpp b/source/ui/TitleTile.cpp index 4aa72f6..6f10a05 100644 --- a/source/ui/TitleTile.cpp +++ b/source/ui/TitleTile.cpp @@ -9,6 +9,8 @@ namespace constexpr int SELECTED_WIDTH_HEIGHT = 176; } +// ---- Construction ---- + ui::TitleTile::TitleTile(bool isFavorite, int index, sdl::SharedTexture icon) : m_transition(0, 0, @@ -23,6 +25,8 @@ ui::TitleTile::TitleTile(bool isFavorite, int index, sdl::SharedTexture icon) , m_index(index) , m_icon(icon) {}; +// ---- Public functions ---- + void ui::TitleTile::update(int selected) { const bool isSelected = selected == m_index; diff --git a/source/ui/TitleView.cpp b/source/ui/TitleView.cpp index e8f41bf..f453868 100644 --- a/source/ui/TitleView.cpp +++ b/source/ui/TitleView.cpp @@ -15,6 +15,8 @@ namespace constexpr int ICON_ROW_SIZE = 7; } +// ---- Construction ---- + ui::TitleView::TitleView(data::User *user) : m_user(user) , m_transition(0, UPPER_THRESHOLD, 0, 0, 0, UPPER_THRESHOLD, 0, 0, m_transition.DEFAULT_THRESHOLD) @@ -114,6 +116,8 @@ void ui::TitleView::reset() void ui::TitleView::play_sound() noexcept { sm_cursor->play(); } +// ---- Private functions ---- + void ui::TitleView::initialize_static_members() { static constexpr std::string_view CURSOR_NAME = "MenuCursor"; diff --git a/source/ui/Transition.cpp b/source/ui/Transition.cpp index 5f5ce48..d4b4165 100644 --- a/source/ui/Transition.cpp +++ b/source/ui/Transition.cpp @@ -6,6 +6,8 @@ #include +// ---- Construction ---- + ui::Transition::Transition() { Transition::update_scaling(); } ui::Transition::Transition(int x, @@ -30,6 +32,8 @@ ui::Transition::Transition(int x, Transition::update_scaling(); } +// ---- Public functions ---- + void ui::Transition::update() noexcept { ui::Transition::update_x_coord(); @@ -99,6 +103,8 @@ void ui::Transition::set_threshold(int threshold) noexcept { m_threshold = stati void ui::Transition::update_scaling() noexcept { sm_scaling = config::get_animation_scaling(); } +// ---- Private functions ---- + void ui::Transition::update_x_coord() noexcept { const double distance = math::Util::absolute_distance(m_x, m_targetX);