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:
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <pd/lithium/lithium.hpp>
|
||||
#include <pd/ultra/canvas.hpp>
|
||||
#include <pd/ultra/elems/element.hpp>
|
||||
|
||||
namespace PD {
|
||||
@@ -11,14 +12,18 @@ class Container {
|
||||
Container(const PD::Li::Rect& r) : pRect(r) {}
|
||||
virtual ~Container() {}
|
||||
|
||||
void Push(PD::Ultra::ElementBase* elem) {
|
||||
elem->SetParent(this);
|
||||
pElems.Push(elem);
|
||||
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); }
|
||||
void SetViewport(const PD::fvec2& vp) {
|
||||
pCanvas.SetViewport(vp);
|
||||
pRect = PD::fvec4(PD::fvec2(0), vp);
|
||||
}
|
||||
void SetBaseViewport(const PD::ivec2& vp) { pCanvas.SetVirtualViewport(vp); }
|
||||
|
||||
const PD::fvec2 GetTopLeft() const { return pRect.TopLeft(); }
|
||||
const PD::fvec2 GetTopRight() const { return pRect.TopRight(); }
|
||||
@@ -26,12 +31,14 @@ class Container {
|
||||
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(); }
|
||||
const Canvas& GetCanvas() const { return pCanvas; }
|
||||
|
||||
protected:
|
||||
PD::Pool<PD::Ultra::ElementBase*>& GetElements() { return pElems; }
|
||||
|
||||
private:
|
||||
PD::Li::Rect pRect;
|
||||
Canvas pCanvas;
|
||||
PD::Pool<PD::Ultra::ElementBase*> pElems;
|
||||
};
|
||||
} // namespace Ultra
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <pd/lithium/lithium.hpp>
|
||||
#include <pd/ultra/flags.hpp>
|
||||
|
||||
@@ -7,6 +8,7 @@ namespace PD {
|
||||
namespace Ultra {
|
||||
class Canvas;
|
||||
class Container;
|
||||
using EventFunc = std::function<void()>;
|
||||
class PD_API ElementBase {
|
||||
public:
|
||||
ElementBase() {}
|
||||
@@ -17,24 +19,36 @@ class PD_API ElementBase {
|
||||
* Reset Function (for PD::Pool::FastReset)
|
||||
*/
|
||||
virtual void Reset() {}
|
||||
void Update();
|
||||
virtual void Update();
|
||||
|
||||
void SetAlignment(UltraAlignment a) { pAlignment = a; }
|
||||
void SetPosition(const PD::fvec2& pos) { pPos = pos; }
|
||||
void SetPosition(float x, float y) { pPos = PD::fvec2(x, y); }
|
||||
void SetSize(const PD::fvec2& size) { pSize = size; }
|
||||
void SetSize(float w, float h) { pSize = PD::fvec2(w, h); }
|
||||
/**
|
||||
* Executed every frame
|
||||
* Elemnents can override / discard this func
|
||||
*/
|
||||
virtual void OnHover(EventFunc func) { pHover = func; }
|
||||
/**
|
||||
* Executrd on KeyUp event
|
||||
* Elemnents can override / discard this func
|
||||
*/
|
||||
virtual void OnPress(EventFunc func) { pPress = func; }
|
||||
|
||||
protected:
|
||||
friend class Container;
|
||||
void SetParent(Container* c) { pParent = c; }
|
||||
bool RevisionUpdate(PD::u32 req);
|
||||
Container* pParent;
|
||||
Container* pParent = nullptr;
|
||||
PD::u32 pCanvasRev = 0;
|
||||
UltraAlignment pAlignment = 0;
|
||||
PD::fvec2 pPos;
|
||||
PD::fvec2 pSize;
|
||||
PD::Li::Rect pRenderspace;
|
||||
EventFunc pHover = nullptr;
|
||||
EventFunc pPress = nullptr;
|
||||
};
|
||||
} // namespace Ultra
|
||||
} // namespace PD
|
||||
@@ -11,13 +11,18 @@ class PD_API Text : public ElementBase {
|
||||
~Text() {}
|
||||
|
||||
void Draw(PD::Li::Drawlist& l) override;
|
||||
void Update() override;
|
||||
|
||||
void SetColor(const PD::Color& color) { pColor = color; }
|
||||
void SetText(const std::string& text) { pText = text; }
|
||||
void SetFont(PD::Li::Font& font) { pFont = &font; }
|
||||
void SetScale(float scale) { pScale = scale; }
|
||||
|
||||
private:
|
||||
PD::Color pColor;
|
||||
float pScale = 1.f;
|
||||
std::string pText;
|
||||
PD::Li::Font* pFont = nullptr;
|
||||
};
|
||||
} // namespace Ultra
|
||||
|
||||
|
||||
@@ -11,14 +11,7 @@ class PD_API Layout : public Container {
|
||||
Layout() {}
|
||||
~Layout() {}
|
||||
|
||||
void SetFont(PD::Li::Font& font);
|
||||
|
||||
void Render();
|
||||
|
||||
const PD::Li::Drawlist& Data() const { return pList; }
|
||||
|
||||
private:
|
||||
PD::Li::Drawlist pList;
|
||||
void Render(PD::Li::Drawlist& list);
|
||||
};
|
||||
} // namespace Ultra
|
||||
} // namespace PD
|
||||
Reference in New Issue
Block a user