More stuff done at Project Ultra

- Added renderspace
- Revision System (to not always update pRenderspace
- added some test scene
This commit is contained in:
2026-03-28 13:52:36 +01:00
parent 784421fa6c
commit 2e652a3c24
14 changed files with 192 additions and 33 deletions
+38 -2
View File
@@ -2,9 +2,9 @@
namespace PD {
namespace Ultra {
PD_API Canvas::Canvas() {}
PD_API Canvas::Canvas() { pRev = 0; }
PD_API Canvas::Canvas(const PD::fvec2& size) : pViewport(size) {}
PD_API Canvas::Canvas(const PD::fvec2& size) : pViewport(size) { pRev = 0; }
PD_API Canvas::~Canvas() {}
@@ -15,9 +15,11 @@ PD_API void Canvas::SetVirtualViewport(const PD::fvec2& size) {
pViewport.y / pVirtualViewPort.y);
pVoff = (pViewport - (pVirtualViewPort * pVfactor)) * 0.5f;
}
pRev++;
}
PD_API void Canvas::SetViewport(const PD::fvec2& size) {
if (pViewport == size) return;
pViewport = size;
SetVirtualViewport(pVirtualViewPort); // recalculate Vfactor
}
@@ -55,6 +57,8 @@ PD_API PD::Li::Rect Canvas::VTranslateObject(const PD::fvec2& pos,
final.x = pos.x * pVfactor;
} else if (align & UltraAlignment_Right) {
final.x = pViewport.x - (pos.x * pVfactor) - nsize.x;
} else if (align & UltraAlignment_CenterHorizontal) {
final.x = pViewport.x * 0.5 - nsize.x * 0.5 + pos.x * pVfactor;
} else {
final.x = pVoff.x + (pos.x * pVfactor) - nsize.x * 0.5;
}
@@ -62,17 +66,49 @@ PD_API PD::Li::Rect Canvas::VTranslateObject(const PD::fvec2& pos,
final.y = pos.y * pVfactor;
} else if (align & UltraAlignment_Bot) {
final.y = pViewport.y - (pos.y * pVfactor) - nsize.y;
} else if (align & UltraAlignment_CenterVertical) {
final.y = pViewport.y * 0.5 - nsize.y * 0.5 + pos.y * pVfactor;
} else {
final.y = pVoff.y + (pos.y * pVfactor) - nsize.y * 0.5;
}
return PD::fvec4(final, final + nsize);
}
PD_API PD::Li::Rect Canvas::TranslateObject(const PD::fvec2& pos,
const PD::fvec2& size,
UltraAlignment align,
bool size_modified) const {
PD::fvec2 nsize = size;
if (!size_modified) nsize *= pViewport;
PD::fvec2 final;
if (align & UltraAlignment_Left) {
final.x = pos.x * pViewport.x;
} else if (align & UltraAlignment_Right) {
final.x = pViewport.x - (pos.x * pViewport.x) - nsize.x;
} else if (align & UltraAlignment_CenterHorizontal) {
final.x = pViewport.x * 0.5 - nsize.x * 0.5 + pos.x * pViewport.x;
} else {
final.x = pVoff.x + (pos.x * pViewport.x) - nsize.x * 0.5;
}
if (align & UltraAlignment_Top) {
final.y = pos.y * pViewport.y;
} else if (align & UltraAlignment_Bot) {
final.y = pViewport.y - (pos.y * pViewport.y) - nsize.y;
} else if (align & UltraAlignment_CenterVertical) {
final.y = pViewport.y * 0.5 - nsize.y * 0.5 + pos.y * pViewport.y;
} else {
final.y = pVoff.y + (pos.y * pViewport.y) - nsize.y * 0.5;
}
return PD::fvec4(final, final + nsize);
}
PD_API PD::fvec2 Canvas::VTranslateAlignPos(const PD::fvec2& pos,
const PD::fvec2& size,
UltraAlignment align) const {
return VTranslateObject(pos, size, align).TopLeft();
}
PD_API const PD::u32& Canvas::GetRevision() const { return pRev; }
} // namespace Ultra
} // namespace PD
+26
View File
@@ -0,0 +1,26 @@
#include <pd/ultra/canvas.hpp>
#include <pd/ultra/elems/element.hpp>
namespace PD {
namespace Ultra {
PD_API bool ElementBase::RevisionUpdate(PD::u32 req) {
if (req != pCanvasRev) {
pCanvasRev = req;
return true;
} else {
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 PD
+11
View File
@@ -0,0 +1,11 @@
#include <pd/ultra/elems/image.hpp>
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);
}
} // namespace Ultra
} // namespace PD
+3 -1
View File
@@ -3,8 +3,10 @@
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);
l.PathFill(pColor);
l.DrawText(pRenderspace.BotRight(), std::to_string(pCanvasRev).c_str(),
0xff0000ff);
}
} // namespace Ultra
} // namespace PD
+1 -1
View File
@@ -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
+1
View File
@@ -9,6 +9,7 @@ PD_API void Layout::SetFont(PD::Li::Font& font) { pList.SetFont(&font); }
PD_API void Layout::Render() {
pList.Clear();
for (auto& it : pElements) {
it->Update(pCanvas);
it->Draw(pList);
}
}