feat: add canvas rework
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
#ifndef DESTRUM_APPLAYER_H
|
||||
#define DESTRUM_APPLAYER_H
|
||||
|
||||
#include <optional>
|
||||
|
||||
#include <destrum/Components/UI/CanvasFrame.h>
|
||||
|
||||
class Camera;
|
||||
class GameRenderer;
|
||||
|
||||
@@ -25,6 +29,7 @@ public:
|
||||
[[nodiscard]] virtual Camera* viewCamera() { return nullptr; }
|
||||
[[nodiscard]] virtual bool hostsViewport() const { return false; }
|
||||
[[nodiscard]] virtual InputFocus gameInputFocus() const { return {}; }
|
||||
[[nodiscard]] virtual std::optional<CanvasFrame> canvasFrame() const { return std::nullopt; }
|
||||
};
|
||||
|
||||
#endif // DESTRUM_APPLAYER_H
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#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>
|
||||
|
||||
@@ -22,6 +23,7 @@ public:
|
||||
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;
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
#ifndef DESTRUM_CANVASFRAME_H
|
||||
#define DESTRUM_CANVASFRAME_H
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
// Where canvases lay out, in draw image pixels: a resolution sized screen at min, drawn zoom times larger
|
||||
struct CanvasFrame {
|
||||
glm::vec2 min{0.0f};
|
||||
glm::vec2 resolution{0.0f};
|
||||
float zoom{1.0f};
|
||||
};
|
||||
|
||||
#endif // DESTRUM_CANVASFRAME_H
|
||||
@@ -43,6 +43,8 @@ public:
|
||||
// Where the canvas last drew this object
|
||||
[[nodiscard]] const UIRect& GetScreenRect() const { return m_ScreenRect; }
|
||||
[[nodiscard]] const UIRect& GetParentRect() const { return m_ParentRect; }
|
||||
// Screen pixels per canvas unit at the last draw
|
||||
[[nodiscard]] float GetScreenScale() const { return m_LastScale; }
|
||||
void SetScreenRect(const UIRect& rect, const UIRect& parentRect, float scale)
|
||||
{
|
||||
m_ScreenRect = rect;
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
#ifndef RENDERCONTEXT_H
|
||||
#define RENDERCONTEXT_H
|
||||
|
||||
#include <optional>
|
||||
|
||||
#include <destrum/Components/UI/CanvasFrame.h>
|
||||
#include <destrum/Graphics/Renderer.h>
|
||||
|
||||
struct RenderContext {
|
||||
GameRenderer& renderer;
|
||||
const Camera& camera;
|
||||
const GameRenderer::SceneData& sceneData;
|
||||
// Unset: canvases fill the draw image
|
||||
std::optional<CanvasFrame> canvasFrame{};
|
||||
};
|
||||
|
||||
#endif //RENDERCONTEXT_H
|
||||
|
||||
Reference in New Issue
Block a user