diff --git a/include/pd/ultra/elems/element.hpp b/include/pd/ultra/elems/element.hpp index 8628690..55cdaba 100644 --- a/include/pd/ultra/elems/element.hpp +++ b/include/pd/ultra/elems/element.hpp @@ -17,6 +17,7 @@ class PD_API ElementBase { * Reset Function (for PD::Pool::FastReset) */ virtual void Reset() {} + void Update(); void SetAlignment(UltraAlignment a) { pAlignment = a; } void SetPosition(const PD::fvec2& pos) { pPos = pos; } @@ -33,6 +34,7 @@ class PD_API ElementBase { UltraAlignment pAlignment = 0; PD::fvec2 pPos; PD::fvec2 pSize; + PD::Li::Rect pRenderspace; }; } // namespace Ultra } // namespace PD \ No newline at end of file diff --git a/source/ultra/elems/element.cpp b/source/ultra/elems/element.cpp index 40ed798..14b3068 100644 --- a/source/ultra/elems/element.cpp +++ b/source/ultra/elems/element.cpp @@ -1,4 +1,4 @@ -#include +#include #include namespace PD { @@ -11,5 +11,10 @@ PD_API bool ElementBase::RevisionUpdate(PD::u32 req) { return false; } } +PD_API void ElementBase::Update() { + if (!pParent) pRenderspace = PD::fvec4(pPos, pPos + pSize); + pRenderspace = PD::fvec4(pParent->GetTopLeft() + pPos, + pParent->GetTopLeft() + pPos + pSize); +} } // namespace Ultra } // namespace PD \ No newline at end of file diff --git a/source/ultra/elems/image.cpp b/source/ultra/elems/image.cpp index 471a0af..b04e182 100644 --- a/source/ultra/elems/image.cpp +++ b/source/ultra/elems/image.cpp @@ -3,9 +3,9 @@ namespace PD { namespace Ultra { PD_API void Image::Draw(PD::Li::Drawlist& l) { - // l.BindTexture(*pTex); - // l.PathRect(pRenderspace.TopLeft(), pRenderspace.BotRight(), pRounding); - // l.PathFill(pColor); + l.BindTexture(*pTex); + l.PathRect(pRenderspace.TopLeft(), pRenderspace.BotRight(), pRounding); + l.PathFill(pColor); } } // namespace Ultra } // namespace PD \ No newline at end of file diff --git a/source/ultra/elems/rect.cpp b/source/ultra/elems/rect.cpp index 4c5a485..e3d2257 100644 --- a/source/ultra/elems/rect.cpp +++ b/source/ultra/elems/rect.cpp @@ -3,7 +3,7 @@ namespace PD { namespace Ultra { PD_API void Rect::Draw(PD::Li::Drawlist& l) { - l.PathRect(pPos, pPos + pSize, pRounding); + l.PathRect(pRenderspace.TopLeft(), pRenderspace.BotRight(), pRounding); if (pLined) { l.PathStroke(pColor, pThickness, LiDrawFlags_Close); } else { diff --git a/source/ultra/elems/text.cpp b/source/ultra/elems/text.cpp index 0b284af..5680967 100644 --- a/source/ultra/elems/text.cpp +++ b/source/ultra/elems/text.cpp @@ -3,7 +3,7 @@ namespace PD { namespace Ultra { PD_API void Text::Draw(PD::Li::Drawlist& l) { - l.DrawText(pPos, pText.c_str(), pColor); + l.DrawText(pRenderspace.TopLeft(), pText.c_str(), pColor); } } // namespace Ultra } // namespace PD \ No newline at end of file diff --git a/source/ultra/layout.cpp b/source/ultra/layout.cpp index ff2d7f7..07c916b 100644 --- a/source/ultra/layout.cpp +++ b/source/ultra/layout.cpp @@ -1,3 +1,4 @@ +#include #include namespace PD { @@ -7,8 +8,12 @@ PD_API void Layout::SetFont(PD::Li::Font& font) { pList.SetFont(&font); } PD_API void Layout::Render() { pList.Clear(); for (auto& it : GetElements()) { + it->Update(); it->Draw(pList); } + pList.DrawText(PD::fvec2(5, GetBotLeft().y - 40), + std::format("Lyt: [{}]", GetRenderspace()).c_str(), + 0xffff00ff); } } // namespace Ultra } // namespace PD \ No newline at end of file diff --git a/tests/gfx/source/main.cpp b/tests/gfx/source/main.cpp index 9c73d9a..04e6095 100644 --- a/tests/gfx/source/main.cpp +++ b/tests/gfx/source/main.cpp @@ -59,10 +59,10 @@ int main(int argc, char** argv) { 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); + rr.SetColor(0x880000ff); + rr.SetRounding(10.f); + rr.SetPosition(250, 150); + rr.SetSize(100, 70); lyt.Push(&rr); lyt.Push(&r); PD::Ultra::Text txt; @@ -72,6 +72,7 @@ int main(int argc, char** argv) { lyt.Push(&txt); while (pOs->Mainloop()) { pOs->ClearViewPort(); + lyt.SetViewport(pOs->GetViewport()); PD::Li::ResetPools(); pList.DrawRectFilled(150, 50, 0x88ffffff); pList.DrawRect(150, 50, 0xffffffff);