Fix The rest of UI7 Mem leaks
Throw OneFrame living objs into a pool
This commit is contained in:
@@ -111,6 +111,25 @@ class PD_API Container {
|
|||||||
virtual void Draw() {}
|
virtual void Draw() {}
|
||||||
/** Template function to update internal data (if needed) */
|
/** Template function to update internal data (if needed) */
|
||||||
virtual void Update() {}
|
virtual void Update() {}
|
||||||
|
/** Template as well as base func for Pool based Containers */
|
||||||
|
virtual void Reset() {
|
||||||
|
pos = 0;
|
||||||
|
size = 0;
|
||||||
|
parent = nullptr;
|
||||||
|
id = 0;
|
||||||
|
pFlags = 0;
|
||||||
|
skippable = false;
|
||||||
|
rem = false;
|
||||||
|
inp_done = false;
|
||||||
|
pSelected = false;
|
||||||
|
pPressed = false;
|
||||||
|
pPressedTwice = false;
|
||||||
|
pCLipRectUsed = false;
|
||||||
|
pClipRect = 0;
|
||||||
|
io = nullptr;
|
||||||
|
list = nullptr;
|
||||||
|
last_use = 0;
|
||||||
|
}
|
||||||
|
|
||||||
/** Internal function */
|
/** Internal function */
|
||||||
void PreDraw();
|
void PreDraw();
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ namespace UI7 {
|
|||||||
*/
|
*/
|
||||||
class PD_API DynObj : public Container {
|
class PD_API DynObj : public Container {
|
||||||
public:
|
public:
|
||||||
|
DynObj() {}
|
||||||
/**
|
/**
|
||||||
* Button Object constructor
|
* Button Object constructor
|
||||||
* @param label Label of the Button
|
* @param label Label of the Button
|
||||||
@@ -69,6 +70,14 @@ class PD_API DynObj : public Container {
|
|||||||
/** Function to Update Size if framepadding changes */
|
/** Function to Update Size if framepadding changes */
|
||||||
void Update() override;
|
void Update() override;
|
||||||
|
|
||||||
|
void Reset() override {
|
||||||
|
Container::Reset();
|
||||||
|
color = UI7Color_Button;
|
||||||
|
pressed = false;
|
||||||
|
pRenFun = nullptr;
|
||||||
|
pInp = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
UI7Color color = UI7Color_Button; ///< current button color
|
UI7Color color = UI7Color_Button; ///< current button color
|
||||||
bool pressed = false; ///< ispressed value
|
bool pressed = false; ///< ispressed value
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ namespace UI7 {
|
|||||||
*/
|
*/
|
||||||
class PD_API Image : public Container {
|
class PD_API Image : public Container {
|
||||||
public:
|
public:
|
||||||
|
Image() {}
|
||||||
/**
|
/**
|
||||||
* Constructor for the Image Object
|
* Constructor for the Image Object
|
||||||
* @param img Image Texture Reference
|
* @param img Image Texture Reference
|
||||||
@@ -57,6 +58,13 @@ class PD_API Image : public Container {
|
|||||||
* */
|
* */
|
||||||
void Draw() override;
|
void Draw() override;
|
||||||
|
|
||||||
|
void Reset() override {
|
||||||
|
Container::Reset();
|
||||||
|
img = Li::Texture();
|
||||||
|
newsize = 0.f;
|
||||||
|
cuv = Li::Rect();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Li::Texture img; ///< Texture
|
Li::Texture img; ///< Texture
|
||||||
fvec2 newsize = 0.f; ///< New Size
|
fvec2 newsize = 0.f; ///< New Size
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ namespace UI7 {
|
|||||||
*/
|
*/
|
||||||
class PD_API Label : public Container {
|
class PD_API Label : public Container {
|
||||||
public:
|
public:
|
||||||
|
Label() {}
|
||||||
/**
|
/**
|
||||||
* Constructor for Label Object
|
* Constructor for Label Object
|
||||||
* @param label Label [Text] to Draw
|
* @param label Label [Text] to Draw
|
||||||
@@ -54,6 +55,13 @@ class PD_API Label : public Container {
|
|||||||
*/
|
*/
|
||||||
void Update() override;
|
void Update() override;
|
||||||
|
|
||||||
|
void Reset() override {
|
||||||
|
Container::Reset();
|
||||||
|
tdim = 0;
|
||||||
|
color = UI7Color_Text;
|
||||||
|
label.clear();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
fvec2 tdim; ///< Text Size
|
fvec2 tdim; ///< Text Size
|
||||||
UI7Color color = UI7Color_Text; ///< Color
|
UI7Color color = UI7Color_Text; ///< Color
|
||||||
|
|||||||
+10
-7
@@ -31,16 +31,14 @@ SOFTWARE.
|
|||||||
#include <pd/ui7/viewport.hpp>
|
#include <pd/ui7/viewport.hpp>
|
||||||
|
|
||||||
namespace PD {
|
namespace PD {
|
||||||
class Context;
|
|
||||||
namespace UI7 {
|
namespace UI7 {
|
||||||
|
class Label;
|
||||||
|
class Image;
|
||||||
|
class DynObj;
|
||||||
class PD_API IO {
|
class PD_API IO {
|
||||||
public:
|
public:
|
||||||
IO() : DeltaStats(60), CurrentViewPort("", 0) {
|
IO();
|
||||||
/** Probably not the best solution i guess */
|
~IO();
|
||||||
// CurrentViewPort =
|
|
||||||
// ViewPort::New("Default", ivec4(ivec2(0, 0), pCtx.Gfx()->ViewPort));
|
|
||||||
}
|
|
||||||
~IO() {}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* IO Update Internal Variables
|
* IO Update Internal Variables
|
||||||
@@ -84,6 +82,11 @@ class PD_API IO {
|
|||||||
u32 NumIndices = 0; ///< Debug Indices Num
|
u32 NumIndices = 0; ///< Debug Indices Num
|
||||||
std::vector<u32> MenuOrder;
|
std::vector<u32> MenuOrder;
|
||||||
|
|
||||||
|
// Pools
|
||||||
|
PD::Pool<UI7::Label> LabelPool;
|
||||||
|
PD::Pool<UI7::Image> ImagePool;
|
||||||
|
PD::Pool<UI7::DynObj> DynObjPool;
|
||||||
|
|
||||||
// DrawlistApi
|
// DrawlistApi
|
||||||
void RegisterDrawlist(const UI7::ID& id, Li::Drawlist* v) {
|
void RegisterDrawlist(const UI7::ID& id, Li::Drawlist* v) {
|
||||||
DrawlistRegestry.push_back(std::make_pair(id, v));
|
DrawlistRegestry.push_back(std::make_pair(id, v));
|
||||||
|
|||||||
@@ -53,26 +53,27 @@ PD_API void ColorEdit::Draw() {
|
|||||||
layout = new UI7::Layout(GetID(), *io);
|
layout = new UI7::Layout(GetID(), *io);
|
||||||
}
|
}
|
||||||
layout->SetPosition(FinalPos());
|
layout->SetPosition(FinalPos());
|
||||||
layout->AddObjectEx(
|
DynObj* r = io->DynObjPool.Allocate();
|
||||||
new DynObj([=, this](UI7::IO* io, Li::Drawlist* l, Container* thiz) {
|
*r = UI7::DynObj([=, this](UI7::IO* io, Li::Drawlist* l, Container* thiz) {
|
||||||
thiz->SetSize(layout->GetSize());
|
thiz->SetSize(layout->GetSize());
|
||||||
// l->Layer(30);
|
// l->Layer(30);
|
||||||
l->PathRect(thiz->GetPos(), thiz->GetPos() + thiz->GetSize(),
|
l->PathRect(thiz->GetPos(), thiz->GetPos() + thiz->GetSize(),
|
||||||
io->FrameRounding);
|
io->FrameRounding);
|
||||||
l->PathFill(io->Theme.Get(UI7Color_FrameBackground));
|
l->PathFill(io->Theme.Get(UI7Color_FrameBackground));
|
||||||
}),
|
});
|
||||||
UI7LytAdd_Front | UI7LytAdd_NoCursorUpdate | UI7LytAdd_NoScrollHandle);
|
layout->AddObjectEx(r, UI7LytAdd_Front | UI7LytAdd_NoCursorUpdate |
|
||||||
auto obj =
|
UI7LytAdd_NoScrollHandle);
|
||||||
new DynObj([=, this](UI7::IO* io, Li::Drawlist* l, Container* thiz) {
|
r = io->DynObjPool.Allocate();
|
||||||
l->PathRect(thiz->FinalPos(), thiz->FinalPos() + io->ItemRowHeight,
|
*r = UI7::DynObj([=, this](UI7::IO* io, Li::Drawlist* l, Container* thiz) {
|
||||||
io->FrameRounding);
|
l->PathRect(thiz->FinalPos(), thiz->FinalPos() + io->ItemRowHeight,
|
||||||
l->PathFill(*color_ref);
|
io->FrameRounding);
|
||||||
l->DrawText(
|
l->PathFill(*color_ref);
|
||||||
thiz->FinalPos() + fvec2(io->ItemSpace.x + io->ItemRowHeight, 0),
|
l->DrawText(
|
||||||
label.c_str(), io->Theme.Get(UI7Color_Text));
|
thiz->FinalPos() + fvec2(io->ItemSpace.x + io->ItemRowHeight, 0),
|
||||||
});
|
label.c_str(), io->Theme.Get(UI7Color_Text));
|
||||||
obj->SetSize(PD::fvec2(200, io->ItemRowHeight));
|
});
|
||||||
layout->AddObject(obj);
|
r->SetSize(PD::fvec2(200, io->ItemRowHeight));
|
||||||
|
layout->AddObject(r);
|
||||||
layout->Label("RGBA: ({}, {}, {}, {})", *((u8*)color_ref),
|
layout->Label("RGBA: ({}, {}, {}, {})", *((u8*)color_ref),
|
||||||
*(((u8*)color_ref) + 1), *(((u8*)color_ref) + 2),
|
*(((u8*)color_ref) + 1), *(((u8*)color_ref) + 2),
|
||||||
*(((u8*)color_ref) + 3));
|
*(((u8*)color_ref) + 3));
|
||||||
|
|||||||
@@ -23,9 +23,22 @@ SOFTWARE.
|
|||||||
|
|
||||||
#include <pd/core/core.hpp>
|
#include <pd/core/core.hpp>
|
||||||
#include <pd/drivers/drivers.hpp>
|
#include <pd/drivers/drivers.hpp>
|
||||||
|
#include <pd/ui7/containers.hpp>
|
||||||
#include <pd/ui7/io.hpp>
|
#include <pd/ui7/io.hpp>
|
||||||
|
|
||||||
namespace PD {
|
namespace PD {
|
||||||
|
|
||||||
|
PD_API UI7::IO::IO() : DeltaStats(60), CurrentViewPort("", 0) {
|
||||||
|
/** Probably not the best solution i guess */
|
||||||
|
// CurrentViewPort =
|
||||||
|
// ViewPort::New("Default", ivec4(ivec2(0, 0), pCtx.Gfx()->ViewPort));
|
||||||
|
// Start a little larger on these
|
||||||
|
LabelPool.Init(512);
|
||||||
|
DynObjPool.Init(512);
|
||||||
|
}
|
||||||
|
|
||||||
|
PD_API UI7::IO::~IO() {}
|
||||||
|
|
||||||
PD_API void UI7::IO::Update() {
|
PD_API void UI7::IO::Update() {
|
||||||
/** Todo: find out if we even still use the Drawlist regestry */
|
/** Todo: find out if we even still use the Drawlist regestry */
|
||||||
u64 current = PD::Os::GetTimeNano();
|
u64 current = PD::Os::GetTimeNano();
|
||||||
@@ -41,5 +54,8 @@ PD_API void UI7::IO::Update() {
|
|||||||
// RegisterDrawList("CtxBackList", Back);
|
// RegisterDrawList("CtxBackList", Back);
|
||||||
NumIndices = 0; // FDL.pNumIndices;
|
NumIndices = 0; // FDL.pNumIndices;
|
||||||
NumVertices = 0; // FDL.pNumVertices;
|
NumVertices = 0; // FDL.pNumVertices;
|
||||||
|
LabelPool.ResetFast();
|
||||||
|
DynObjPool.ResetFast();
|
||||||
|
ImagePool.ResetFast();
|
||||||
}
|
}
|
||||||
} // namespace PD
|
} // namespace PD
|
||||||
@@ -161,7 +161,8 @@ PD_API void Layout::Update() {
|
|||||||
|
|
||||||
PD_API void Layout::Label(const std::string& label) {
|
PD_API void Layout::Label(const std::string& label) {
|
||||||
// Layout API
|
// Layout API
|
||||||
auto r = new UI7::Label(label, IO);
|
auto r = IO.LabelPool.Allocate();
|
||||||
|
*r = UI7::Label(label, IO);
|
||||||
r->SetClipRect(fvec4(GetPosition(), GetPosition() + GetSize()));
|
r->SetClipRect(fvec4(GetPosition(), GetPosition() + GetSize()));
|
||||||
AddObject(r);
|
AddObject(r);
|
||||||
}
|
}
|
||||||
@@ -192,7 +193,8 @@ PD_API void Layout::Checkbox(const std::string& label, bool& v) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PD_API void Layout::Image(Li::Texture img, fvec2 size, Li::Rect uv) {
|
PD_API void Layout::Image(Li::Texture img, fvec2 size, Li::Rect uv) {
|
||||||
Container* r = new UI7::Image(img, size, uv);
|
auto r = IO.ImagePool.Allocate();
|
||||||
|
*r = UI7::Image(img, size, uv);
|
||||||
AddObject(r);
|
AddObject(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+27
-20
@@ -36,7 +36,8 @@ Menu::Menu(const ID& id, IO& io) : pIO(io), pID(id), pLayout(id, io) {
|
|||||||
|
|
||||||
PD_API void Menu::Label(const std::string& label) {
|
PD_API void Menu::Label(const std::string& label) {
|
||||||
// Layout API
|
// Layout API
|
||||||
auto r = new UI7::Label(label, pIO);
|
auto r = pIO.LabelPool.Allocate();
|
||||||
|
*r = UI7::Label(label, pIO);
|
||||||
pLayout.AddObject(r);
|
pLayout.AddObject(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,7 +69,8 @@ PD_API void Menu::Checkbox(const std::string& label, bool& v) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PD_API void Menu::Image(Li::Texture img, fvec2 size, Li::Rect uv) {
|
PD_API void Menu::Image(Li::Texture img, fvec2 size, Li::Rect uv) {
|
||||||
Container* r = new UI7::Image(img, size, uv);
|
auto r = pIO.ImagePool.Allocate();
|
||||||
|
*r = UI7::Image(img, size, uv);
|
||||||
pLayout.AddObject(r);
|
pLayout.AddObject(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,8 +86,9 @@ PD_API void Menu::ColorEdit(const std::string& label, u32& clr) {
|
|||||||
|
|
||||||
PD_API void Menu::Separator() {
|
PD_API void Menu::Separator() {
|
||||||
// Dynamic Objects are very simple...
|
// Dynamic Objects are very simple...
|
||||||
Container* r =
|
DynObj* r = pIO.DynObjPool.Allocate();
|
||||||
new DynObj([=, this](UI7::IO* io, Li::Drawlist* l, UI7::Container* self) {
|
*r = UI7::DynObj(
|
||||||
|
[=, this](UI7::IO* io, Li::Drawlist* l, UI7::Container* self) {
|
||||||
l->DrawRectFilled(self->FinalPos(), self->GetSize(),
|
l->DrawRectFilled(self->FinalPos(), self->GetSize(),
|
||||||
pIO.Theme.Get(UI7Color_TextDead));
|
pIO.Theme.Get(UI7Color_TextDead));
|
||||||
});
|
});
|
||||||
@@ -98,8 +101,9 @@ PD_API void Menu::Separator() {
|
|||||||
|
|
||||||
PD_API void Menu::SeparatorText(const std::string& label) {
|
PD_API void Menu::SeparatorText(const std::string& label) {
|
||||||
// Also note to use [=] instead of [&] to not undefined access label
|
// Also note to use [=] instead of [&] to not undefined access label
|
||||||
Container* r = new DynObj([=, this](UI7::IO* io, Li::Drawlist* l,
|
DynObj* r = pIO.DynObjPool.Allocate();
|
||||||
UI7::Container* self) {
|
*r = UI7::DynObj([=, this](UI7::IO* io, Li::Drawlist* l,
|
||||||
|
UI7::Container* self) {
|
||||||
fvec2 size = self->GetSize();
|
fvec2 size = self->GetSize();
|
||||||
fvec2 tdim = io->Font->GetTextBounds(label.c_str(), io->FontScale);
|
fvec2 tdim = io->Font->GetTextBounds(label.c_str(), io->FontScale);
|
||||||
fvec2 pos = self->FinalPos();
|
fvec2 pos = self->FinalPos();
|
||||||
@@ -251,14 +255,14 @@ PD_API void Menu::DrawBaseLayout() {
|
|||||||
if (pIsOpen) {
|
if (pIsOpen) {
|
||||||
/** Resize Sym (Render on Top of Everything) */
|
/** Resize Sym (Render on Top of Everything) */
|
||||||
if (!(Flags & UI7MenuFlags_NoResize)) {
|
if (!(Flags & UI7MenuFlags_NoResize)) {
|
||||||
Container* r =
|
DynObj* r = pIO.DynObjPool.Allocate();
|
||||||
new DynObj([](IO* io, Li::Drawlist* l, UI7::Container* self) {
|
*r = UI7::DynObj([](IO* io, Li::Drawlist* l, UI7::Container* self) {
|
||||||
// //l->Layer(1);
|
// //l->Layer(1);
|
||||||
l->PathAdd(self->FinalPos() + self->GetSize() - fvec2(0, 20));
|
l->PathAdd(self->FinalPos() + self->GetSize() - fvec2(0, 20));
|
||||||
l->PathAdd(self->FinalPos() + self->GetSize());
|
l->PathAdd(self->FinalPos() + self->GetSize());
|
||||||
l->PathAdd(self->FinalPos() + self->GetSize() - fvec2(20, 0));
|
l->PathAdd(self->FinalPos() + self->GetSize() - fvec2(20, 0));
|
||||||
l->PathFill(io->Theme.Get(UI7Color_Button));
|
l->PathFill(io->Theme.Get(UI7Color_Button));
|
||||||
});
|
});
|
||||||
r->SetSize(
|
r->SetSize(
|
||||||
fvec2(pLayout.GetSize().x, pLayout.GetSize().y - TitleBarHeight));
|
fvec2(pLayout.GetSize().x, pLayout.GetSize().y - TitleBarHeight));
|
||||||
r->SetPos(fvec2(0, TitleBarHeight));
|
r->SetPos(fvec2(0, TitleBarHeight));
|
||||||
@@ -267,8 +271,8 @@ PD_API void Menu::DrawBaseLayout() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Background */
|
/** Background */
|
||||||
Container* r = new DynObj([](IO* io, Li::Drawlist* l,
|
DynObj* r = pIO.DynObjPool.Allocate();
|
||||||
UI7::Container* self) {
|
*r = UI7::DynObj([](IO* io, Li::Drawlist* l, UI7::Container* self) {
|
||||||
// l->Layer(0);
|
// l->Layer(0);
|
||||||
l->PathRectEx(self->FinalPos(), self->FinalPos() + self->GetSize(), 10.f,
|
l->PathRectEx(self->FinalPos(), self->FinalPos() + self->GetSize(), 10.f,
|
||||||
LiPathRectFlags_KeepTop | LiPathRectFlags_KeepBot);
|
LiPathRectFlags_KeepTop | LiPathRectFlags_KeepBot);
|
||||||
@@ -284,7 +288,8 @@ PD_API void Menu::DrawBaseLayout() {
|
|||||||
UI7LytAdd_Front);
|
UI7LytAdd_Front);
|
||||||
}
|
}
|
||||||
if (!(Flags & UI7MenuFlags_NoTitlebar)) {
|
if (!(Flags & UI7MenuFlags_NoTitlebar)) {
|
||||||
Container* r = new DynObj(
|
DynObj* r = pIO.DynObjPool.Allocate();
|
||||||
|
*r = UI7::DynObj(
|
||||||
[=, this](UI7::IO* io, Li::Drawlist* l, UI7::Container* self) {
|
[=, this](UI7::IO* io, Li::Drawlist* l, UI7::Container* self) {
|
||||||
// l->Layer(20);
|
// l->Layer(20);
|
||||||
/** Header Bar */
|
/** Header Bar */
|
||||||
@@ -307,8 +312,9 @@ PD_API void Menu::DrawBaseLayout() {
|
|||||||
|
|
||||||
/** Collapse Sym */
|
/** Collapse Sym */
|
||||||
if (!(Flags & UI7MenuFlags_NoCollapse)) {
|
if (!(Flags & UI7MenuFlags_NoCollapse)) {
|
||||||
r = new DynObj([=, this](UI7::IO* io, Li::Drawlist* l,
|
DynObj* r = pIO.DynObjPool.Allocate();
|
||||||
UI7::Container* self) {
|
*r = UI7::DynObj([=, this](UI7::IO* io, Li::Drawlist* l,
|
||||||
|
UI7::Container* self) {
|
||||||
/** This sym actually requires layer 21 (i dont know why) */
|
/** This sym actually requires layer 21 (i dont know why) */
|
||||||
// l->Layer(21);
|
// l->Layer(21);
|
||||||
/**
|
/**
|
||||||
@@ -383,7 +389,8 @@ PD_API bool Menu::BeginTreeNode(const ID& id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Object
|
// Object
|
||||||
auto r = new DynObj([=, this](IO* io, Li::Drawlist* l, Container* self) {
|
DynObj* r = pIO.DynObjPool.Allocate();
|
||||||
|
*r = UI7::DynObj([=, this](IO* io, Li::Drawlist* l, Container* self) {
|
||||||
fvec2 ts = self->FinalPos() + fvec2(0, 7);
|
fvec2 ts = self->FinalPos() + fvec2(0, 7);
|
||||||
fvec2 pl[2] = {fvec2(10, 5), fvec2(0, 10)};
|
fvec2 pl[2] = {fvec2(10, 5), fvec2(0, 10)};
|
||||||
if (n->second) {
|
if (n->second) {
|
||||||
|
|||||||
Reference in New Issue
Block a user