6 Commits
Author SHA1 Message Date
tobid7 3575a6787d hotfix 2025-12-28 21:38:41 +01:00
tobid7 7fc7a2ecb9 QoL Changes
fix timetrace last diff
2025-12-27 23:35:23 +01:00
tobid7 03f65e069f Add TextMapSystem WIP 2025-12-24 18:17:58 +01:00
tobid7 c618c616fe Fix UI7 Crash by safe deleting the elements 2025-12-24 15:05:05 +01:00
tobid7 ac281dc7a9 Update
- Add data getter to DrawList
- Add NoOOS (Out Of screen Rendering) flag to text renderer (requires a textbox)
- UI7 Label Wrapping (optinal and beta)
2025-12-23 19:20:31 +01:00
tobid7 0cb5de882f Fixes and function additions
- Fixed Text pos at NoCollapse flag
- Fix Button Input Api (HandleScrolling after layout Update)
- Add getter for IO and Current Menu
- Add AdObject func wrappers to Menu
2025-12-20 19:25:20 +01:00
16 changed files with 153 additions and 34 deletions
+7 -7
View File
@@ -55,8 +55,7 @@ public:
* @return Average * @return Average
*/ */
u64 GetAverage() { u64 GetAverage() {
if (!num_val) if (!num_val) return 0.f;
return 0.f;
u64 res = 0; u64 res = 0;
for (int i = 0; i < num_val; i++) { for (int i = 0; i < num_val; i++) {
res += val[smart_idx(i)]; res += val[smart_idx(i)];
@@ -69,8 +68,7 @@ public:
* @return Minimum value * @return Minimum value
*/ */
u64 GetMin() { u64 GetMin() {
if (!num_val) if (!num_val) return 0.f;
return 0.f;
u64 res = std::numeric_limits<u64>::max(); u64 res = std::numeric_limits<u64>::max();
for (int i = 0; i < num_val; i++) { for (int i = 0; i < num_val; i++) {
res = std::min(val[smart_idx(i)], res); res = std::min(val[smart_idx(i)], res);
@@ -83,8 +81,7 @@ public:
* @return Max Value * @return Max Value
*/ */
u64 GetMax() { u64 GetMax() {
if (!num_val) if (!num_val) return 0.f;
return 0.f;
u64 res = 0; u64 res = 0;
for (int i = 0; i < num_val; i++) { for (int i = 0; i < num_val; i++) {
res = std::max(val[smart_idx(i)], res); res = std::max(val[smart_idx(i)], res);
@@ -185,6 +182,7 @@ public:
*/ */
void SetEnd(u64 v) { void SetEnd(u64 v) {
end = v; end = v;
diff = end - start;
protocol->Add(GetLastDiff()); protocol->Add(GetLastDiff());
} }
/** /**
@@ -197,7 +195,7 @@ public:
* Get Last Diffrence between end and start * Get Last Diffrence between end and start
* @return end - start * @return end - start
*/ */
u64 GetLastDiff() { return end - start; } u64 GetLastDiff() { return diff; }
/** /**
* Get Protcol Reference * Get Protcol Reference
* @return Protocol Ref * @return Protocol Ref
@@ -211,6 +209,8 @@ private:
u64 start; u64 start;
/** End Time */ /** End Time */
u64 end; u64 end;
/** Last Diff */
u64 diff;
/** Protocol */ /** Protocol */
TimeStats::Ref protocol; TimeStats::Ref protocol;
}; };
+1
View File
@@ -94,6 +94,7 @@ class Gfx {
static void BindTex(Li::TexAddress addr) { pGfx->BindTex(addr); } static void BindTex(Li::TexAddress addr) { pGfx->BindTex(addr); }
static void SetViewPort(const ivec2& vp) { pGfx->SetViewPort(vp); } static void SetViewPort(const ivec2& vp) { pGfx->SetViewPort(vp); }
static void SetViewPort(int w, int h) { pGfx->SetViewPort(PD::ivec2(w, h)); }
static void RenderDrawData(const std::vector<Li::Command::Ref>& Commands) { static void RenderDrawData(const std::vector<Li::Command::Ref>& Commands) {
pGfx->RenderDrawData(Commands); pGfx->RenderDrawData(Commands);
+6
View File
@@ -40,6 +40,12 @@ class Command {
IndexBuffer.push_back(VertexBuffer.size() + idx); IndexBuffer.push_back(VertexBuffer.size() + idx);
return *this; return *this;
} }
Command& AddIdxs(const u16& a, const u16& b, const u16& c) {
IndexBuffer.push_back(VertexBuffer.size() + a);
IndexBuffer.push_back(VertexBuffer.size() + b);
IndexBuffer.push_back(VertexBuffer.size() + c);
return *this;
}
Command& AddVtx(const Vertex& v) { Command& AddVtx(const Vertex& v) {
VertexBuffer.push_back(std::move(v)); VertexBuffer.push_back(std::move(v));
+9
View File
@@ -68,6 +68,12 @@ class PD_LITHIUM_API DrawList {
* @param list DrawList to move into current * @param list DrawList to move into current
*/ */
void Merge(DrawList::Ref list); void Merge(DrawList::Ref list);
/**
* Copy another drawlist to this drawist.
* This is important for static prerendered Drawlists
* @param list DrawList Reference to copy from
*/
void Copy(DrawList::Ref list);
/** /**
* Optimize a Drawlist to a more or less perfect order * Optimize a Drawlist to a more or less perfect order
* to reduce drawcall overhead... This function also uses * to reduce drawcall overhead... This function also uses
@@ -80,6 +86,8 @@ class PD_LITHIUM_API DrawList {
void Clear(); void Clear();
void Layer(int l) { this->pLayer = l; } void Layer(int l) { this->pLayer = l; }
int Layer() { return this->pLayer; } int Layer() { return this->pLayer; }
void LayerUp() { this->pLayer++; }
void LayerDown() { this->pLayer--; }
void SetFont(Font::Ref font) { pCurrentFont = font; } void SetFont(Font::Ref font) { pCurrentFont = font; }
void SetFontScale(float scale) { pFontScale = scale; } void SetFontScale(float scale) { pFontScale = scale; }
@@ -198,6 +206,7 @@ class PD_LITHIUM_API DrawList {
} }
pClipRects.pop(); pClipRects.pop();
} }
const std::vector<Command::Ref>& Data() const { return pDrawList; }
/** One linear Clip rect Setup */ /** One linear Clip rect Setup */
void pClipCmd(Command* cmd); void pClipCmd(Command* cmd);
+14
View File
@@ -39,6 +39,7 @@ enum LiTextFlags_ {
LiTextFlags_Wrap = 1 << 3, ///< Wrap Text: May be runs better with TMS LiTextFlags_Wrap = 1 << 3, ///< Wrap Text: May be runs better with TMS
LiTextFlags_Short = 1 << 4, ///< Short Text: May be runs better with TMS LiTextFlags_Short = 1 << 4, ///< Short Text: May be runs better with TMS
LiTextFlags_Scroll = 1 << 5, ///< Not implemented [scoll text if to long] LiTextFlags_Scroll = 1 << 5, ///< Not implemented [scoll text if to long]
LiTextFlags_NoOOS = 1 << 6, ///< No Out of Screen Rendering
}; };
namespace PD { namespace PD {
@@ -95,6 +96,11 @@ class PD_LITHIUM_API Font {
void CmdTextEx(std::vector<Command::Ref>& cmds, const fvec2& pos, u32 color, void CmdTextEx(std::vector<Command::Ref>& cmds, const fvec2& pos, u32 color,
float scale, const std::string& text, LiTextFlags flags = 0, float scale, const std::string& text, LiTextFlags flags = 0,
const fvec2& box = 0); const fvec2& box = 0);
/**
* Garbage collection for TextMapSystem
*/
void CleanupTMS();
/** /**
* Utility function to create a font atlas * Utility function to create a font atlas
* During TTF loading (Internal and should not be called) * During TTF loading (Internal and should not be called)
@@ -115,6 +121,14 @@ class PD_LITHIUM_API Font {
* **Now using unordered map** * **Now using unordered map**
*/ */
std::unordered_map<u32, Codepoint> CodeMap; std::unordered_map<u32, Codepoint> CodeMap;
/** TMS */
struct TMELEM {
PD::u32 ID;
PD::fvec2 Size;
std::string Text;
u64 TimeStamp;
};
std::unordered_map<u32, TMELEM> pTMS;
}; };
} // namespace Li } // namespace Li
} // namespace PD } // namespace PD
+4
View File
@@ -51,6 +51,10 @@ class PD_UI7_API Label : public Container {
* @note This function is usally called by Menu::Update * @note This function is usally called by Menu::Update
* */ * */
void Draw() override; void Draw() override;
/**
* Override Update func to support Text modifications
*/
void Update() override;
private: private:
fvec2 tdim; ///< Text Size fvec2 tdim; ///< Text Size
+1
View File
@@ -77,6 +77,7 @@ class PD_UI7_API IO {
fvec2 MinSliderDragSize = 10.f; // Min height (Vt) and Min Width (Hz) fvec2 MinSliderDragSize = 10.f; // Min height (Vt) and Min Width (Hz)
bool ShowMenuBorder = true; bool ShowMenuBorder = true;
bool ShowFrameBorder = false; // not implemented yet bool ShowFrameBorder = false; // not implemented yet
bool WrapLabels = false; // Beta state
float OverScrollMod = 0.15f; float OverScrollMod = 0.15f;
u64 DoubleClickTime = 500; // Milliseconds u64 DoubleClickTime = 500; // Milliseconds
std::list<std::pair<UI7::ID, Li::DrawList::Ref>> DrawListRegestry; std::list<std::pair<UI7::ID, Li::DrawList::Ref>> DrawListRegestry;
+2
View File
@@ -103,6 +103,8 @@ class PD_UI7_API Layout {
void Update(); void Update();
fvec2 DbgScrollOffset() { return ScrollOffset; }
private: private:
friend class Menu; friend class Menu;
friend class Context; friend class Context;
+5
View File
@@ -103,6 +103,11 @@ class PD_UI7_API Menu {
void HandleTitlebarActions(); void HandleTitlebarActions();
void DrawBaseLayout(); void DrawBaseLayout();
void AddObject(PD::UI7::Container::Ref obj) { pLayout->AddObject(obj); }
void AddObjectEx(PD::UI7::Container::Ref obj, PD::u32 flags) {
pLayout->AddObjectEx(obj, flags);
}
void Update(); void Update();
/** Data Section */ /** Data Section */
+2
View File
@@ -55,10 +55,12 @@ class PD_UI7_API Context {
PD_SHARED(Context); PD_SHARED(Context);
IO::Ref GetIO() { return pIO; }
void AddViewPort(const ID& id, const ivec4& vp); void AddViewPort(const ID& id, const ivec4& vp);
void UseViewPort(const ID& id); void UseViewPort(const ID& id);
void Update(); void Update();
bool BeginMenu(const ID& id, UI7MenuFlags flags = 0, bool* pShow = nullptr); bool BeginMenu(const ID& id, UI7MenuFlags flags = 0, bool* pShow = nullptr);
Menu::Ref CurrentMenu() { return pCurrent; }
void EndMenu(); void EndMenu();
void AboutMenu(bool* show = nullptr); void AboutMenu(bool* show = nullptr);
void MetricsMenu(bool* show = nullptr); void MetricsMenu(bool* show = nullptr);
+1 -1
View File
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.22) cmake_minimum_required(VERSION 3.22)
## The Core Core Library ## The Core Core Library
project(pd-drivers LANGUAGES CXX VERSION 0.5.1) project(pd-drivers LANGUAGES CXX VERSION 0.6.0)
set(SRC set(SRC
source/hid.cpp source/hid.cpp
+3
View File
@@ -38,6 +38,9 @@ PD_LITHIUM_API void DrawList::Clear() {
pNumVertices = 0; pNumVertices = 0;
pDrawList.clear(); pDrawList.clear();
pPath.clear(); pPath.clear();
if (pCurrentFont) {
pCurrentFont->CleanupTMS();
}
while (!pClipRects.empty()) { while (!pClipRects.empty()) {
pClipRects.pop(); pClipRects.pop();
} }
+52
View File
@@ -196,6 +196,11 @@ PD_LITHIUM_API Font::Codepoint &Font::GetCodepoint(u32 cp) {
} }
PD_LITHIUM_API fvec2 Font::GetTextBounds(const std::string &text, float scale) { PD_LITHIUM_API fvec2 Font::GetTextBounds(const std::string &text, float scale) {
u32 id = PD::FNV1A32(text);
if (pTMS.find(id) != pTMS.end()) {
pTMS[id].TimeStamp = PD::OS::GetTime();
return pTMS[id].Size;
}
// Use wstring for exemple for german äöü // Use wstring for exemple for german äöü
auto wtext = Strings::MakeWstring(text); auto wtext = Strings::MakeWstring(text);
// Create a temp position and offset as [0, 0] // Create a temp position and offset as [0, 0]
@@ -237,6 +242,9 @@ PD_LITHIUM_API fvec2 Font::GetTextBounds(const std::string &text, float scale) {
} }
res.x = std::max(res.x, x); res.x = std::max(res.x, x);
res.y += lh; res.y += lh;
pTMS[id].ID = id;
pTMS[id].Size = res;
pTMS[id].TimeStamp = PD::OS::GetTime();
return res; return res;
} }
@@ -272,6 +280,15 @@ PD_LITHIUM_API void Font::CmdTextEx(std::vector<Command::Ref> &cmds,
} }
for (auto &it : lines) { for (auto &it : lines) {
if (flags & LiTextFlags_NoOOS) {
if (rpos.y + off.y + lh < 0) {
off.y += lh;
continue;
}
if (rpos.y + off.y > box.y && box.y != 0) {
break;
}
}
if (flags & LiTextFlags_Short) { if (flags & LiTextFlags_Short) {
fvec2 tmp_dim; fvec2 tmp_dim;
it = pShortText(it, scale, box - pos, tmp_dim); it = pShortText(it, scale, box - pos, tmp_dim);
@@ -322,6 +339,14 @@ PD_LITHIUM_API void Font::CmdTextEx(std::vector<Command::Ref> &cmds,
PD_LITHIUM_API std::string Font::pWrapText(const std::string &txt, float scale, PD_LITHIUM_API std::string Font::pWrapText(const std::string &txt, float scale,
const PD::fvec2 &max, const PD::fvec2 &max,
PD::fvec2 &dim) { PD::fvec2 &dim) {
u32 id = PD::FNV1A32(txt);
if (pTMS.find(id) != pTMS.end()) {
if (pTMS[id].Text.size()) {
dim = pTMS[id].Size;
pTMS[id].TimeStamp = PD::OS::GetTime();
return pTMS[id].Text;
}
}
std::string ret; std::string ret;
std::string line; std::string line;
int lx = 0; int lx = 0;
@@ -341,12 +366,24 @@ PD_LITHIUM_API std::string Font::pWrapText(const std::string &txt, float scale,
} }
ret += line; ret += line;
dim = GetTextBounds(ret, scale); dim = GetTextBounds(ret, scale);
pTMS[id].ID = id;
pTMS[id].Size = dim;
pTMS[id].Text = ret;
pTMS[id].TimeStamp = PD::OS::GetTime();
return ret; return ret;
} }
PD_LITHIUM_API std::string Font::pShortText(const std::string &txt, float scale, PD_LITHIUM_API std::string Font::pShortText(const std::string &txt, float scale,
const PD::fvec2 &max, const PD::fvec2 &max,
PD::fvec2 &dim) { PD::fvec2 &dim) {
u32 id = PD::FNV1A32(txt);
if (pTMS.find(id) != pTMS.end()) {
if (pTMS[id].Text.size()) {
dim = pTMS[id].Size;
pTMS[id].TimeStamp = PD::OS::GetTime();
return pTMS[id].Text;
}
}
auto test = GetTextBounds(txt, scale); auto test = GetTextBounds(txt, scale);
if (test.x < max.x) { if (test.x < max.x) {
return txt; return txt;
@@ -373,8 +410,23 @@ PD_LITHIUM_API std::string Font::pShortText(const std::string &txt, float scale,
} }
ret += it; ret += it;
} }
pTMS[id].ID = id;
pTMS[id].Size = dim;
pTMS[id].Text = ret;
pTMS[id].TimeStamp = PD::OS::GetTime();
return ret; return ret;
} }
PD_LITHIUM_API void Font::CleanupTMS() {
u64 t = PD::OS::GetTime();
for (auto it = pTMS.begin(); it != pTMS.end();) {
if (t - it->second.TimeStamp > 1000) {
it = pTMS.erase(it);
} else {
it++;
}
}
}
} // namespace Li } // namespace Li
} // namespace PD } // namespace PD
+18 -1
View File
@@ -31,10 +31,27 @@ PD_UI7_API void Label::Draw() {
if (pCLipRectUsed) { if (pCLipRectUsed) {
list->PushClipRect(pClipRect); list->PushClipRect(pClipRect);
} }
list->DrawText(FinalPos(), label, io->Theme->Get(UI7Color_Text)); list->DrawTextEx(FinalPos(), label, io->Theme->Get(UI7Color_Text),
LiTextFlags_NoOOS, PD::fvec2(0, io->CurrentViewPort.w));
if (pCLipRectUsed) { if (pCLipRectUsed) {
list->PopClipRect(); list->PopClipRect();
} }
} }
PD_UI7_API void Label::Update() {
/**
* Todo: This is a hacky workaround
* Needs proper optimisation
* Needs a max size (to support sligning dynaically by the window size)
*/
if (io->WrapLabels) {
this->label =
io->Font->pWrapText(this->label, io->FontScale,
PD::fvec2(io->CurrentViewPort.z - FinalPos().x * 4,
io->CurrentViewPort.w),
this->tdim);
SetSize(tdim);
}
}
} // namespace UI7 } // namespace UI7
} // namespace PD } // namespace PD
+7 -7
View File
@@ -124,15 +124,15 @@ PD_UI7_API void Layout::Update() {
it->Draw(); it->Draw();
} }
} }
std::vector<size_t> tbr;
for (size_t i = 0; i < IDObjects.size(); i++) { for (auto it = IDObjects.begin(); it != IDObjects.end();) {
if (IDObjects[i]->Removable()) { if ((*it)->Removable()) {
tbr.push_back(i); it = IDObjects.erase(it);
} else {
it++;
} }
} }
for (auto& it : tbr) {
IDObjects.erase(IDObjects.begin() + it);
}
Objects.clear(); Objects.clear();
WorkRect = fvec4(fvec2(WorkRect.x, WorkRect.y), Size - IO->MenuPadding); WorkRect = fvec4(fvec2(WorkRect.x, WorkRect.y), Size - IO->MenuPadding);
CursorInit(); CursorInit();
+12 -9
View File
@@ -81,7 +81,9 @@ PD_UI7_API void Menu::Separator() {
pIO->Theme->Get(UI7Color_TextDead)); pIO->Theme->Get(UI7Color_TextDead));
}); });
// Set size before pushing (cause Cursor Move will require it) // Set size before pushing (cause Cursor Move will require it)
r->SetSize(fvec2(pLayout->Size.x - 10, 1)); r->SetSize(fvec2(
pLayout->Size.x - pIO->MenuPadding.x * 2 - pLayout->InitialCursorOffset.x,
1));
pLayout->AddObject(r); pLayout->AddObject(r);
} }
@@ -109,8 +111,9 @@ PD_UI7_API void Menu::SeparatorText(const std::string& label) {
fvec2(pLayout->Size.x, self->GetSize().y)); fvec2(pLayout->Size.x, self->GetSize().y));
}); });
// Set size before pushing (cause Cursor Move will require it) // Set size before pushing (cause Cursor Move will require it)
r->SetSize( r->SetSize(fvec2(
fvec2(pLayout->Size.x - 10, pIO->Font->PixelHeight * pIO->FontScale)); pLayout->Size.x - pIO->MenuPadding.x * 2 - pLayout->InitialCursorOffset.x,
pIO->Font->PixelHeight * pIO->FontScale));
pLayout->AddObject(r); pLayout->AddObject(r);
} }
PD_UI7_API void Menu::HandleFocus() { PD_UI7_API void Menu::HandleFocus() {
@@ -148,7 +151,7 @@ PD_UI7_API void Menu::HandleScrolling() {
pLayout->ScrollOffset.y = std::clamp( pLayout->ScrollOffset.y = std::clamp(
pLayout->ScrollStart.y + pIO->InputHandler->DragSourcePos.y - pLayout->ScrollStart.y + pIO->InputHandler->DragSourcePos.y -
pIO->InputHandler->DragPosition.y, pIO->InputHandler->DragPosition.y,
20.f, pLayout->MaxPosition.y - 220); -20.f, pLayout->MaxPosition.y - 220);
} }
} }
} else { } else {
@@ -279,12 +282,12 @@ PD_UI7_API void Menu::DrawBaseLayout() {
l->pLayer = 21; l->pLayer = 21;
/** Inline if statement to shift the Text if collapse sym is shown */ /** Inline if statement to shift the Text if collapse sym is shown */
/** What the hell is this code btw (didn't found a better way) */ /** What the hell is this code btw (didn't found a better way) */
l->DrawText(self->FinalPos() + fvec2(Flags & UI7MenuFlags_NoClose l->DrawText(self->FinalPos() + fvec2((Flags & UI7MenuFlags_NoCollapse)
? 0 ? pIO->FramePadding.x
: (TitleBarHeight - : (TitleBarHeight -
pIO->FramePadding.y * 2 + pIO->FramePadding.y * 2 +
(io->FramePadding.x * 2)), (io->FramePadding.x * 2)),
0), 2),
pID.GetName(), io->Theme->Get(UI7Color_Text)); pID.GetName(), io->Theme->Get(UI7Color_Text));
}); });
r->SetSize(fvec2(pLayout->GetSize().x, TitleBarHeight)); r->SetSize(fvec2(pLayout->GetSize().x, TitleBarHeight));
@@ -344,11 +347,11 @@ PD_UI7_API void Menu::Update() {
TitleBarHeight = 0.f; TitleBarHeight = 0.f;
pLayout->WorkRect.y = 5.f; pLayout->WorkRect.y = 5.f;
} }
DrawBaseLayout();
pLayout->Update();
if (Flags & UI7MenuFlags_VtScrolling || Flags & UI7MenuFlags_HzScrolling) { if (Flags & UI7MenuFlags_VtScrolling || Flags & UI7MenuFlags_HzScrolling) {
HandleScrolling(); HandleScrolling();
} }
DrawBaseLayout();
pLayout->Update();
} }
PD_UI7_API bool Menu::BeginTreeNode(const ID& id) { PD_UI7_API bool Menu::BeginTreeNode(const ID& id) {