53 lines
1.7 KiB
C++
53 lines
1.7 KiB
C++
#ifndef DESTRUM_CANVAS_H
|
|
#define DESTRUM_CANVAS_H
|
|
|
|
#include <destrum/Components/UI/CanvasFrame.h>
|
|
#include <destrum/Components/UI/RectTransform.h>
|
|
#include <destrum/ObjectModel/Component.h>
|
|
|
|
#include <glm/glm.hpp>
|
|
|
|
enum class CanvasScaleMode {
|
|
ConstantPixelSize,
|
|
ScaleWithScreenHeight,
|
|
};
|
|
|
|
// Draws the UIGraphics on its object and every active child, depth first, so later siblings draw on top.
|
|
// A child with its own Canvas is skipped and draws itself.
|
|
class Canvas final : public Component {
|
|
public:
|
|
explicit Canvas(GameObject& parent);
|
|
|
|
std::string GetTypeName() const override { return "Canvas"; }
|
|
|
|
void Start() override;
|
|
void Render(const RenderContext& ctx) override;
|
|
void Draw(const glm::vec2& screenSize);
|
|
void Draw(const CanvasFrame& frame);
|
|
|
|
void Reflect(FieldVisitor& v) override;
|
|
|
|
[[nodiscard]] float GetScale(const glm::vec2& screenSize) const;
|
|
|
|
[[nodiscard]] static Canvas* FindFor(GameObject& object);
|
|
|
|
void SetScaleMode(CanvasScaleMode mode) { m_ScaleMode = mode; }
|
|
void SetReferenceHeight(float height) { m_ReferenceHeight = height; }
|
|
void SetScaleFactor(float factor) { m_ScaleFactor = factor; }
|
|
void SetDrawDebugRects(bool draw) { m_DrawDebugRects = draw; }
|
|
|
|
[[nodiscard]] CanvasScaleMode GetScaleMode() const { return m_ScaleMode; }
|
|
[[nodiscard]] float GetReferenceHeight() const { return m_ReferenceHeight; }
|
|
[[nodiscard]] float GetScaleFactor() const { return m_ScaleFactor; }
|
|
|
|
private:
|
|
void DrawObject(GameObject& object, const UIRect& rect, float scale, bool visible) const;
|
|
|
|
CanvasScaleMode m_ScaleMode{CanvasScaleMode::ScaleWithScreenHeight};
|
|
float m_ReferenceHeight{1080.0f};
|
|
float m_ScaleFactor{1.0f};
|
|
bool m_DrawDebugRects{false};
|
|
};
|
|
|
|
#endif // DESTRUM_CANVAS_H
|