Flint Engine
Modular C++20 2D game engine powered by SDL3
Loading...
Searching...
No Matches
shape.h
1// SPDX-License-Identifier: MIT
2// SPDX-FileCopyrightText: 2025-2026 Manuel Osorio
3#pragma once
4#include "flint/graphics/drawable.h"
5#include "flint/graphics/texture.h"
6#include "flint/graphics/types/color.h"
7#include "flint/math/types.h"
8
9namespace Flint {
10 class Texture;
11
20 class Shape : public Drawable {
21 public:
22 ~Shape() override = default;
23
29 virtual void setPosition(Vec2f newPosition) {
30 m_position = newPosition;
31 }
32
38 virtual void setFillColor(Color color) {
39 m_fillColor = color;
40 }
41
47 virtual void setOutlineColor(Color color) {
48 m_outlineColor = color;
49 }
50
56 virtual void setOutlineThickness(float thickness) {
57 m_outlineThickness = thickness;
58 }
59
61 virtual Vec2f getPosition() const {
62 return m_position;
63 }
64
66 virtual Color getFillColor() const {
67 return m_fillColor;
68 }
69
71 virtual Color getOutlineColor() const {
72 return m_outlineColor;
73 }
74
76 virtual float getOutlineThickness() const {
77 return m_outlineThickness;
78 }
79
89 virtual FloatRect getGlobalBounds() const {
90 return FloatRect({m_position.x, m_position.y},
91 {static_cast<float>(m_texture ? m_texture->getWidth() : 0),
92 static_cast<float>(m_texture ? m_texture->getHeight() : 0)});
93 }
94
95 protected:
96 Vec2f m_position{0, 0};
97 Color m_fillColor{255, 255, 255, 255};
98 Color m_outlineColor{0, 0, 0, 0};
99 float m_outlineThickness{0.f};
100
101 private:
102 Texture *m_texture = nullptr;
103 };
104}
Interface for objects that contribute ordered work to a rendered frame.
Definition drawable.h:21
virtual FloatRect getGlobalBounds() const
Return the axis-aligned bounding rectangle in world space.
Definition shape.h:89
virtual Color getFillColor() const
Return the current fill color.
Definition shape.h:66
virtual void setOutlineThickness(float thickness)
Set the outline stroke thickness in pixels.
Definition shape.h:56
virtual float getOutlineThickness() const
Return the current outline thickness in pixels.
Definition shape.h:76
virtual Color getOutlineColor() const
Return the current outline color.
Definition shape.h:71
virtual void setFillColor(Color color)
Set the fill (interior) color.
Definition shape.h:38
virtual Vec2f getPosition() const
Return the current world-space position.
Definition shape.h:61
virtual void setPosition(Vec2f newPosition)
Set the world-space position of the shape.
Definition shape.h:29
virtual void setOutlineColor(Color color)
Set the outline (stroke) color.
Definition shape.h:47
Abstract base class for 2-D geometric shapes.
Definition shape.h:20
int getWidth() const
Return the texture width in pixels.
int getHeight() const
Return the texture height in pixels.
RGBA color with 8-bit unsigned components.
Definition color.h:13