#pragma once /* MIT License Copyright (c) 2024 - 2025 René Amthor (tobid7) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include #include #include #include #include #include #include /** * Declare UI7 Version * Format: 00 00 00 00 * Major Minor Patch Build * 0x01010000 -> 1.1.0-0 */ #define UI7_VERSION 0x00020701 namespace PD { namespace UI7 { /** * Get UI7 Version String * @param show_build Ahow build num (mostly unused) * @return Version String (1.0.0-1 for example) */ std::string GetVersion(bool show_build = false); /** Base Context for UI7 */ class Context : public SmartCtor { public: /** * Constructor for UI7 Context * @param ren Renderer Reference * @param hid Input Driver Reference */ Context(LI::Renderer::Ref ren, Hid::Ref hid) { /// Set the Internal References this->ren = ren; this->inp = hid; /// Init Theme and Front / Back Drawlists theme = Theme::New(); back = DrawList::New(ren); front = DrawList::New(ren); s_delta = TimeStats::New(60); } ~Context() = default; /** * Begin a New Menu * @param id Menu ID / Name shown in Titlebar * @param flags Optional flags to change stuff * @return If the Menu was Created * (useless as false results in an error screen) */ bool BeginMenu(const ID& id, UI7MenuFlags flags = 0); /** * Get the Current Menu * for example for auto m = ctx->GetCurrentMenu */ Menu::Ref GetCurrentMenu(); /** * Find a Menu by its ID to edit things outside of * the place between Begin and EndMenu * @param id ID (Menu Name) to search for */ Menu::Ref FindMenu(const ID& id); /** * Ends the Current Menu * (to be able to create another one) */ void EndMenu(); /** * Get Theme reference * @return Reference to the base Theme of the context */ Theme::Ref GetTheme() { return theme; } /** *Directly return a Color by using the * ctx->ThemeColor(UI7Color_Text) for example * @param clr The Input UI7 Color * @return The 32bit color value */ u32 ThemeColor(UI7Color clr) const { return theme->Get(clr); } /** * Update Context (Render menus) * @param delta deltatime */ void Update(float delta); // Expose DrawLists /** Background DrawList Reference */ DrawList::Ref BackList() { return back; } /** Foreground DrawList Reference */ DrawList::Ref FrontList() { return front; } /** * Set the Root Layer of the Menu * @param l Layer */ void RootLayer(int l) { root_layer = l; } /** Get the Root Layer of the Menu */ int RootLayer() const { return root_layer; } // Debugging / Demo / About /** About Menu */ void AboutMenu(); /** Metrics */ void MetricsMenu(); private: // Used in Overlays int root_layer = 0; // Linked Renderer LI::Renderer::Ref ren; // Input Driver Reference Hid::Ref inp; // Delta time float delta; // Context Run Time float time; /// @brief Last Time [unused ?] float last; // In Menu [unused ?] bool in_menu; // Is Debugging [unused ?] bool debugging; // Map of The Menus by ID std::unordered_map menus; std::vector amenus; ///< Active ones Menu::Ref current; ///< Current Menu // Debug Drawlist DrawList::Ref debug; // Foreground Drawlist DrawList::Ref front; // Background Drawlist DrawList::Ref back; // Active Theme Theme::Ref theme; // Metrics // Deltatime Average TimeStats::Ref s_delta; }; } // namespace UI7 } // namespace PD