forked from cursey/reframework-d2d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDrawList.hpp
More file actions
183 lines (175 loc) · 6.31 KB
/
DrawList.hpp
File metadata and controls
183 lines (175 loc) · 6.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#pragma once
#include <memory>
#include <mutex>
#include <string>
#include <vector>
#include "D2DFont.hpp"
#include "D2DImage.hpp"
class DrawList {
public:
enum class CommandType { TEXT, FILL_RECT, OUTLINE_RECT, ROUNDED_RECT, FILL_ROUNDED_RECT, QUAD, FILL_QUAD, LINE, IMAGE, FILL_CIRCLE, CIRCLE, PIE, OUTLINE_PIE, RING, OUTLINE_RING };
struct Command {
CommandType type;
union {
struct {
float x{};
float y{};
unsigned int color{};
} text;
struct {
float x{};
float y{};
float w{};
float h{};
unsigned int color{};
} fill_rect;
struct {
float x{};
float y{};
float w{};
float h{};
float thickness{};
unsigned int color{};
} outline_rect;
struct {
float x{};
float y{};
float w{};
float h{};
float rX{};
float rY{};
float thickness{};
unsigned int color{};
} rounded_rect;
struct {
float x{};
float y{};
float w{};
float h{};
float rX{};
float rY{};
unsigned int color{};
} fill_rounded_rect;
struct {
float x1{};
float y1{};
float x2{};
float y2{};
float x3{};
float y3{};
float x4{};
float y4{};
float thickness{};
unsigned int color{};
} quad;
struct {
float x1{};
float y1{};
float x2{};
float y2{};
float x3{};
float y3{};
float x4{};
float y4{};
unsigned int color{};
} fill_quad;
struct {
float x1{};
float y1{};
float x2{};
float y2{};
float thickness{};
unsigned int color{};
} line;
struct {
float x{};
float y{};
float w{};
float h{};
float alpha{1.0f};
} image;
struct {
float x{};
float y{};
float radiusX{};
float radiusY{};
unsigned int color{};
} fill_circle;
struct {
float x{};
float y{};
float radiusX{};
float radiusY{};
float thickness{};
unsigned int color{};
} circle;
struct {
float x{};
float y{};
float r{};
float startAngle{};
float sweepAngle{};
unsigned int color{};
bool clockwise{};
} pie;
struct {
float x{};
float y{};
float r{};
float startAngle{};
float sweepAngle{};
float thickness{};
unsigned int color{};
bool clockwise{};
} outline_pie;
struct {
float x{};
float y{};
float outerRadius{};
float innerRadius{};
float startAngle{};
float sweepAngle{};
unsigned int color{};
bool clockwise{};
} ring;
struct {
float x{};
float y{};
float outerRadius{};
float innerRadius{};
float startAngle{};
float sweepAngle{};
float thickness{};
unsigned int color{};
bool clockwise{};
} outline_ring;
};
std::string str{};
std::shared_ptr<D2DFont> font_resource{};
std::shared_ptr<D2DImage> image_resource{};
};
struct [[nodiscard]] CommandLock {
std::vector<Command>& commands;
std::scoped_lock<std::mutex> lock;
void text(std::shared_ptr<D2DFont>& font, std::string text, float x, float y, unsigned int color);
void fill_rect(float x, float y, float w, float h, unsigned int color);
void outline_rect(float x, float y, float w, float h, float thickness, unsigned int color);
void rounded_rect(float x, float y, float w, float h, float rX, float rY, float thickness, unsigned int color);
void fill_rounded_rect(float x, float y, float w, float h, float rX, float rY, unsigned int color);
void quad(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, float thickness, unsigned int color);
void fill_quad(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, unsigned int color);
void line(float x1, float y1, float x2, float y2, float thickness, unsigned int color);
void image(std::shared_ptr<D2DImage>& image, float x, float y, float w, float h, float alpha = 1.0f);
void fill_circle(float x, float y, float radiusX, float radiusY, unsigned int color);
void circle(float x, float y, float radiusX, float radiusY, float thickness, unsigned int color);
void pie(float x, float y, float r, float startAngle, float sweepAngle, unsigned int color, bool clockwise);
void outline_pie(float x, float y, float r, float startAngle, float sweepAngle, float thickness, unsigned int color, bool clockwise);
void ring(float x, float y, float outerRadius, float innerRadius, float startAngle, float sweepAngle, unsigned int color, bool clockwise);
void outline_ring(float x, float y, float outerRadius, float innerRadius, float startAngle, float sweepAngle, float thickness,
unsigned int color, bool clockwise);
};
auto acquire() { return CommandLock{m_commands, std::scoped_lock{m_commands_mux}}; }
private:
std::vector<Command> m_commands{};
std::mutex m_commands_mux{};
};