Rework Project Ultra
- Added container - Made container the base of Layout - Set Containers theirself as pParent for Elements on Push
This commit is contained in:
+23
-45
@@ -8,7 +8,6 @@
|
||||
#include <pd/ultra/elems/rect.hpp>
|
||||
#include <pd/ultra/elems/text.hpp>
|
||||
#include <pd/ultra/layout.hpp>
|
||||
|
||||
////
|
||||
|
||||
PD::OsCtx* pOs = nullptr;
|
||||
@@ -23,20 +22,6 @@ const char* ResourcePath(const char* in) {
|
||||
#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) {
|
||||
// PD::LogFilter(PD::LogLevel::Warning);
|
||||
Driver drv = Driver::OpenGL3;
|
||||
@@ -65,48 +50,41 @@ int main(int argc, char** argv) {
|
||||
font.LoadTTF(ResourcePath("default.ttf"), 64);
|
||||
pList.SetFont(&font);
|
||||
PD::Ultra::Layout lyt;
|
||||
lyt.GetCanvas().SetVirtualViewport(PD::fvec2(400, 240));
|
||||
lyt.SetViewport(PD::fvec2(1280, 720));
|
||||
lyt.SetFont(font);
|
||||
PD::Ultra::Rect rr(
|
||||
0, 0, 90, 60, PD::Color("#ffff00"), 12.f,
|
||||
UltraAlignment_CenterHorizontal | UltraAlignment_CenterVertical);
|
||||
PD::Ultra::Rect r;
|
||||
r.SetColor(0xff0000ff);
|
||||
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::Image _img(&pTex, 10, 10, 5.f, UltraAlignment_BotRight);
|
||||
_img.SetSize(90); // Override size
|
||||
lyt.Add(rr);
|
||||
lyt.Add(_img);
|
||||
txt.SetPosition(0);
|
||||
txt.SetColor(0xffffffff);
|
||||
txt.SetText("const std::string &text");
|
||||
txt.SetAlignment(UltraAlignment_TopLeft);
|
||||
lyt.Add(txt);
|
||||
txt.SetPosition(PD::fvec2(5, 200));
|
||||
txt.SetText("OpenGL");
|
||||
txt.SetColor(PD::Color("#ffffffff"));
|
||||
lyt.Push(&txt);
|
||||
while (pOs->Mainloop()) {
|
||||
lyt.GetCanvas().SetViewport(pOs->GetViewport());
|
||||
pOs->ClearViewPort();
|
||||
PD::Li::ResetPools();
|
||||
pList.SetFontscale(lyt.GetCanvas().VTranslateFontscale(0.7f));
|
||||
pList.DrawRectFilled(150, 50, 0x88ffffff);
|
||||
pList.DrawRect(150, 50, 0xffffffff);
|
||||
lyt.Render();
|
||||
/*auto t = lyt.GetCanvas().VTranslateObject(
|
||||
PD::fvec2(5, 30), PD::fvec2(170, 110), UltraAlignment_TopLeft);
|
||||
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(
|
||||
pList.DrawText(
|
||||
5,
|
||||
std::format(
|
||||
"Font Scale: {}\nVP: [{}]\nVIDC: [{}, {}, {}, {}]\nGfxDriver: {}",
|
||||
pList.GetFontScale(), pOs->GetViewport(), PD::Gfx::GetNumVertices(),
|
||||
PD::Gfx::GetNumIndices(), PD::Gfx::GetNumDrawcalls(),
|
||||
PD::Gfx::GetNumCommands(), PD::Gfx::GetDriverName())
|
||||
.c_str(),
|
||||
font, pList, lyt.GetCanvas(), PD::fvec2(5, 5), 0xffffffff,
|
||||
UltraAlignment_BotLeft);
|
||||
0xffffffff);
|
||||
PD::Gfx::Reset();
|
||||
PD::Gfx::Draw(pList);
|
||||
PD::Gfx::Draw(lyt.Data());
|
||||
|
||||
Reference in New Issue
Block a user