diff --git a/include/renderd7/Color.hpp b/include/renderd7/Color.hpp index bb34fc6..85a9144 100644 --- a/include/renderd7/Color.hpp +++ b/include/renderd7/Color.hpp @@ -20,7 +20,9 @@ #include #include +#include #include +#include #define UNPACK_RGBA(col) (uint8_t)(col >> 24), (col >> 16), (col >> 8), (col) #define UNPACK_BGRA(col) (uint8_t)(col >> 8), (col >> 16), (col >> 24), (col) @@ -58,23 +60,59 @@ enum RD7Color_ { RD7Color_TextDisabled, /// Text Disabled Color RD7Color_Text2, ///< And This want for Texts on Dark Backgrounds RD7Color_Background, ///< Your Bg Color - RD7Color_Header, ///< Header Color (if the header is dark text2 is used) - RD7Color_Selector, - RD7Color_SelectorFade, - RD7Color_List0, - RD7Color_List1, - RD7Color_MessageBackground, - RD7Color_Button, - RD7Color_ButtonHovered, - RD7Color_ButtonDisabled, - RD7Color_ButtonActive, - RD7Color_Checkmark, - RD7Color_FrameBg, - RD7Color_FrameBgHovered, - RD7Color_Progressbar, + RD7Color_Header, ///< Header Color (if the header is dark text2 is used) + RD7Color_Selector, ///< Selector Color + RD7Color_SelectorFade, ///< Selector FadingTo Color + RD7Color_List0, ///< List Color1 + RD7Color_List1, ///< List Color2 + RD7Color_MessageBackground, ///< Message Background + RD7Color_Button, ///< Button Color + RD7Color_ButtonHovered, ///< Button Color if Hovered + RD7Color_ButtonDisabled, ///< Button Color if disabled + RD7Color_ButtonActive, ///< Button Colkor if Clicked + RD7Color_Checkmark, ///< Checkbox Checkmark Color + RD7Color_FrameBg, ///< Frame Background Color + RD7Color_FrameBgHovered, ///< Frame Background Color if hovered + RD7Color_Progressbar, ///< Progressbar Color + /// NON COLOR /// + RD7Color_Len, ///< Used to define the lengh of this list }; namespace RenderD7 { +class Theme { + public: + Theme() = default; + ~Theme() = default; + + void Load(const std::string &path); + void Default(); + + unsigned int Get(RD7Color clr); + void Set(RD7Color clr, unsigned int v); + void Swap(RD7Color a, RD7Color b); + bool Undo(); + void UndoAll(); + + // For Smart Pointer + using Ref = std::shared_ptr; + static Ref New() { return std::make_shared(); } + + private: + struct change { + change(RD7Color a, unsigned int f, unsigned int t) + : clr(a), from(f), to(t) {} + change(RD7Color a, RD7Color b, unsigned int f, unsigned int t) + : clr(a), clr2(b), from(f), to(t) {} + RD7Color clr; + RD7Color clr2 = 0; // Used if Swap + unsigned int from; + unsigned int to; + }; + // Use a vector for faster access + std::vector clr_tab; + std::vector changes; +}; + unsigned int StyleColor(RD7Color color); void RedirectColor(RD7Color to, RD7Color from); void TextColorByBg(RD7Color background); @@ -88,6 +126,8 @@ void UndoAllColorEdits(); void ThemeLoad(const std::string &path); void ThemeSave(const std::string &path); void ThemeDefault(); +Theme::Ref ThemeActive(); +void ThemeSet(Theme::Ref theme); namespace Color { /// @brief RGBA Class class RGBA { diff --git a/include/renderd7/FunctionTrace.hpp b/include/renderd7/FunctionTrace.hpp index 2e665e6..ae48250 100644 --- a/include/renderd7/FunctionTrace.hpp +++ b/include/renderd7/FunctionTrace.hpp @@ -18,8 +18,10 @@ #pragma once // Base includes +#include #include #include + // 3ds does not support std::chrono #include <3ds.h> @@ -39,6 +41,7 @@ struct FTRes { uint64_t time_start; ///< when started uint64_t time_end; ///< when stopped float time_of; ///< stop - start (how long) + float time_ofm; ///< max time off bool is_ovl; ///< is displayed in overlay? }; @@ -48,21 +51,44 @@ extern std::map rd7_traces; /// @brief Set a Start TracePoint /// @param group Set a Group Name /// @param func_name Set a Function Name -inline void Beg(std::string group, std::string func_name) { +inline void Beg(const std::string& group, const std::string& func_name) { std::string trace_id = scomb(group, func_name); - rd7_traces[trace_id].group = group; - rd7_traces[trace_id].func_name = func_name; - rd7_traces[trace_id].time_start = svcGetSystemTick(); + auto& trace = rd7_traces[trace_id]; + trace.group = group; + trace.func_name = func_name; + trace.time_start = svcGetSystemTick(); } /// @brief Set an End TracePoint /// @param group Set a Group Name /// @param func_name Set a Function Name -inline void End(std::string group, std::string func_name) { +inline void End(const std::string& group, const std::string& func_name) { std::string trace_id = scomb(group, func_name); - rd7_traces[trace_id].time_end = svcGetSystemTick(); - rd7_traces[trace_id].time_of = static_cast( - ((float)rd7_traces[trace_id].time_end / (float)TICKS_PER_MSEC) - - ((float)rd7_traces[trace_id].time_start / (float)TICKS_PER_MSEC)); + auto& trace = rd7_traces[trace_id]; + trace.time_end = svcGetSystemTick(); + if (trace.time_of > trace.time_ofm) trace.time_ofm = trace.time_of; + trace.time_of = + static_cast(trace.time_end - trace.time_start) / TICKS_PER_MSEC; } +/// @brief Trace a function execution +/// @param group Set a Group Name +/// @param name Set a Function Name +inline void Func(const std::string& group, const std::string& name, + std::function fun) { + if (!fun) return; + Beg(group, name); + fun(); + End(group, name); +} + +/// @brief This Starts an Ftrace and +/// end ist when going out of scope +struct ScopedTrace { + ScopedTrace(std::string g, std::string n) : group(g), name(n) { + Ftrace::Beg(g, n); + } + ~ScopedTrace() { Ftrace::End(group, name); } + std::string group; + std::string name; +}; } // namespace Ftrace } // namespace RenderD7 diff --git a/include/renderd7/ThemeEditor.hpp b/include/renderd7/ThemeEditor.hpp new file mode 100644 index 0000000..6f1a595 --- /dev/null +++ b/include/renderd7/ThemeEditor.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include + +namespace RenderD7 { +class ThemeEditor : public RenderD7::Scene { + public: + ThemeEditor() = default; + ~ThemeEditor() = default; + + void Draw() const override; + void Logic() override; + + private: +}; +} // namespace RenderD7 \ No newline at end of file diff --git a/source/Color.cpp b/source/Color.cpp index 3f97f02..7d2711f 100644 --- a/source/Color.cpp +++ b/source/Color.cpp @@ -23,6 +23,41 @@ #include #include +void rd7i_swap32(unsigned int& c) { + c = ((c & 0xFF) << 24) | ((c & 0xFF00) << 8) | ((c & 0xFF0000) >> 8) | + ((c & 0xFF000000) >> 24); +} + +std::string rd7i_mk2hex(unsigned int c32) { + rd7i_swap32(c32); + std::stringstream ss; + ss << "#"; + ss << std::hex << std::setw(8) << std::setfill('0') << c32; + return ss.str(); +} + +// Standart Color Converter +static const std::map HEX_TO_DEC = { + {'0', 0}, {'1', 1}, {'2', 2}, {'3', 3}, {'4', 4}, {'5', 5}, + {'6', 6}, {'7', 7}, {'8', 8}, {'9', 9}, {'a', 10}, {'b', 11}, + {'c', 12}, {'d', 13}, {'e', 14}, {'f', 15}, {'A', 10}, {'B', 11}, + {'C', 12}, {'D', 13}, {'E', 14}, {'F', 15}}; + +unsigned int rd7i_special_color_hex(const std::string& hex) { + if (hex.length() < 9 || std::find_if(hex.begin() + 1, hex.end(), [](char c) { + return !std::isxdigit(c); + }) != hex.end()) { + return rd7i_special_color_hex("#00000000"); + } + + int r = HEX_TO_DEC.at(hex[1]) * 16 + HEX_TO_DEC.at(hex[2]); + int g = HEX_TO_DEC.at(hex[3]) * 16 + HEX_TO_DEC.at(hex[4]); + int b = HEX_TO_DEC.at(hex[5]) * 16 + HEX_TO_DEC.at(hex[6]); + int a = HEX_TO_DEC.at(hex[7]) * 16 + HEX_TO_DEC.at(hex[8]); + + return RGBA8(r, g, b, a); +} + // Default Theme const std::map rd7i_default_theme = { {RD7Color_Text, RGBA8(0, 0, 0, 255)}, @@ -45,6 +80,86 @@ const std::map rd7i_default_theme = { {RD7Color_Progressbar, RGBA8(0, 255, 0, 255)}, }; +void RenderD7::Theme::Load(const std::string& path) { + std::ifstream file(path); + if (!file.is_open()) { + return; + } + nlohmann::json js; + file >> js; + // clang-format off + if(THEMEVER != js["version"]) { + file.close(); + return; + } + this->clr_tab.clear(); + this->clr_tab.resize(RD7Color_Len); + this->clr_tab[RD7Color_Text] = rd7i_special_color_hex(js["RD7Color_Text"].get()); + this->clr_tab[RD7Color_Text2] = rd7i_special_color_hex(js["RD7Color_Text2"].get()); + this->clr_tab[RD7Color_TextDisabled] = rd7i_special_color_hex(js["RD7Color_TextDisabled"].get()); + this->clr_tab[RD7Color_Background] = rd7i_special_color_hex(js["RD7Color_Background"].get()); + this->clr_tab[RD7Color_Header] = rd7i_special_color_hex(js["RD7Color_Header"].get()); + this->clr_tab[RD7Color_Selector] = rd7i_special_color_hex(js["RD7Color_Selector"].get()); + this->clr_tab[RD7Color_SelectorFade] = rd7i_special_color_hex(js["RD7Color_SelectorFade"].get()); + this->clr_tab[RD7Color_List0] = rd7i_special_color_hex(js["RD7Color_List0"].get()); + this->clr_tab[RD7Color_List1] = rd7i_special_color_hex(js["RD7Color_List1"].get()); + this->clr_tab[RD7Color_MessageBackground] = rd7i_special_color_hex(js["RD7Color_MessageBackground"].get()); + this->clr_tab[RD7Color_Button] = rd7i_special_color_hex(js["RD7Color_Button"].get()); + this->clr_tab[RD7Color_ButtonHovered] = rd7i_special_color_hex(js["RD7Color_ButtonHovered"].get()); + this->clr_tab[RD7Color_ButtonDisabled] = rd7i_special_color_hex(js["RD7Color_ButtonDisabled"].get()); + this->clr_tab[RD7Color_ButtonActive] = rd7i_special_color_hex(js["RD7Color_ButtonActive"].get()); + this->clr_tab[RD7Color_Checkmark] = rd7i_special_color_hex(js["RD7Color_Checkmark"].get()); + this->clr_tab[RD7Color_FrameBg] = rd7i_special_color_hex(js["RD7Color_FrameBg"].get()); + this->clr_tab[RD7Color_FrameBgHovered] = rd7i_special_color_hex(js["RD7Color_FrameBgHovered"].get()); + this->clr_tab[RD7Color_Progressbar] = rd7i_special_color_hex(js["RD7Color_Progressbar"].get()); + // clang-format on + file.close(); +} + +void RenderD7::Theme::Default() { + this->clr_tab.clear(); + this->clr_tab.resize(RD7Color_Len); + for (auto& it : rd7i_default_theme) { + this->clr_tab[it.first] = it.second; + } +} + +unsigned int RenderD7::Theme::Get(RD7Color clr) { + if (clr < 0 || clr >= RD7Color_Len) return 0; + return this->clr_tab[clr]; +} +void RenderD7::Theme::Set(RD7Color clr, unsigned int v) { + if (clr < 0 || clr >= RD7Color_Len) return; + this->changes.push_back(change(clr, this->clr_tab[clr], v)); + this->clr_tab[clr] = v; +} +void RenderD7::Theme::Swap(RD7Color a, RD7Color b) { + if (a < 0 || a >= RD7Color_Len || b < 0 || b >= RD7Color_Len) return; + auto c = this->clr_tab[a]; + this->clr_tab[a] = this->clr_tab[b]; + this->clr_tab[b] = c; + this->changes.push_back(change(a, b, c, this->clr_tab[a])); +} + +bool RenderD7::Theme::Undo() { + if (!this->changes.size()) return false; + auto ch = this->changes[this->changes.size() - 1]; + this->changes.pop_back(); + if (ch.clr2) { + this->clr_tab[ch.clr2] = ch.to; + this->clr_tab[ch.clr] = ch.from; + } else { + this->clr_tab[ch.clr] = ch.from; + } + return true; +} + +void RenderD7::Theme::UndoAll() { + while (Undo()) { + // Just Run Undo Until all is undone + } +} + // RenderD7 StyleColor Api // not const cause const = error lol std::map rd7i_color_map = rd7i_default_theme; @@ -90,41 +205,6 @@ void RenderD7::UndoColorEdit(RD7Color color) { void RenderD7::UndoAllColorEdits() { rd7i_color_swap_map.clear(); } -void rd7i_swap32(unsigned int& c) { - c = ((c & 0xFF) << 24) | ((c & 0xFF00) << 8) | ((c & 0xFF0000) >> 8) | - ((c & 0xFF000000) >> 24); -} - -std::string rd7i_mk2hex(unsigned int c32) { - rd7i_swap32(c32); - std::stringstream ss; - ss << "#"; - ss << std::hex << std::setw(8) << std::setfill('0') << c32; - return ss.str(); -} - -// Standart Color Converter -static const std::map HEX_TO_DEC = { - {'0', 0}, {'1', 1}, {'2', 2}, {'3', 3}, {'4', 4}, {'5', 5}, - {'6', 6}, {'7', 7}, {'8', 8}, {'9', 9}, {'a', 10}, {'b', 11}, - {'c', 12}, {'d', 13}, {'e', 14}, {'f', 15}, {'A', 10}, {'B', 11}, - {'C', 12}, {'D', 13}, {'E', 14}, {'F', 15}}; - -unsigned int rd7i_special_color_hex(const std::string& hex) { - if (hex.length() < 9 || std::find_if(hex.begin() + 1, hex.end(), [](char c) { - return !std::isxdigit(c); - }) != hex.end()) { - return rd7i_special_color_hex("#00000000"); - } - - int r = HEX_TO_DEC.at(hex[1]) * 16 + HEX_TO_DEC.at(hex[2]); - int g = HEX_TO_DEC.at(hex[3]) * 16 + HEX_TO_DEC.at(hex[4]); - int b = HEX_TO_DEC.at(hex[5]) * 16 + HEX_TO_DEC.at(hex[6]); - int a = HEX_TO_DEC.at(hex[7]) * 16 + HEX_TO_DEC.at(hex[8]); - - return RGBA8(r, g, b, a); -} - void RenderD7::ThemeLoad(const std::string& path) { std::ifstream file(path); if (!file.is_open()) { diff --git a/source/UI7.cpp b/source/UI7.cpp index 05ad3d7..50ff3c5 100644 --- a/source/UI7.cpp +++ b/source/UI7.cpp @@ -25,6 +25,16 @@ #include #include +template +inline T d7max(T a, T b) { + return a > b ? a : b; +} + +template +inline T d7min(T a, T b) { + return a < b ? a : b; +} + // As the 3ds doesn't support std::chrono #ifdef __3DS__ /// @brief 3ds System Ticks per milli second @@ -54,24 +64,16 @@ struct UI7ID { // Ensure the id is lowercase std::transform(real_id.begin(), real_id.end(), real_id.begin(), [](unsigned char c) { return std::tolower(c); }); - lt = time(0); } UI7ID() { title = ""; real_id = ""; has_title = false; - lt = time(0); } - std::string Title() { - lt = time(0); - return title; - } + std::string Title() { return title; } - std::string ID() { - lt = time(0); - return real_id; - } + std::string ID() { return real_id; } bool operator==(const UI7ID &in) { return (real_id == in.real_id); } @@ -80,7 +82,6 @@ struct UI7ID { std::string title; std::string real_id; bool has_title; - int lt; }; std::vector ui7i_debug_colors{ @@ -125,11 +126,14 @@ struct UI7Menu { R7Vec2 cursor; // cursor R7Vec2 cb; // backup cursor R7Vec2 slc; // sameline cursor - float scrolling_offset = 0.f; // For MenuScrolling + float scrolling_offset = 0.f; // MenuScrolling Pos bool enable_scrolling = false; // Menu Scrolling + float scrolling_mod = 0.f; // For Menu Scrolling effect float tbh; // TabBar Height + bool show_scroolbar = true; // Show Scrollbar R7Vec2 ms; // Max Size + R7Vec2 msr; // Max Size Real (Slider) R7Vec2 mdp; // Mouse/Touch Initial pos // For Smart Pointer using Ref = std::shared_ptr; @@ -153,7 +157,6 @@ struct UI7_Ctx { bool debugging; std::map menus; UI7Menu::Ref cm; - std::unordered_map ids; std::vector objects; }; @@ -185,6 +188,31 @@ bool UI7CtxBeginMenu(const std::string &lb) { void UI7CtxEndMenu() { if (!UI7CtxValidate()) return; if (!UI7CtxInMenu()) return; + RenderD7::Ftrace::ScopedTrace tr("ui7", "EndMenu"); + // Draw Scrollbar + if (ui7_ctx->cm->enable_scrolling) { + int sw = (rd7i_current_screen ? 400 : 320); + int tsp = 5 + ui7_ctx->cm->tbh; + int szs = 240 - tsp - 5; + int lszs = 20; // Lowest Slider size + float slider_h = (szs - 4) * (static_cast(szs - 4) / + static_cast(ui7_ctx->cm->msr.y)); + int slider_rh = d7min(d7max(slider_h, (float)lszs), (float)(szs - 4)); + int slider_pos = d7min( + static_cast(tsp + szs - slider_rh - 4), + d7max( + static_cast(tsp), + static_cast(tsp) + + static_cast( + (szs) * (static_cast(ui7_ctx->cm->scrolling_offset) / + static_cast(ui7_ctx->cm->msr.y))))); + int slider_w = 4; + RenderD7::Draw2::RFS(R7Vec2(sw - 12, tsp), R7Vec2(slider_w * 2, szs), + RenderD7::StyleColor(RD7Color_List0)); + RenderD7::Draw2::RFS(R7Vec2(sw - 10, slider_pos + 2), + R7Vec2(slider_w, slider_rh), + RenderD7::StyleColor(RD7Color_Selector)); + } ui7_ctx->cm = nullptr; ui7_ctx->in_menu = false; } @@ -196,6 +224,8 @@ void UI7CtxCursorMove(R7Vec2 size) { ui7_ctx->cm->cursor.x = 5; ui7_ctx->cm->cursor += R7Vec2(0, size.y + 5); ui7_ctx->cm->ms = R7Vec2(ui7_ctx->cm->slc.x, ui7_ctx->cm->cursor.y); + // TODO: Correct that calculation + ui7_ctx->cm->msr = R7Vec2(ui7_ctx->cm->slc.x, ui7_ctx->cm->slc.y - 10); } void UI7CtxRegObj(const UI7OBJ &obj) { @@ -204,34 +234,6 @@ void UI7CtxRegObj(const UI7OBJ &obj) { ui7_ctx->objects.push_back(obj); } -UI7ID *UI7CtxNewID(const std::string &i) { - std::string t = i; - std::transform(t.begin(), t.end(), t.begin(), - [](unsigned char c) { return std::tolower(c); }); - if (ui7_ctx->ids.find(t) != ui7_ctx->ids.end()) { - return ui7_ctx->ids[t]; - } - auto id = new UI7ID(i); - ui7_ctx->ids[id->real_id] = id; - return id; -} - -void UI7CtxClearIDs() { - for (auto it = ui7_ctx->ids.begin(); it != ui7_ctx->ids.end();) { - if (time(0) - it->second->lt > 5) { - delete it->second; - it = ui7_ctx->ids.erase(it); - continue; - } - ++it; - } -} - -int rd7i_ui7_ids_active() { - if (!UI7CtxValidate()) return 0; - return ui7_ctx->ids.size(); -} - namespace UI7 { bool InBox(R7Vec2 inpos, R7Vec2 boxpos, R7Vec2 boxsize) { if ((inpos.x > boxpos.x) && (inpos.y > boxpos.y) && @@ -256,9 +258,6 @@ void Deinit() { // written wrong by me :( if (!UI7CtxValidate()) return; ui7_ctx->is_activated = false; - for (auto &it : ui7_ctx->ids) { - delete it.second; - } ui7_ctx->menus.clear(); delete ui7_ctx; } @@ -270,7 +269,6 @@ void Update() { ui7_ctx->delta = (current - ui7_ctx->_last) / 1000.f; ui7_ctx->_last = current; ui7_ctx->time += ui7_ctx->delta; - UI7CtxClearIDs(); if (ui7_ctx->debugging) ui7_ctx->objects.clear(); } @@ -513,7 +511,7 @@ void InputText(const std::string &label, std::string &text, R7Vec2 txtdim = RenderD7::GetTextDimensions(label); R7Vec2 inp = cbs + R7Vec2(txtdim.x + 5, 0); RD7Color bg = RD7Color_FrameBg; - auto id = UI7CtxNewID(label); + auto id = UI7ID(label); RD7KeyboardState kbd_state; // tmp (goes out of scope) R7Vec2 pos = GetCursorPos(); @@ -543,7 +541,7 @@ void InputText(const std::string &label, std::string &text, RenderD7::TextColorByBg(bg); RenderD7::Draw2::Text(pos + R7Vec2(5, 1), (text != "" ? text : hint)); RenderD7::UndoColorEdit(RD7Color_Text); - RenderD7::Draw2::Text(pos + R7Vec2(cbs.x + 5, 1), id->Title()); + RenderD7::Draw2::Text(pos + R7Vec2(cbs.x + 5, 1), id.Title()); RenderD7::Draw2::ScissorReset(); } @@ -551,7 +549,7 @@ bool BeginMenu(const std::string &title, R7Vec2 size, UI7MenuFlags flags) { if (!UI7CtxValidate()) return false; if (UI7CtxInMenu()) return false; RenderD7::Draw2::ScissorReset(); - auto id = UI7CtxNewID(title); + auto id = UI7ID(title); auto ret = UI7CtxBeginMenu(title); if (!ret) return ret; bool titlebar = true; @@ -569,31 +567,77 @@ bool BeginMenu(const std::string &title, R7Vec2 size, UI7MenuFlags flags) { if (flags & UI7MenuFlags_TitleMid) txtflags = RD7TextFlags_AlignMid; ui7_ctx->cm->enable_scrolling = (flags & UI7MenuFlags_Scrolling); if (ui7_ctx->cm->enable_scrolling && !rd7i_current_screen) { + // Patch that sets scrolling to 0 if max pos is not out of screen if (ui7_ctx->cm->scrolling_offset != 0.f && ui7_ctx->cm->ms.y < 235) { ui7_ctx->cm->scrolling_offset = 0.f; } + // Auto scroll back if last object is on screen if (ui7_ctx->cm->scrolling_offset > ui7_ctx->cm->ms.y - 240 && ui7_ctx->cm->ms.y != 0 && ui7_ctx->cm->ms.y >= 235) { ui7_ctx->cm->scrolling_offset -= 3; + // Patch to Scroll to perfect pos + if (ui7_ctx->cm->scrolling_offset < ui7_ctx->cm->ms.y - 240) { + ui7_ctx->cm->scrolling_offset = ui7_ctx->cm->ms.y - 240; + } } + // Auto Scroll back if offset gets below 0 if (ui7_ctx->cm->scrolling_offset < 0) { ui7_ctx->cm->scrolling_offset += 3; if (ui7_ctx->cm->scrolling_offset > 0) ui7_ctx->cm->scrolling_offset = 0; } + + // Zero out scrolling_mod if it goeas < -40 + // or > 40 over the max size + if (ui7_ctx->cm->scrolling_offset < -40 || + ui7_ctx->cm->scrolling_offset > ui7_ctx->cm->ms.y - 200) { + ui7_ctx->cm->scrolling_mod = 0.f; + } + if (RenderD7::Hid::IsEvent("touch", RenderD7::Hid::Down)) { + // Set the mdp Value as Start Pos ui7_ctx->cm->mdp = RenderD7::Hid::GetTouchPosition(); } else if (RenderD7::Hid::IsEvent("touch", RenderD7::Hid::Up)) { + // 0 out the start pos ui7_ctx->cm->mdp = R7Vec2(); } if (RenderD7::Hid::IsEvent("touch", RenderD7::Hid::Held)) { + // Set modifier auto np = RenderD7::Hid::GetTouchPosition(); + // Check if and do nothing if the scrolling ofset goes out of screen if (ui7_ctx->cm->scrolling_offset < ui7_ctx->cm->ms.y - 200 && - ui7_ctx->cm->scrolling_offset > -40) - ui7_ctx->cm->scrolling_offset += (ui7_ctx->cm->mdp.y - np.y); + ui7_ctx->cm->scrolling_offset > -40) { + float cursor_mod = (ui7_ctx->cm->mdp.y - np.y); + if (ui7_ctx->cm->scrolling_mod <= 4.f && + ui7_ctx->cm->scrolling_mod >= -4 && cursor_mod != 0.0f) { + if (cursor_mod > 0) { + ui7_ctx->cm->scrolling_mod = cursor_mod; + } else { + ui7_ctx->cm->scrolling_mod = cursor_mod; + } + } + } + // Update Start pos ui7_ctx->cm->mdp = np; } + // New Scrolling efect + if (ui7_ctx->cm->scrolling_mod != 0) + ui7_ctx->cm->scrolling_offset += ui7_ctx->cm->scrolling_mod; + // Slow out the effect + if (ui7_ctx->cm->scrolling_mod < 0.f) { + ui7_ctx->cm->scrolling_mod += 0.4f; + if (ui7_ctx->cm->scrolling_mod > 0.f) { + ui7_ctx->cm->scrolling_mod = 0.f; + } + } else if (ui7_ctx->cm->scrolling_mod > 0.f) { + ui7_ctx->cm->scrolling_mod -= 0.4f; + if (ui7_ctx->cm->scrolling_mod < 0.f) { + ui7_ctx->cm->scrolling_mod = 0.f; + } + } } else { + // Set scrollingoffset and mod to 0 if not scrolling enabled ui7_ctx->cm->scrolling_offset = 0.f; + ui7_ctx->cm->scrolling_mod = 0.f; } RenderD7::Draw2::RFS(R7Vec2(0, 0), size, RenderD7::StyleColor(RD7Color_Background)); @@ -602,7 +646,7 @@ bool BeginMenu(const std::string &title, R7Vec2 size, UI7MenuFlags flags) { RenderD7::Draw2::RFS(R7Vec2(0, 0), R7Vec2(size.x, tbh), RenderD7::StyleColor(RD7Color_Header)); RenderD7::TextColorByBg(RD7Color_Header); - RenderD7::Draw2::Text(R7Vec2(5, 2), id->title, txtflags); + RenderD7::Draw2::Text(R7Vec2(5, 2), id.Title(), txtflags); RenderD7::UndoColorEdit(RD7Color_Text); } diff --git a/source/renderd7.cpp b/source/renderd7.cpp index 35f226a..829c15f 100644 --- a/source/renderd7.cpp +++ b/source/renderd7.cpp @@ -81,6 +81,7 @@ void Npifade() { } void PushSplash() { + RenderD7::Ftrace::ScopedTrace st("rd7-core", f2s(PushSplash)); C2D_SpriteSheet sheet; sheet = C2D_SpriteSheetLoadFromMem((void *)renderd7_logo, renderd7_logo_size); // Display for 2 Sec @@ -242,10 +243,12 @@ void RenderD7::Init::NdspFirm() { } void RenderD7::Scene::doDraw() { + Ftrace::ScopedTrace st("rd7-core", f2s(Scene::doDraw)); if (!RenderD7::Scene::scenes.empty()) RenderD7::Scene::scenes.top()->Draw(); } void RenderD7::Scene::doLogic() { + Ftrace::ScopedTrace st("rd7-core", f2s(Scene::doLogic)); if (!RenderD7::Scene::scenes.empty()) RenderD7::Scene::scenes.top()->Logic(); } @@ -278,7 +281,7 @@ std::string RenderD7::GetFramerate() { } bool RenderD7::MainLoop() { - RenderD7::Ftrace::Beg("rd7-core", f2s(RenderD7::MainLoop)); + RenderD7::Ftrace::ScopedTrace st("rd7-core", f2s(MainLoop)); if (!aptMainLoop()) return false; // Deltatime uint64_t currentTime = svcGetSystemTick(); @@ -304,18 +307,11 @@ bool RenderD7::MainLoop() { C2D_TargetClear(Top, C2D_Color32(0, 0, 0, 0)); C2D_TargetClear(Bottom, C2D_Color32(0, 0, 0, 0)); - RenderD7::Ftrace::Beg("rd7-core", "frame"); frameloop(); if (rd7_enable_scene_system) { - RenderD7::Ftrace::Beg("rd7sm", f2s(RenderD7::Scene::doDraw)); RenderD7::Scene::doDraw(); - RenderD7::Ftrace::End("rd7sm", f2s(RenderD7::Scene::doDraw)); - RenderD7::Ftrace::Beg("rd7sm", f2s(RenderD7::Scene::doLogic)); RenderD7::Scene::doLogic(); - RenderD7::Ftrace::End("rd7sm", f2s(RenderD7::Scene::doLogic)); } - - RenderD7::Ftrace::End("rd7-core", f2s(RenderD7::MainLoop)); return rd7i_running; } @@ -334,9 +330,8 @@ void RenderD7::Init::Graphics() { } Result RenderD7::Init::Main(std::string app_name) { + RenderD7::Ftrace::ScopedTrace st("rd7-core", f2s(Init::Main)); rd7i_app_name = app_name; - /// The only func that can be executed before Security - RenderD7::Ftrace::Beg("rd7-core", f2s(RenderD7::Init::Main)); gfxInitDefault(); atexit(gfxExit); @@ -379,21 +374,19 @@ Result RenderD7::Init::Main(std::string app_name) { rd7i_graphics_on = true; rd7i_last_tm = svcGetSystemTick(); - RenderD7::Ftrace::Beg("rd7-core", "do_splash"); if (rd7_do_splash) PushSplash(); - RenderD7::Ftrace::End("rd7-core", "do_splash"); rd7i_init_config(); rd7i_init_input(); rd7i_init_theme(); UI7::Init(); atexit(UI7::Deinit); - RenderD7::Ftrace::End("rd7-core", f2s(RenderD7::Init::Main)); rd7i_running = true; return 0; } Result RenderD7::Init::Minimal(std::string app_name) { + RenderD7::Ftrace::ScopedTrace st("rd7-core", f2s(Init::Minimal)); rd7i_app_name = app_name; gfxInitDefault(); @@ -484,6 +477,7 @@ int RenderD7::GetFps() { return (int)rd7i_framerate; } bool RenderD7::IsNdspInit() { return rd7i_is_ndsp; } void OvlHandler() { + RenderD7::Ftrace::ScopedTrace st("rd7-core", f2s(OvlHandler)); for (size_t i = 0; i < rd7i_overlays.size(); i++) { rd7i_overlays[i]->Draw(); rd7i_overlays[i]->Logic(); @@ -493,18 +487,16 @@ void OvlHandler() { } void RenderD7::FrameEnd() { + Ftrace::ScopedTrace st("rd7-core", f2s(FrameEnd)); C3D_FrameBegin(2); if (!rd7_enable_scene_system && rd7i_settings) { RenderD7::Scene::doDraw(); RenderD7::Scene::doLogic(); } RenderD7::ProcessMessages(); - RenderD7::Ftrace::Beg("rd7oh", f2s(OvlHandler)); OvlHandler(); - RenderD7::Ftrace::End("rd7oh", f2s(OvlHandler)); UI7::Debug(); Npifade(); - RenderD7::Ftrace::End("rd7-core", "frame"); C3D_FrameEnd(0); } @@ -538,8 +530,6 @@ std::vector StrHelper(std::string input) { return test1; } -extern int rd7i_ui7_ids_active(); - void RenderD7::RSettings::Draw(void) const { if (m_state == RSETTINGS) { RenderD7::OnScreen(Top); @@ -690,6 +680,10 @@ void RenderD7::RSettings::Draw(void) const { UI7::Label("Function: " + jt->second.func_name); UI7::Checkbox("In Overlay", jt->second.is_ovl); UI7::Label("Time: " + RenderD7::MsTimeFmt(jt->second.time_of)); + UI7::Label("Max: " + RenderD7::MsTimeFmt(jt->second.time_ofm)); + UI7::Label("TS: " + std::to_string(jt->second.time_start)); + UI7::Label("TE: " + std::to_string(jt->second.time_end)); + UI7::Label("SVC_Stk: " + std::to_string(svcGetSystemTick())); UI7::EndMenu(); } } else if (m_state == RUI7) { @@ -711,7 +705,6 @@ void RenderD7::RSettings::Draw(void) const { UI7::Label( "Touch Last Pos: " + std::to_string(Hid::GetLastTouchPosition().x) + ", " + std::to_string(Hid::GetLastTouchPosition().y)); - UI7::Label("Active IDs: " + std::to_string(rd7i_ui7_ids_active())); UI7::EndMenu(); }