2025-01-09 20:22:49 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
/*
|
|
|
|
MIT License
|
2025-02-04 21:44:27 +01:00
|
|
|
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
2025-01-09 20:22:49 +01:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2025-02-22 00:23:48 +01:00
|
|
|
#include <pd/drivers/hid.hpp> //// WOW A NON UI/ Header
|
2025-01-09 20:22:49 +01:00
|
|
|
#include <pd/ui7/drawlist.hpp>
|
|
|
|
#include <pd/ui7/flags.hpp>
|
2025-01-19 20:16:43 +01:00
|
|
|
#include <pd/ui7/id.hpp>
|
|
|
|
#include <pd/ui7/menu.hpp>
|
2025-01-09 20:22:49 +01:00
|
|
|
#include <pd/ui7/theme.hpp>
|
|
|
|
|
|
|
|
namespace PD {
|
2025-01-19 20:16:43 +01:00
|
|
|
namespace UI7 {
|
|
|
|
class Context : public SmartCtor<Context> {
|
2025-01-09 20:22:49 +01:00
|
|
|
public:
|
2025-01-29 03:14:29 +01:00
|
|
|
Context(LI::Renderer::Ref ren, Hid::Ref hid) {
|
|
|
|
this->ren = ren;
|
|
|
|
this->inp = hid;
|
2025-02-28 19:49:24 +01:00
|
|
|
theme = Theme::New();
|
2025-01-29 03:14:29 +01:00
|
|
|
back = DrawList::New(ren);
|
|
|
|
front = DrawList::New(ren);
|
|
|
|
}
|
2025-01-19 20:16:43 +01:00
|
|
|
~Context() {}
|
|
|
|
|
2025-01-29 03:14:29 +01:00
|
|
|
bool BeginMenu(const ID& id, UI7MenuFlags flags = 0);
|
|
|
|
Menu::Ref GetCurrentMenu();
|
2025-02-17 22:20:30 +01:00
|
|
|
Menu::Ref FindMenu(const ID& id);
|
2025-01-29 03:14:29 +01:00
|
|
|
void EndMenu();
|
|
|
|
|
2025-02-28 19:49:24 +01:00
|
|
|
/// @brief Get Theme reference
|
|
|
|
/// @return Reference to the base Theme of the context
|
|
|
|
Theme::Ref GetTheme() { return theme; }
|
|
|
|
/// @brief 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); }
|
2025-01-29 03:14:29 +01:00
|
|
|
|
|
|
|
/// @brief Update Context (Render menus)
|
|
|
|
/// @param delta deltatime
|
2025-01-19 20:16:43 +01:00
|
|
|
void Update(float delta);
|
2025-01-09 20:22:49 +01:00
|
|
|
|
2025-01-29 03:14:29 +01:00
|
|
|
/// Expose DrawLists
|
|
|
|
DrawList::Ref BackList() { return back; }
|
|
|
|
DrawList::Ref FrontList() { return front; }
|
|
|
|
|
2025-02-09 21:40:31 +01:00
|
|
|
void RootLayer(int l) { root_layer = l; }
|
|
|
|
int RootLayer() const { return root_layer; }
|
|
|
|
|
2025-01-09 20:22:49 +01:00
|
|
|
private:
|
2025-02-09 21:40:31 +01:00
|
|
|
// Used in Overlays
|
|
|
|
int root_layer = 0;
|
2025-01-29 03:14:29 +01:00
|
|
|
// Linked Renderer / Hid
|
|
|
|
LI::Renderer::Ref ren;
|
|
|
|
Hid::Ref inp;
|
2025-01-09 20:22:49 +01:00
|
|
|
// Timing
|
|
|
|
float delta;
|
|
|
|
float time;
|
|
|
|
float last;
|
|
|
|
// Context
|
|
|
|
bool in_menu;
|
|
|
|
// Debug
|
2025-01-19 20:16:43 +01:00
|
|
|
bool debugging;
|
2025-01-09 20:22:49 +01:00
|
|
|
// Menu Handlers
|
2025-01-19 20:16:43 +01:00
|
|
|
std::unordered_map<u32, Menu::Ref> menus;
|
2025-01-29 03:14:29 +01:00
|
|
|
std::vector<u32> amenus; // Active ones
|
2025-01-19 20:16:43 +01:00
|
|
|
Menu::Ref current;
|
2025-01-09 20:22:49 +01:00
|
|
|
// Context DrawList
|
2025-01-19 20:16:43 +01:00
|
|
|
DrawList::Ref debug;
|
|
|
|
DrawList::Ref front;
|
|
|
|
DrawList::Ref back;
|
2025-01-29 03:14:29 +01:00
|
|
|
// Theme
|
2025-02-28 19:49:24 +01:00
|
|
|
Theme::Ref theme;
|
2025-01-09 20:22:49 +01:00
|
|
|
// Promt Handler
|
|
|
|
};
|
2025-01-19 20:16:43 +01:00
|
|
|
} // namespace UI7
|
2025-01-09 20:22:49 +01:00
|
|
|
} // namespace PD
|