- Fix nullptr->value access issue in UI7::Context - Add UI7MenuFlags_NoMove to disable window movement - Fix testapp to support the new DebugLabels standard
139 lines
4.8 KiB
C++
139 lines
4.8 KiB
C++
/*
|
|
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/core/timetrace.hpp>
|
|
#include <pd/ui7/ui7.hpp>
|
|
|
|
namespace PD {
|
|
std::string UI7::GetVersion(bool show_build) {
|
|
std::stringstream s;
|
|
s << ((UI7_VERSION >> 24) & 0xFF) << ".";
|
|
s << ((UI7_VERSION >> 16) & 0xFF) << ".";
|
|
s << ((UI7_VERSION >> 8) & 0xFF);
|
|
if (show_build) s << "-" << ((UI7_VERSION) & 0xFF);
|
|
return s.str();
|
|
}
|
|
bool UI7::Context::BeginMenu(const ID& id, UI7MenuFlags flags) {
|
|
Assert(!this->current, "You are already in another Menu!");
|
|
Assert(std::find(amenus.begin(), amenus.end(), (u32)id) == amenus.end(),
|
|
"Menu Name Already used or\nContext::Update not called!");
|
|
auto menu = this->menus.find(id);
|
|
if (menu == this->menus.end()) {
|
|
this->menus[id] = Menu::New(id, theme, inp);
|
|
menu = this->menus.find(id);
|
|
}
|
|
this->current = menu->second;
|
|
if (!this->current->BackList()) {
|
|
this->current->BackList(DrawList::New(ren));
|
|
this->current->BackList()->BaseLayer(root_layer + 30);
|
|
}
|
|
if (!this->current->MainList()) {
|
|
this->current->MainList(DrawList::New(ren));
|
|
this->current->MainList()->BaseLayer(root_layer + 40);
|
|
}
|
|
if (!this->current->FrontList()) {
|
|
this->current->FrontList(DrawList::New(ren));
|
|
this->current->FrontList()->BaseLayer(root_layer + 50);
|
|
}
|
|
this->current->ViewArea(this->ren->GetViewport());
|
|
this->current->PreHandler(flags);
|
|
amenus.push_back(this->current->GetID());
|
|
if (!this->current->is_open) {
|
|
this->current = nullptr;
|
|
}
|
|
return this->current != nullptr;
|
|
}
|
|
|
|
UI7::Menu::Ref UI7::Context::GetCurrentMenu() {
|
|
Assert(current != nullptr, "Not in a Menu!");
|
|
return current;
|
|
}
|
|
|
|
UI7::Menu::Ref UI7::Context::FindMenu(const ID& id) {
|
|
auto e = this->menus.find(id);
|
|
if (e != this->menus.end()) {
|
|
return e->second;
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
void UI7::Context::EndMenu() {
|
|
this->current->PostHandler();
|
|
this->current = nullptr;
|
|
}
|
|
|
|
void UI7::Context::Update(float delta) {
|
|
TT::Scope st("UI7_Update");
|
|
Assert(current == nullptr, "Still in a Menu!");
|
|
this->delta = delta;
|
|
s_delta->Add(delta * 1000);
|
|
this->back->BaseLayer(root_layer + 10);
|
|
this->back->Process();
|
|
for (auto it : amenus) {
|
|
menus[it]->Update(delta);
|
|
}
|
|
this->front->BaseLayer(root_layer + 60);
|
|
this->front->Process();
|
|
this->amenus.clear();
|
|
}
|
|
|
|
void UI7::Context::AboutMenu() {
|
|
if (this->BeginMenu("About UI7", UI7MenuFlags_Scrolling)) {
|
|
auto m = this->GetCurrentMenu();
|
|
|
|
m->Label("Palladium - UI7 " + GetVersion());
|
|
m->Separator();
|
|
m->Label("(c) 2023-2025 René Amthor");
|
|
m->Label("UI7 is licensed under the MIT License.");
|
|
m->Label("See LICENSE for more information.");
|
|
static bool show_build;
|
|
m->Checkbox("Show Build Info", show_build);
|
|
if (show_build) {
|
|
m->SeparatorText("Build Info");
|
|
m->Label("Full Version -> " + GetVersion(true));
|
|
m->Label("sizeof(size_t) -> " + std::to_string(sizeof(size_t)));
|
|
m->Label("sizeof(LI::Vertex) -> " + std::to_string(sizeof(LI::Vertex)));
|
|
m->Label("__cplusplus -> " + std::to_string(__cplusplus));
|
|
m->Label("Compiler -> " + LibInfo::CompiledWith());
|
|
}
|
|
this->EndMenu();
|
|
}
|
|
}
|
|
|
|
void UI7::Context::MetricsMenu() {
|
|
if (this->BeginMenu("UI7 Metrics", UI7MenuFlags_Scrolling)) {
|
|
auto m = this->GetCurrentMenu();
|
|
|
|
m->Label("Palladium - UI7 " + GetVersion());
|
|
m->Separator();
|
|
m->Label(std::format("Average {:.3f} ms/f ({:.1f} FPS)",
|
|
((float)s_delta->GetAverage() / 1000.f),
|
|
1000.f / ((float)s_delta->GetAverage() / 1000.f)));
|
|
m->Label(std::format("Vertices: {} Indices: {}", ren->Vertices(),
|
|
ren->Indices()));
|
|
m->Label("Triangles: " + std::to_string(ren->Indices() / 3));
|
|
m->Label("Menus: " + std::to_string(menus.size()));
|
|
this->EndMenu();
|
|
}
|
|
}
|
|
} // namespace PD
|