From ba77dc9b42164e8195601ebb93ad21f199edafc3 Mon Sep 17 00:00:00 2001 From: tobid7 Date: Wed, 12 Mar 2025 21:09:45 +0100 Subject: [PATCH] # 0.3.0 - Fix minor issues - Add Custom UV Support to Drawlist and Menu Image - Add DoubleClick to IO Input API - Add Flashbang Theme (Not completly done) - Fix Menu glitch when scrolling was possible when not allowed --- CMakeLists.txt | 2 +- include/pd/ui7/container/image.hpp | 4 +++- include/pd/ui7/drawlist.hpp | 4 +++- include/pd/ui7/id.hpp | 5 ++++- include/pd/ui7/io.hpp | 21 ++++++++++++--------- include/pd/ui7/menu.hpp | 2 +- include/pd/ui7/theme.hpp | 5 +++++ include/pd/ui7/ui7.hpp | 2 +- source/ui7/container/button.cpp | 2 ++ source/ui7/container/image.cpp | 2 +- source/ui7/drawlist.cpp | 23 +++-------------------- source/ui7/io.cpp | 1 + source/ui7/menu.cpp | 11 ++++++++--- source/ui7/theme.cpp | 19 +++++++++++++++++++ source/ui7/ui7.cpp | 19 +++++++++++++++++++ 15 files changed, 83 insertions(+), 39 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6d0e4ea..7dcd0ec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,7 +52,7 @@ execute_process( ) # Set Project -project(palladium LANGUAGES C CXX VERSION 0.2.9) +project(palladium LANGUAGES C CXX VERSION 0.3.0) option(PD_BUILD_TESTS "Sets if TestApp and TestBench get build" OFF) diff --git a/include/pd/ui7/container/image.hpp b/include/pd/ui7/container/image.hpp index 784b6bf..60d772e 100644 --- a/include/pd/ui7/container/image.hpp +++ b/include/pd/ui7/container/image.hpp @@ -37,9 +37,10 @@ class Image : public Container { * @param img Image Texture Reference * @param size Custom Size of the Image */ - Image(Texture::Ref img, vec2 size = 0.f) { + Image(Texture::Ref img, vec2 size = 0.f, LI::Rect uv = vec4(0.f)) { this->img = img; this->newsize = size; + this->cuv = uv; if (size.x() != 0 || size.y() != 0) { this->SetSize(size); } else { @@ -57,6 +58,7 @@ class Image : public Container { private: Texture::Ref img; ///< Texture reference to the Image vec2 newsize = 0.f; ///< New Size + LI::Rect cuv; ///< Custom UV }; } // namespace UI7 } // namespace PD \ No newline at end of file diff --git a/include/pd/ui7/drawlist.hpp b/include/pd/ui7/drawlist.hpp index 183be93..98d07a9 100644 --- a/include/pd/ui7/drawlist.hpp +++ b/include/pd/ui7/drawlist.hpp @@ -69,8 +69,10 @@ class DrawList : public SmartCtor { * @param pos Position * @param img Image Texture Reference * @param size Optional Size of the Image + * @param uv Custom UV coords */ - void AddImage(vec2 pos, Texture::Ref img, vec2 size = 0.f); + void AddImage(vec2 pos, Texture::Ref img, vec2 size = 0.f, + LI::Rect uv = vec4(0.f)); /** * Render a Line from Position A to Position B * @param a Pos a diff --git a/include/pd/ui7/id.hpp b/include/pd/ui7/id.hpp index 304cb12..639604b 100644 --- a/include/pd/ui7/id.hpp +++ b/include/pd/ui7/id.hpp @@ -57,7 +57,10 @@ class ID { ~ID() = default; /** Get The ID Initial Name */ - std::string GetName() const { return name; } + const std::string& GetName() const { return name; } + + /** Getter for the raw 32bit int id */ + const u32& RawID() const { return id; } /** Return the ID when casting to u32 */ operator u32() const { return id; } diff --git a/include/pd/ui7/io.hpp b/include/pd/ui7/io.hpp index 5dc4973..3340841 100644 --- a/include/pd/ui7/io.hpp +++ b/include/pd/ui7/io.hpp @@ -69,19 +69,13 @@ class IO : public SmartCtor { vec2 MenuPadding = 5.f; vec2 FramePadding = 5.f; vec2 ItemSpace = vec2(5.f, 2.f); + u64 DoubleClickTime = 500; // Milliseconds std::vector> DrawListRegestry; DrawList::Ref Back; DrawList::Ref Front; u32 NumVertices = 0; ///< Debug Vertices Num u32 NumIndices = 0; ///< Debug Indices Num - // Layer Rules - int ContextBackLayer = 10; - int MenuBackLayer = 20; - int MenuMainLayer = 30; - int MenuFrontLayer = 40; - int ContextFrontLayer = 50; - // DrawListApi void RegisterDrawList(const UI7::ID& id, DrawList::Ref v) { DrawListRegestry.push_back(std::make_pair(id, v)); @@ -97,8 +91,10 @@ class IO : public SmartCtor { vec2 DragLastPosition = 0; vec4 DragDestination = 0; Timer::Ref DragTime; - bool DragReleased = false; ///< Drag Releaded in Box - bool DragReleasedAW = false; ///< Drag Released Anywhere + u64 DragLastReleased = 0; + bool DragReleased = false; ///< Drag Releaded in Box + bool DragReleasedAW = false; ///< Drag Released Anywhere + bool DragDoubleRelease = false; ///< Double Click /** Check if an object is Dragged already */ bool IsObjectDragged() const { return DraggedObject != 0; } /** @@ -147,6 +143,13 @@ class IO : public SmartCtor { // and Only if still in Box DragReleased = Ren->InBox(Inp->TouchPosLast(), area); DragReleasedAW = true; // Advanced + u64 d_rel = Sys::GetTime(); + if (d_rel - DragLastReleased < DoubleClickTime) { + DragDoubleRelease = true; + DragLastReleased = 0; // Set 0 to prevent double exec + } else { + DragLastReleased = d_rel; + } // Ensure timer is paused DragTime->Pause(); DragTime->Reset(); diff --git a/include/pd/ui7/menu.hpp b/include/pd/ui7/menu.hpp index f59ad78..26a6926 100644 --- a/include/pd/ui7/menu.hpp +++ b/include/pd/ui7/menu.hpp @@ -80,7 +80,7 @@ class Menu : public SmartCtor { * @param img Texture reference of the image * @param size a Custom Size if needed */ - void Image(Texture::Ref img, vec2 size = 0.f); + void Image(Texture::Ref img, vec2 size = 0.f, LI::Rect uv = vec4(0)); /** * Color Edit Object that opens a popup editor if clicked diff --git a/include/pd/ui7/theme.hpp b/include/pd/ui7/theme.hpp index 21d8822..2ea7f80 100644 --- a/include/pd/ui7/theme.hpp +++ b/include/pd/ui7/theme.hpp @@ -69,6 +69,11 @@ class Theme : public SmartCtor { * @param theme Theme Reference */ static void Default(Theme& theme); + /** + * White Mode Theme + * @param Theme theme reference + */ + static void Flashbang(Theme& theme); /** Revert the last Color Change */ Theme& Pop() { diff --git a/include/pd/ui7/ui7.hpp b/include/pd/ui7/ui7.hpp index f3c85a6..c1773c1 100644 --- a/include/pd/ui7/ui7.hpp +++ b/include/pd/ui7/ui7.hpp @@ -37,7 +37,7 @@ SOFTWARE. * Major Minor Patch Build * 0x01010000 -> 1.1.0-0 */ -#define UI7_VERSION 0x00020901 +#define UI7_VERSION 0x00030000 namespace PD { namespace UI7 { diff --git a/source/ui7/container/button.cpp b/source/ui7/container/button.cpp index 2c31cc6..58f0378 100644 --- a/source/ui7/container/button.cpp +++ b/source/ui7/container/button.cpp @@ -50,8 +50,10 @@ void Button::Draw() { Assert(io.get() && list.get(), "Did you run Container::Init correctly?"); io->Ren->OnScreen(screen); list->AddRectangle(FinalPos(), size, io->Theme->Get(color)); + list->Layer(list->Layer() + 1); list->AddText(FinalPos() + size * 0.5 - tdim * 0.5, label, io->Theme->Get(UI7Color_Text)); + list->Layer(list->Layer() - 1); } void Button::Update() { diff --git a/source/ui7/container/image.cpp b/source/ui7/container/image.cpp index 3567b70..2d678a9 100644 --- a/source/ui7/container/image.cpp +++ b/source/ui7/container/image.cpp @@ -29,7 +29,7 @@ void Image::Draw() { Assert(io.get() && list.get(), "Did you run Container::Init correctly?"); Assert(img.get(), "Image is nullptr!"); io->Ren->OnScreen(screen); - list->AddImage(FinalPos(), img, newsize); + list->AddImage(FinalPos(), img, newsize, this->cuv); } } // namespace UI7 } // namespace PD \ No newline at end of file diff --git a/source/ui7/drawlist.cpp b/source/ui7/drawlist.cpp index e3835ee..f9155e1 100644 --- a/source/ui7/drawlist.cpp +++ b/source/ui7/drawlist.cpp @@ -95,28 +95,11 @@ void DrawList::AddText(vec2 pos, const std::string& text, const UI7Color& clr, ren->CurrentScreen()->ScreenType() == Screen::Bottom, it)); } e->GetRawObject()->ReCopy(); - - ////// STILL LEAVING THE OLD CODE BELOW AS IT IS MAYBE NEEDED ////// - ////// IF STATIC TEXT SYSTEM SHOULD HAVE AN DISABLE OPTION ////// - - // Dont create a Command here as TextCommand has autosetup - // cause it needs to generate multiple commands if - // Font uses multiple textures - // Oh and Handle Layer management here as well - // int l = ren->Layer(); - // ren->Layer(base + layer); - // std::vector cmds; - // ren->TextCommand(cmds, pos, clr, text, flags, box); - // ren->Layer(l); - // for (auto c : cmds) { - // commands.push_back( - // std::make_pair(ren->CurrentScreen()->ScreenType() == Screen::Bottom, - // c)); - // } } -void DrawList::AddImage(vec2 pos, Texture::Ref img, vec2 size) { +void DrawList::AddImage(vec2 pos, Texture::Ref img, vec2 size, LI::Rect uv) { size = size == 0.f ? img->GetSize() : size; + uv = (uv.Top() == 0.0f && uv.Bot() == 0.0f) ? img->GetUV() : uv; if (!ren->InBox(pos, size, ren->GetViewport())) { return; } @@ -129,7 +112,7 @@ void DrawList::AddImage(vec2 pos, Texture::Ref img, vec2 size) { cmd->SetScissorMode(LI::ScissorMode_Normal); cmd->ScissorRect(clip_rects.top()); } - ren->QuadCommand(cmd, rect, img->GetUV(), 0xffffffff); + ren->QuadCommand(cmd, rect, uv, 0xffffffff); commands.push_back(std::make_pair( ren->CurrentScreen()->ScreenType() == Screen::Bottom, cmd)); } diff --git a/source/ui7/io.cpp b/source/ui7/io.cpp index 66e4ab5..540f446 100644 --- a/source/ui7/io.cpp +++ b/source/ui7/io.cpp @@ -30,6 +30,7 @@ void UI7::IO::Update() { DragTime->Update(); DragReleased = false; DragReleasedAW = false; + DragDoubleRelease = false; Framerate = 1000.f / Delta; DrawListRegestry.clear(); RegisterDrawList("CtxBackList", Back); diff --git a/source/ui7/menu.cpp b/source/ui7/menu.cpp index 18b785a..1c9a25b 100644 --- a/source/ui7/menu.cpp +++ b/source/ui7/menu.cpp @@ -85,8 +85,8 @@ void UI7::Menu::Checkbox(const std::string& label, bool& v) { r->HandleScrolling(scrolling_off, view_area); } -void UI7::Menu::Image(Texture::Ref img, vec2 size) { - Container::Ref r = ObjectPush(PD::New(img, size)); +void UI7::Menu::Image(Texture::Ref img, vec2 size, LI::Rect uv) { + Container::Ref r = ObjectPush(PD::New(img, size, uv)); r->SetPos(AlignPos(Cursor(), r->GetSize(), view_area, GetAlignment())); CursorMove(r->GetSize()); r->Init(io, main); @@ -538,6 +538,7 @@ bool UI7::Menu::BeginTreeNode(const UI7::ID& id) { } return n->second; } + void UI7::Menu::EndTreeNode() { icursoroff.x() -= 10.f; cursor.x() -= 10; @@ -591,6 +592,9 @@ void UI7::Menu::MoveHandler() { if (has_touch && io->DragObject(name + "tmv", vec4(view_area.xy(), vec2(view_area.z(), tbh)))) { + if (io->DragDoubleRelease) { + is_open = !is_open; + } view_area = vec4(view_area.xy() + (io->DragPosition - io->DragLastPosition), view_area.zw()); @@ -626,7 +630,8 @@ void UI7::Menu::CollapseHandler() { void UI7::Menu::PostScrollHandler() { if (has_touch && io->DragObject(id, view_area) && scrolling[1] && - flags & UI7MenuFlags_VtScrolling) { + flags & UI7MenuFlags_VtScrolling && + max[1] - view_area.w() + io->MenuPadding[1] > 0) { if (io->DragReleased) { scroll_mod = (io->DragPosition - io->DragLastPosition); } else { diff --git a/source/ui7/theme.cpp b/source/ui7/theme.cpp index 0357ed1..cbd1487 100644 --- a/source/ui7/theme.cpp +++ b/source/ui7/theme.cpp @@ -44,5 +44,24 @@ void Theme::Default(Theme& theme) { theme.Set(UI7Color_ListEven, Color("#CCCCCCFF")); theme.Set(UI7Color_ListOdd, Color("#BBBBBBFF")); } + +void Theme::Flashbang(Theme& theme) { + theme.Set(UI7Color_Text, Color("#000000FF")); + theme.Set(UI7Color_TextDead, Color("#333333FF")); + theme.Set(UI7Color_Background, Color("#eeeeeeFF")); + theme.Set(UI7Color_Button, Color("#ccccccFF")); + theme.Set(UI7Color_ButtonDead, Color("#bbbbbbFF")); + theme.Set(UI7Color_ButtonActive, Color("#ccccccFF")); + theme.Set(UI7Color_ButtonHovered, Color("#cbcbcbFF")); + theme.Set(UI7Color_Header, Color("#ddddddFF")); + theme.Set(UI7Color_HeaderDead, Color("#cdcdcdFF")); + theme.Set(UI7Color_Selector, Color("#222222FF")); + theme.Set(UI7Color_Checkmark, Color("#ccccccFF")); + theme.Set(UI7Color_FrameBackground, Color("#aaaaaaFF")); + theme.Set(UI7Color_FrameBackgroundHovered, Color("#909090FF")); + theme.Set(UI7Color_Progressbar, Color("#00FF00FF")); + theme.Set(UI7Color_ListEven, Color("#CCCCCCFF")); + theme.Set(UI7Color_ListOdd, Color("#BBBBBBFF")); +} } // namespace UI7 } // namespace PD \ No newline at end of file diff --git a/source/ui7/ui7.cpp b/source/ui7/ui7.cpp index 8b12af4..496e73c 100644 --- a/source/ui7/ui7.cpp +++ b/source/ui7/ui7.cpp @@ -178,6 +178,18 @@ void UI7::Context::MetricsMenu(bool* show) { m->Label(std::format("NumIndices: {} -> {} Tris", io->NumIndices, io->NumIndices / 3)); m->Label("Menus: " + std::to_string(menus.size())); + if (m->BeginTreeNode("Font")) { + for (u32 i = 0; i <= 0x00ff; i++) { + auto& c = io->Ren->Font()->GetCodepoint(i); + if (!c.invalid()) { + m->Image(c.tex(), c.size(), c.uv()); + if ((i % 15) != 0 || i == 0) { + m->SameLine(); + } + } + } + m->EndTreeNode(); + } m->SeparatorText("TimeTrace"); if (m->BeginTreeNode("Traces (" + std::to_string(Sys::GetTraceMap().size()) + ")")) { @@ -280,6 +292,13 @@ void UI7::Context::StyleEditor(bool* show) { io->ItemSpace += 1; } m->SeparatorText("Theme"); + if (m->Button("Dark")) { + UI7::Theme::Default(*io->Theme.get()); + } + m->SameLine(); + if (m->Button("Flashbang")) { + UI7::Theme::Flashbang(*io->Theme.get()); + } /// Small trick to print without prefix #define ts(x) m->ColorEdit(std::string(#x).substr(9), &io->Theme->GetRef(x)); ts(UI7Color_Background);