- Add GIT_BRANCH (for development and stable) - Write Documentation of - pd-core (exept of vec.hpp) - pd-app - pd-drivers - pd-lib3ds - pd-image - pd-image - pd-ui7
144 lines
4.0 KiB
C++
144 lines
4.0 KiB
C++
#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 <pd/drivers/hid.hpp>
|
|
#include <pd/ui7/drawlist.hpp>
|
|
#include <pd/ui7/flags.hpp>
|
|
#include <pd/ui7/id.hpp>
|
|
#include <pd/ui7/menu.hpp>
|
|
#include <pd/ui7/theme.hpp>
|
|
|
|
namespace PD {
|
|
namespace UI7 {
|
|
/** Base Context for UI7 */
|
|
class Context : public SmartCtor<Context> {
|
|
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);
|
|
}
|
|
~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; }
|
|
|
|
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<u32, Menu::Ref> menus;
|
|
std::vector<u32> 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;
|
|
};
|
|
} // namespace UI7
|
|
} // namespace PD
|