Implement VCanvas and Update TextElem
- Text now requires a font and is able to take an individual scale - Container requires &ref for Elements to make sure they always exist - SetViewport now sets the canvas as well - SetBaseViewport Sets the Virtual Canvas Size - Layout Now requires a Drawlist reference in Render function - main.cpp: updated the template
This commit is contained in:
@@ -13,8 +13,10 @@ PD_API bool ElementBase::RevisionUpdate(PD::u32 req) {
|
||||
}
|
||||
PD_API void ElementBase::Update() {
|
||||
if (!pParent) pRenderspace = PD::fvec4(pPos, pPos + pSize);
|
||||
pRenderspace = PD::fvec4(pParent->GetTopLeft() + pPos,
|
||||
pParent->GetTopLeft() + pPos + pSize);
|
||||
pRenderspace = pParent->GetCanvas().VTranslateObject(
|
||||
pParent->GetTopLeft() + pPos, pSize, pAlignment);
|
||||
/*pRenderspace = PD::fvec4(pParent->GetTopLeft() + pPos,
|
||||
pParent->GetTopLeft() + pPos + pSize);*/
|
||||
}
|
||||
} // namespace Ultra
|
||||
} // namespace PD
|
||||
@@ -1,9 +1,22 @@
|
||||
#include <pd/ultra/container.hpp>
|
||||
#include <pd/ultra/elems/text.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace Ultra {
|
||||
PD_API void Text::Draw(PD::Li::Drawlist& l) {
|
||||
if (!pFont) return;
|
||||
l.SetFont(pFont);
|
||||
l.DrawText(pRenderspace.TopLeft(), pText.c_str(), pColor);
|
||||
}
|
||||
|
||||
PD_API void Text::Update() {
|
||||
if (!pFont) return;
|
||||
if (!pParent) ElementBase::Update();
|
||||
pRenderspace = pParent->GetCanvas().VTranslateObject(
|
||||
pParent->GetTopLeft() + pPos,
|
||||
pFont->GetTextBounds(pText.c_str(),
|
||||
pParent->GetCanvas().VTranslateFontscale(pScale)),
|
||||
pAlignment, true);
|
||||
}
|
||||
} // namespace Ultra
|
||||
} // namespace PD
|
||||
@@ -3,17 +3,16 @@
|
||||
|
||||
namespace PD {
|
||||
namespace Ultra {
|
||||
PD_API void Layout::SetFont(PD::Li::Font& font) { pList.SetFont(&font); }
|
||||
|
||||
PD_API void Layout::Render() {
|
||||
pList.Clear();
|
||||
PD_API void Layout::Render(PD::Li::Drawlist& list) {
|
||||
float fc = list.GetFontScale();
|
||||
list.SetFontscale(GetCanvas().VTranslateFontscale(fc));
|
||||
for (auto& it : GetElements()) {
|
||||
it->Update();
|
||||
it->Draw(pList);
|
||||
it->Draw(list);
|
||||
}
|
||||
pList.DrawText(PD::fvec2(5, GetBotLeft().y - 40),
|
||||
std::format("Lyt: [{}]", GetRenderspace()).c_str(),
|
||||
0xffff00ff);
|
||||
list.DrawText(PD::fvec2(5, GetBotLeft().y - 40),
|
||||
std::format("Lyt: [{}]", GetRenderspace()).c_str(), 0xffff00ff);
|
||||
list.SetFontscale(fc);
|
||||
}
|
||||
} // namespace Ultra
|
||||
} // namespace PD
|
||||
Reference in New Issue
Block a user