Dura2D  v0.1.0
An educational 2D game physics library
Loading...
Searching...
No Matches
d2Draw.h
Go to the documentation of this file.
1#ifndef D2DRAW_H
2#define D2DRAW_H
3
4#include "d2api.h"
5#include "d2Math.h"
6#include "d2Types.h"
7
12{
13 d2Color() = default;
14
15 d2Color(float rIn, float gIn, float bIn, float aIn = 1.0f)
16 {
17 r = rIn;
18 g = gIn;
19 b = bIn;
20 a = aIn;
21 }
22
23 void Set(float rIn, float gIn, float bIn, float aIn = 1.0f)
24 {
25 r = rIn;
26 g = gIn;
27 b = bIn;
28 a = aIn;
29 }
30
31 // * operator
32 d2Color operator*(const float &f) const
33 {
34 return d2Color(r * f, g * f, b * f, a * f);
35 }
36
37 // *= operator
38 d2Color &operator*=(const float &f)
39 {
40 r *= f;
41 g *= f;
42 b *= f;
43 a *= f;
44 return *this;
45 }
46
47 // / operator
48 d2Color operator/(const float &f) const
49 {
50 return {r / f, g / f, b / f, a / f};
51 }
52
53 // /= operator
54 d2Color &operator/=(const float &f)
55 {
56 r /= f;
57 g /= f;
58 b /= f;
59 a /= f;
60 return *this;
61 }
62
63 float r{}, g{}, b{}, a{1.0f};
64};
65
67{
68public:
69 d2Draw() = default;
70
71 virtual ~d2Draw(){}
72
73 enum
74 {
75 e_shapeBit = 0x0001,
76 e_meshBit = 0x0002,
77 e_aabbBit = 0x0004,
78 e_aabbTreeBit = 0x0008,
79 e_transformBit = 0x0010,
80 e_jointBit = 0x0020,
81 };
82
83 void SetFlags(uint32 flags);
84
85 uint32 GetFlags() const;
86
87 void AppendFlags(uint32 flags);
88
89 void ClearFlags(uint32 flags);
90
91 virtual void DrawPolygon(const d2Vec2 *vertices, int32 vertexCount, const float &angle, const d2Color &color) const = 0;
92
93 virtual void DrawSolidPolygon(const d2Vec2 *vertices, int32 vertexCount, const float &angle, const bool &mesh, const d2Color &color) const = 0;
94
95 virtual void DrawCircle(const d2Vec2 &center, float radius, const float &angle, const d2Color &color) const = 0;
96
97 virtual void DrawSolidCircle(const d2Vec2 &center, float radius, const float &angle, const d2Color &color) const = 0;
98
99 virtual void DrawTransform(const d2Transform & transform) const = 0;
100
101 virtual void DrawSegment(const d2Vec2 &p1, const d2Vec2 &p2, const d2Color &color) const = 0;
102
103protected:
104 uint32 m_flags{e_shapeBit};
105};
106
107inline void
109{
110 m_flags = flags;
111}
112
113inline uint32
115{
116 return m_flags;
117}
118
119inline void
121{
122 m_flags |= flags;
123}
124
125inline void
127{
128 m_flags &= ~flags;
129}
130
131
132#endif //D2DRAW_H
Definition d2Draw.h:67
void SetFlags(uint32 flags)
Definition d2Draw.h:108
d2Draw()=default
virtual void DrawSolidPolygon(const d2Vec2 *vertices, int32 vertexCount, const float &angle, const bool &mesh, const d2Color &color) const =0
virtual void DrawPolygon(const d2Vec2 *vertices, int32 vertexCount, const float &angle, const d2Color &color) const =0
uint32 m_flags
Definition d2Draw.h:104
virtual void DrawSolidCircle(const d2Vec2 &center, float radius, const float &angle, const d2Color &color) const =0
void ClearFlags(uint32 flags)
Definition d2Draw.h:126
virtual void DrawCircle(const d2Vec2 &center, float radius, const float &angle, const d2Color &color) const =0
virtual void DrawSegment(const d2Vec2 &p1, const d2Vec2 &p2, const d2Color &color) const =0
virtual void DrawTransform(const d2Transform &transform) const =0
uint32 GetFlags() const
Definition d2Draw.h:114
virtual ~d2Draw()
Definition d2Draw.h:71
void AppendFlags(uint32 flags)
Definition d2Draw.h:120
unsigned int uint32
Definition d2Types.h:9
signed int int32
Definition d2Types.h:6
#define D2_API
Definition d2api.h:27
Definition d2Draw.h:12
d2Color & operator*=(const float &f)
Definition d2Draw.h:38
d2Color operator*(const float &f) const
Definition d2Draw.h:32
d2Color operator/(const float &f) const
Definition d2Draw.h:48
d2Color()=default
d2Color & operator/=(const float &f)
Definition d2Draw.h:54
void Set(float rIn, float gIn, float bIn, float aIn=1.0f)
Definition d2Draw.h:23
d2Color(float rIn, float gIn, float bIn, float aIn=1.0f)
Definition d2Draw.h:15
Represents a transformation in 2D space.
Definition d2Math.h:309
Represents a 2D vector.
Definition d2Math.h:22