Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b5321ca1a1
|
||
|
|
4498c2c0fb
|
@@ -0,0 +1,38 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <pd/lithium/lithium.hpp>
|
||||||
|
#include <pd/ultra/elems/element.hpp>
|
||||||
|
|
||||||
|
namespace PD {
|
||||||
|
namespace Ultra {
|
||||||
|
class Container {
|
||||||
|
public:
|
||||||
|
Container() {}
|
||||||
|
Container(const PD::Li::Rect& r) : pRect(r) {}
|
||||||
|
virtual ~Container() {}
|
||||||
|
|
||||||
|
void Push(PD::Ultra::ElementBase* elem) {
|
||||||
|
elem->SetParent(this);
|
||||||
|
pElems.Push(elem);
|
||||||
|
}
|
||||||
|
void Reset() { pElems.ResetFast(); }
|
||||||
|
const PD::Li::Rect& GetRenderspace() const { return pRect; }
|
||||||
|
|
||||||
|
void SetViewport(const PD::fvec2& vp) { pRect = PD::fvec4(PD::fvec2(0), vp); }
|
||||||
|
|
||||||
|
const PD::fvec2 GetTopLeft() const { return pRect.TopLeft(); }
|
||||||
|
const PD::fvec2 GetTopRight() const { return pRect.TopRight(); }
|
||||||
|
const PD::fvec2 GetBotLeft() const { return pRect.BotLeft(); }
|
||||||
|
const PD::fvec2 GetBotRight() const { return pRect.BotRight(); }
|
||||||
|
const PD::fvec2 GetSize() const { return pRect.BotRight() - pRect.TopLeft(); }
|
||||||
|
const PD::fvec2 GetPosition() const { return pRect.TopLeft(); }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
PD::Pool<PD::Ultra::ElementBase*>& GetElements() { return pElems; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
PD::Li::Rect pRect;
|
||||||
|
PD::Pool<PD::Ultra::ElementBase*> pElems;
|
||||||
|
};
|
||||||
|
} // namespace Ultra
|
||||||
|
} // namespace PD
|
||||||
@@ -6,6 +6,7 @@
|
|||||||
namespace PD {
|
namespace PD {
|
||||||
namespace Ultra {
|
namespace Ultra {
|
||||||
class Canvas;
|
class Canvas;
|
||||||
|
class Container;
|
||||||
class PD_API ElementBase {
|
class PD_API ElementBase {
|
||||||
public:
|
public:
|
||||||
ElementBase() {}
|
ElementBase() {}
|
||||||
@@ -16,7 +17,6 @@ class PD_API ElementBase {
|
|||||||
* Reset Function (for PD::Pool::FastReset)
|
* Reset Function (for PD::Pool::FastReset)
|
||||||
*/
|
*/
|
||||||
virtual void Reset() {}
|
virtual void Reset() {}
|
||||||
void Update(Canvas& c);
|
|
||||||
|
|
||||||
void SetAlignment(UltraAlignment a) { pAlignment = a; }
|
void SetAlignment(UltraAlignment a) { pAlignment = a; }
|
||||||
void SetPosition(const PD::fvec2& pos) { pPos = pos; }
|
void SetPosition(const PD::fvec2& pos) { pPos = pos; }
|
||||||
@@ -25,13 +25,14 @@ class PD_API ElementBase {
|
|||||||
void SetSize(float w, float h) { pSize = PD::fvec2(w, h); }
|
void SetSize(float w, float h) { pSize = PD::fvec2(w, h); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
friend class Container;
|
||||||
|
void SetParent(Container* c) { pParent = c; }
|
||||||
bool RevisionUpdate(PD::u32 req);
|
bool RevisionUpdate(PD::u32 req);
|
||||||
|
Container* pParent;
|
||||||
PD::u32 pCanvasRev = 0;
|
PD::u32 pCanvasRev = 0;
|
||||||
PD::Li::Rect pRenderspace;
|
|
||||||
UltraAlignment pAlignment = 0;
|
UltraAlignment pAlignment = 0;
|
||||||
PD::fvec2 pPos;
|
PD::fvec2 pPos;
|
||||||
PD::fvec2 pSize;
|
PD::fvec2 pSize;
|
||||||
ElementBase* pParent = nullptr;
|
|
||||||
};
|
};
|
||||||
} // namespace Ultra
|
} // namespace Ultra
|
||||||
} // namespace PD
|
} // namespace PD
|
||||||
@@ -28,10 +28,14 @@ class PD_API Rect : public ElementBase {
|
|||||||
|
|
||||||
void SetColor(const PD::Color& color) { pColor = color; }
|
void SetColor(const PD::Color& color) { pColor = color; }
|
||||||
void SetRounding(float r) { pRounding = r; }
|
void SetRounding(float r) { pRounding = r; }
|
||||||
|
void SetLined(bool v) { pLined = v; }
|
||||||
|
void SetThickness(int v) { pThickness = v; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PD::Color pColor;
|
PD::Color pColor;
|
||||||
float pRounding = 0.f;
|
float pRounding = 0.f;
|
||||||
|
bool pLined = false;
|
||||||
|
int pThickness = 1.f;
|
||||||
};
|
};
|
||||||
} // namespace Ultra
|
} // namespace Ultra
|
||||||
|
|
||||||
|
|||||||
@@ -1,28 +1,23 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <pd/ultra/canvas.hpp>
|
#include <pd/ultra/canvas.hpp>
|
||||||
|
#include <pd/ultra/container.hpp>
|
||||||
#include <pd/ultra/elems/element.hpp>
|
#include <pd/ultra/elems/element.hpp>
|
||||||
|
|
||||||
namespace PD {
|
namespace PD {
|
||||||
namespace Ultra {
|
namespace Ultra {
|
||||||
class PD_API Layout {
|
class PD_API Layout : public Container {
|
||||||
public:
|
public:
|
||||||
Layout() {}
|
Layout() {}
|
||||||
~Layout() {}
|
~Layout() {}
|
||||||
|
|
||||||
void Add(ElementBase& elem);
|
|
||||||
|
|
||||||
void SetFont(PD::Li::Font& font);
|
void SetFont(PD::Li::Font& font);
|
||||||
|
|
||||||
void Render();
|
void Render();
|
||||||
|
|
||||||
const PD::Li::Drawlist& Data() const { return pList; }
|
const PD::Li::Drawlist& Data() const { return pList; }
|
||||||
Canvas& GetCanvas() { return pCanvas; }
|
|
||||||
const Canvas& GetCanvas() const { return pCanvas; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Canvas pCanvas;
|
|
||||||
PD::Pool<ElementBase*> pElements;
|
|
||||||
PD::Li::Drawlist pList;
|
PD::Li::Drawlist pList;
|
||||||
};
|
};
|
||||||
} // namespace Ultra
|
} // namespace Ultra
|
||||||
|
|||||||
@@ -68,15 +68,15 @@ PD_API void Drawlist::PathFastArcToN(const fvec2& c, float r, float amin,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PD_API void Drawlist::PathRect(const fvec2& tl, const fvec2& br, float r) {
|
PD_API void Drawlist::PathRect(const fvec2& tl, const fvec2& br,
|
||||||
if (r == 0.f) {
|
float rounding) {
|
||||||
|
if (rounding == 0.f) {
|
||||||
PathAdd(tl);
|
PathAdd(tl);
|
||||||
PathAdd(vec2(br.x, tl.y));
|
PathAdd(vec2(br.x, tl.y));
|
||||||
PathAdd(br);
|
PathAdd(br);
|
||||||
PathAdd(vec2(tl.x, br.y));
|
PathAdd(vec2(tl.x, br.y));
|
||||||
} else {
|
} else {
|
||||||
float r = std::numeric_limits<float>::max();
|
float r = std::min({rounding, (br.x - tl.x) * 0.5f, (br.y - tl.y) * 0.5f});
|
||||||
r = std::min({r, (br.x - tl.x) * 0.5f, (br.y - tl.y) * 0.5f});
|
|
||||||
/** Calculate Optimal segment count automatically */
|
/** Calculate Optimal segment count automatically */
|
||||||
float corner = M_PI * 0.5f;
|
float corner = M_PI * 0.5f;
|
||||||
int segments = std::max(3, int(std::ceil(corner / (6.0f * M_PI / 180.0f))));
|
int segments = std::max(3, int(std::ceil(corner / (6.0f * M_PI / 180.0f))));
|
||||||
@@ -101,15 +101,15 @@ PD_API void Drawlist::PathRect(const fvec2& tl, const fvec2& br, float r) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PD_API void Drawlist::PathRectEx(const fvec2& tl, const fvec2& br, float r,
|
PD_API void Drawlist::PathRectEx(const fvec2& tl, const fvec2& br,
|
||||||
LiPathRectFlags flags) {
|
float rounding, LiPathRectFlags flags) {
|
||||||
if (r == 0.f) {
|
if (rounding == 0.f) {
|
||||||
PathAdd(tl);
|
PathAdd(tl);
|
||||||
PathAdd(vec2(br.x, tl.y));
|
PathAdd(vec2(br.x, tl.y));
|
||||||
PathAdd(br);
|
PathAdd(br);
|
||||||
PathAdd(vec2(tl.x, br.y));
|
PathAdd(vec2(tl.x, br.y));
|
||||||
} else {
|
} else {
|
||||||
float r = std::min({r, (br.x - tl.x) * 0.5f, (br.y - tl.y) * 0.5f});
|
float r = std::min({rounding, (br.x - tl.x) * 0.5f, (br.y - tl.y) * 0.5f});
|
||||||
/** Calculate Optimal segment count automatically */
|
/** Calculate Optimal segment count automatically */
|
||||||
float corner = M_PI * 0.5f;
|
float corner = M_PI * 0.5f;
|
||||||
int segments = std::max(3, int(std::ceil(corner / (6.0f * M_PI / 180.0f))));
|
int segments = std::max(3, int(std::ceil(corner / (6.0f * M_PI / 180.0f))));
|
||||||
|
|||||||
@@ -11,16 +11,5 @@ PD_API bool ElementBase::RevisionUpdate(PD::u32 req) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PD_API void ElementBase::Update(Canvas& c) {
|
|
||||||
if (RevisionUpdate(c.GetRevision())) {
|
|
||||||
if (pParent) {
|
|
||||||
pRenderspace = c.VTranslateObject(
|
|
||||||
pParent->pRenderspace.TopLeft(),
|
|
||||||
pRenderspace.BotRight() - pRenderspace.TopLeft(), pAlignment, true);
|
|
||||||
} else {
|
|
||||||
pRenderspace = c.VTranslateObject(pPos, pSize, pAlignment);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} // namespace Ultra
|
} // namespace Ultra
|
||||||
} // namespace PD
|
} // namespace PD
|
||||||
@@ -3,9 +3,9 @@
|
|||||||
namespace PD {
|
namespace PD {
|
||||||
namespace Ultra {
|
namespace Ultra {
|
||||||
PD_API void Image::Draw(PD::Li::Drawlist& l) {
|
PD_API void Image::Draw(PD::Li::Drawlist& l) {
|
||||||
l.BindTexture(*pTex);
|
// l.BindTexture(*pTex);
|
||||||
l.PathRect(pRenderspace.TopLeft(), pRenderspace.BotRight(), pRounding);
|
// l.PathRect(pRenderspace.TopLeft(), pRenderspace.BotRight(), pRounding);
|
||||||
l.PathFill(pColor);
|
// l.PathFill(pColor);
|
||||||
}
|
}
|
||||||
} // namespace Ultra
|
} // namespace Ultra
|
||||||
} // namespace PD
|
} // namespace PD
|
||||||
@@ -3,10 +3,12 @@
|
|||||||
namespace PD {
|
namespace PD {
|
||||||
namespace Ultra {
|
namespace Ultra {
|
||||||
PD_API void Rect::Draw(PD::Li::Drawlist& l) {
|
PD_API void Rect::Draw(PD::Li::Drawlist& l) {
|
||||||
l.PathRect(pRenderspace.TopLeft(), pRenderspace.BotRight(), pRounding);
|
l.PathRect(pPos, pPos + pSize, pRounding);
|
||||||
l.PathFill(pColor);
|
if (pLined) {
|
||||||
l.DrawText(pRenderspace.BotRight(), std::to_string(pCanvasRev).c_str(),
|
l.PathStroke(pColor, pThickness, LiDrawFlags_Close);
|
||||||
0xff0000ff);
|
} else {
|
||||||
|
l.PathFill(pColor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} // namespace Ultra
|
} // namespace Ultra
|
||||||
} // namespace PD
|
} // namespace PD
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
namespace PD {
|
namespace PD {
|
||||||
namespace Ultra {
|
namespace Ultra {
|
||||||
PD_API void Text::Draw(PD::Li::Drawlist& l) {
|
PD_API void Text::Draw(PD::Li::Drawlist& l) {
|
||||||
l.DrawText(pRenderspace.TopLeft(), pText.c_str(), pColor);
|
l.DrawText(pPos, pText.c_str(), pColor);
|
||||||
}
|
}
|
||||||
} // namespace Ultra
|
} // namespace Ultra
|
||||||
} // namespace PD
|
} // namespace PD
|
||||||
@@ -2,14 +2,11 @@
|
|||||||
|
|
||||||
namespace PD {
|
namespace PD {
|
||||||
namespace Ultra {
|
namespace Ultra {
|
||||||
PD_API void Layout::Add(ElementBase& elem) { *pElements.Allocate() = &elem; }
|
|
||||||
|
|
||||||
PD_API void Layout::SetFont(PD::Li::Font& font) { pList.SetFont(&font); }
|
PD_API void Layout::SetFont(PD::Li::Font& font) { pList.SetFont(&font); }
|
||||||
|
|
||||||
PD_API void Layout::Render() {
|
PD_API void Layout::Render() {
|
||||||
pList.Clear();
|
pList.Clear();
|
||||||
for (auto& it : pElements) {
|
for (auto& it : GetElements()) {
|
||||||
it->Update(pCanvas);
|
|
||||||
it->Draw(pList);
|
it->Draw(pList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+23
-45
@@ -8,7 +8,6 @@
|
|||||||
#include <pd/ultra/elems/rect.hpp>
|
#include <pd/ultra/elems/rect.hpp>
|
||||||
#include <pd/ultra/elems/text.hpp>
|
#include <pd/ultra/elems/text.hpp>
|
||||||
#include <pd/ultra/layout.hpp>
|
#include <pd/ultra/layout.hpp>
|
||||||
|
|
||||||
////
|
////
|
||||||
|
|
||||||
PD::OsCtx* pOs = nullptr;
|
PD::OsCtx* pOs = nullptr;
|
||||||
@@ -23,20 +22,6 @@ const char* ResourcePath(const char* in) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawTextHaxxed(const char* text, PD::Li::Font& font, PD::Li::Drawlist& l,
|
|
||||||
const PD::Ultra::Canvas& c, const PD::fvec2& pos,
|
|
||||||
const PD::Color& color, UltraAlignment align) {
|
|
||||||
PD::fvec2 bounds = font.GetTextBounds(text, l.GetFontScale());
|
|
||||||
PD::Li::Rect _b = c.VTranslateObject(pos, bounds, align, true);
|
|
||||||
l.UnbindTexture();
|
|
||||||
l.PathRect(_b.TopLeft(), _b.BotRight());
|
|
||||||
l.PathFill(0x30ff00ff);
|
|
||||||
l.PathRect(_b.TopLeft(), _b.BotRight());
|
|
||||||
l.PathStroke(0xffff00ff, 1, LiDrawFlags_Close);
|
|
||||||
l.DrawText(c.VTranslateObject(pos, bounds, align, true).TopLeft(), text,
|
|
||||||
color);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
// PD::LogFilter(PD::LogLevel::Warning);
|
// PD::LogFilter(PD::LogLevel::Warning);
|
||||||
Driver drv = Driver::OpenGL3;
|
Driver drv = Driver::OpenGL3;
|
||||||
@@ -65,48 +50,41 @@ int main(int argc, char** argv) {
|
|||||||
font.LoadTTF(ResourcePath("default.ttf"), 64);
|
font.LoadTTF(ResourcePath("default.ttf"), 64);
|
||||||
pList.SetFont(&font);
|
pList.SetFont(&font);
|
||||||
PD::Ultra::Layout lyt;
|
PD::Ultra::Layout lyt;
|
||||||
lyt.GetCanvas().SetVirtualViewport(PD::fvec2(400, 240));
|
lyt.SetViewport(PD::fvec2(1280, 720));
|
||||||
lyt.SetFont(font);
|
lyt.SetFont(font);
|
||||||
PD::Ultra::Rect rr(
|
PD::Ultra::Rect r;
|
||||||
0, 0, 90, 60, PD::Color("#ffff00"), 12.f,
|
r.SetColor(0xff0000ff);
|
||||||
UltraAlignment_CenterHorizontal | UltraAlignment_CenterVertical);
|
r.SetRounding(10.f);
|
||||||
|
r.SetLined(true);
|
||||||
|
r.SetPosition(250, 150);
|
||||||
|
r.SetSize(100, 70);
|
||||||
|
PD::Ultra::Rect rr;
|
||||||
|
r.SetColor(0xff0000ff);
|
||||||
|
r.SetRounding(10.f);
|
||||||
|
r.SetPosition(250, 150);
|
||||||
|
r.SetSize(100, 70);
|
||||||
|
lyt.Push(&rr);
|
||||||
|
lyt.Push(&r);
|
||||||
PD::Ultra::Text txt;
|
PD::Ultra::Text txt;
|
||||||
PD::Ultra::Image _img(&pTex, 10, 10, 5.f, UltraAlignment_BotRight);
|
txt.SetPosition(PD::fvec2(5, 200));
|
||||||
_img.SetSize(90); // Override size
|
txt.SetText("OpenGL");
|
||||||
lyt.Add(rr);
|
txt.SetColor(PD::Color("#ffffffff"));
|
||||||
lyt.Add(_img);
|
lyt.Push(&txt);
|
||||||
txt.SetPosition(0);
|
|
||||||
txt.SetColor(0xffffffff);
|
|
||||||
txt.SetText("const std::string &text");
|
|
||||||
txt.SetAlignment(UltraAlignment_TopLeft);
|
|
||||||
lyt.Add(txt);
|
|
||||||
while (pOs->Mainloop()) {
|
while (pOs->Mainloop()) {
|
||||||
lyt.GetCanvas().SetViewport(pOs->GetViewport());
|
|
||||||
pOs->ClearViewPort();
|
pOs->ClearViewPort();
|
||||||
PD::Li::ResetPools();
|
PD::Li::ResetPools();
|
||||||
pList.SetFontscale(lyt.GetCanvas().VTranslateFontscale(0.7f));
|
pList.DrawRectFilled(150, 50, 0x88ffffff);
|
||||||
|
pList.DrawRect(150, 50, 0xffffffff);
|
||||||
lyt.Render();
|
lyt.Render();
|
||||||
/*auto t = lyt.GetCanvas().VTranslateObject(
|
pList.DrawText(
|
||||||
PD::fvec2(5, 30), PD::fvec2(170, 110), UltraAlignment_TopLeft);
|
5,
|
||||||
auto icnpos = lyt.GetCanvas().VTranslateObject(
|
|
||||||
PD::fvec2(5, 5), PD::fvec2(60), UltraAlignment_TopRight);
|
|
||||||
pList.PathRect(t.TopLeft(), t.BotRight(),
|
|
||||||
lyt.GetCanvas().VTranslateSize(10).x);
|
|
||||||
pList.PathFill(0xff00ffff);
|
|
||||||
pList.BindTexture(pTex);
|
|
||||||
pList.PathRect(icnpos.TopLeft(), icnpos.BotRight());
|
|
||||||
pList.PathFill(0xffffffff);
|
|
||||||
DrawTextHaxxed("Hello World!", font, pList, lyt.GetCanvas(),
|
|
||||||
PD::fvec2(5, 5), 0xff0000ff, UltraAlignment_TopLeft);*/
|
|
||||||
DrawTextHaxxed(
|
|
||||||
std::format(
|
std::format(
|
||||||
"Font Scale: {}\nVP: [{}]\nVIDC: [{}, {}, {}, {}]\nGfxDriver: {}",
|
"Font Scale: {}\nVP: [{}]\nVIDC: [{}, {}, {}, {}]\nGfxDriver: {}",
|
||||||
pList.GetFontScale(), pOs->GetViewport(), PD::Gfx::GetNumVertices(),
|
pList.GetFontScale(), pOs->GetViewport(), PD::Gfx::GetNumVertices(),
|
||||||
PD::Gfx::GetNumIndices(), PD::Gfx::GetNumDrawcalls(),
|
PD::Gfx::GetNumIndices(), PD::Gfx::GetNumDrawcalls(),
|
||||||
PD::Gfx::GetNumCommands(), PD::Gfx::GetDriverName())
|
PD::Gfx::GetNumCommands(), PD::Gfx::GetDriverName())
|
||||||
.c_str(),
|
.c_str(),
|
||||||
font, pList, lyt.GetCanvas(), PD::fvec2(5, 5), 0xffffffff,
|
0xffffffff);
|
||||||
UltraAlignment_BotLeft);
|
|
||||||
PD::Gfx::Reset();
|
PD::Gfx::Reset();
|
||||||
PD::Gfx::Draw(pList);
|
PD::Gfx::Draw(pList);
|
||||||
PD::Gfx::Draw(lyt.Data());
|
PD::Gfx::Draw(lyt.Data());
|
||||||
|
|||||||
Reference in New Issue
Block a user