Line |
Branch |
Exec |
Source |
1 |
|
|
/* GATE PROJECT LICENSE: |
2 |
|
|
+----------------------------------------------------------------------------+ |
3 |
|
|
| Copyright(c) 2018-2025, Stefan Meislinger <sm@opengate.at> | |
4 |
|
|
| All rights reserved. | |
5 |
|
|
| | |
6 |
|
|
| Redistribution and use in source and binary forms, with or without | |
7 |
|
|
| modification, are permitted provided that the following conditions are met:| |
8 |
|
|
| | |
9 |
|
|
| 1. Redistributions of source code must retain the above copyright notice, | |
10 |
|
|
| this list of conditions and the following disclaimer. | |
11 |
|
|
| 2. Redistributions in binary form must reproduce the above copyright | |
12 |
|
|
| notice, this list of conditions and the following disclaimer in the | |
13 |
|
|
| documentation and/or other materials provided with the distribution. | |
14 |
|
|
| | |
15 |
|
|
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"| |
16 |
|
|
| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
17 |
|
|
| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
18 |
|
|
| ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | |
19 |
|
|
| LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
20 |
|
|
| CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
21 |
|
|
| SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
22 |
|
|
| INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
23 |
|
|
| CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
24 |
|
|
| ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | |
25 |
|
|
| THE POSSIBILITY OF SUCH DAMAGE. | |
26 |
|
|
+----------------------------------------------------------------------------+ |
27 |
|
|
*/ |
28 |
|
|
|
29 |
|
|
#include "gate/ui/graphics.hpp" |
30 |
|
|
|
31 |
|
|
namespace gate |
32 |
|
|
{ |
33 |
|
|
namespace ui |
34 |
|
|
{ |
35 |
|
✗ |
Graphics::Graphics(gate_ui_graphics_t& external_reference) |
36 |
|
✗ |
: impl_internal(gate_ui_graphics_t()) |
37 |
|
|
{ |
38 |
|
✗ |
this->impl = &external_reference; |
39 |
|
✗ |
} |
40 |
|
✗ |
Graphics::Graphics(Host& host, uint32_t width, uint32_t height) |
41 |
|
|
{ |
42 |
|
✗ |
result_t result = gate_ui_graphics_create_virtual(&this->impl_internal, host.c_impl(), width, height); |
43 |
|
✗ |
GATEXX_CHECK_EXCEPTION(result); |
44 |
|
✗ |
this->impl = &this->impl_internal; |
45 |
|
✗ |
} |
46 |
|
✗ |
Graphics::Graphics(Host& host, uint32_t width, uint32_t height, uint32_t depth) |
47 |
|
|
{ |
48 |
|
✗ |
result_t result = gate_ui_graphics_create_image(&this->impl_internal, host.c_impl(), width, height, depth); |
49 |
|
✗ |
GATEXX_CHECK_EXCEPTION(result); |
50 |
|
✗ |
this->impl = &this->impl_internal; |
51 |
|
✗ |
} |
52 |
|
✗ |
Graphics::Graphics(Host& host, RasterImage const& image) |
53 |
|
|
{ |
54 |
|
✗ |
result_t result = gate_ui_graphics_create_image_from(&this->impl_internal, host.c_impl(), image.c_impl()); |
55 |
|
✗ |
GATEXX_CHECK_EXCEPTION(result); |
56 |
|
✗ |
this->impl = &this->impl_internal; |
57 |
|
✗ |
} |
58 |
|
✗ |
Graphics::Graphics(Control const& ctrl) |
59 |
|
|
{ |
60 |
|
✗ |
result_t result = gate_ui_graphics_create_ctrl(&this->impl_internal, ctrl.c_impl()); |
61 |
|
✗ |
GATEXX_CHECK_EXCEPTION(result); |
62 |
|
✗ |
this->impl = &this->impl_internal; |
63 |
|
✗ |
} |
64 |
|
✗ |
Graphics::Graphics(Host& host, void* native_graphics, void* param, int32_t width, int32_t height) |
65 |
|
|
{ |
66 |
|
✗ |
result_t result = gate_ui_graphics_create_native(&this->impl_internal, host.c_impl(), native_graphics, param, width, height); |
67 |
|
✗ |
GATEXX_CHECK_EXCEPTION(result); |
68 |
|
✗ |
this->impl = &this->impl_internal; |
69 |
|
✗ |
} |
70 |
|
✗ |
Graphics::~Graphics() noexcept |
71 |
|
|
{ |
72 |
|
✗ |
if (this->impl == &this->impl_internal) |
73 |
|
|
{ |
74 |
|
|
// internal object -> default delete |
75 |
|
✗ |
gate_ui_graphics_destroy(this->impl); |
76 |
|
|
} |
77 |
|
|
else |
78 |
|
|
{ |
79 |
|
|
// external object -> do nothing |
80 |
|
|
} |
81 |
|
✗ |
} |
82 |
|
|
|
83 |
|
✗ |
gate_ui_graphics_t* Graphics::c_impl() const noexcept |
84 |
|
|
{ |
85 |
|
✗ |
return this->impl; |
86 |
|
|
} |
87 |
|
|
|
88 |
|
✗ |
int32_t Graphics::getWidth() |
89 |
|
|
{ |
90 |
|
✗ |
return gate_ui_graphics_width(this->impl); |
91 |
|
|
} |
92 |
|
✗ |
int32_t Graphics::getHeight() |
93 |
|
|
{ |
94 |
|
✗ |
return gate_ui_graphics_height(this->impl); |
95 |
|
|
} |
96 |
|
|
|
97 |
|
✗ |
void Graphics::setPixel(Point const& pos, Color const& col) |
98 |
|
|
{ |
99 |
|
✗ |
result_t result = gate_ui_graphics_set_pixel(this->impl, pos, col.value); |
100 |
|
✗ |
GATEXX_CHECK_EXCEPTION(result); |
101 |
|
✗ |
} |
102 |
|
✗ |
Color Graphics::getPixel(Point const& pos) |
103 |
|
|
{ |
104 |
|
✗ |
Color ret; |
105 |
|
✗ |
result_t result = gate_ui_graphics_get_pixel(this->impl, pos, &ret.value); |
106 |
|
✗ |
GATEXX_CHECK_EXCEPTION(result); |
107 |
|
✗ |
return ret; |
108 |
|
|
} |
109 |
|
✗ |
void Graphics::draw(Graphics& src, Point const& dst_pos, Size const& size, Point const& src_pos) |
110 |
|
|
{ |
111 |
|
✗ |
result_t result = gate_ui_graphics_draw(this->c_impl(), src.c_impl(), dst_pos.c_impl(), |
112 |
|
✗ |
!size ? NULL : size.c_impl(), src_pos.c_impl()); |
113 |
|
✗ |
GATEXX_CHECK_EXCEPTION(result); |
114 |
|
✗ |
} |
115 |
|
✗ |
void Graphics::drawEx(Graphics& src, Position const& dst_pos, Position const& src_pos) |
116 |
|
|
{ |
117 |
|
✗ |
result_t result = gate_ui_graphics_draw_ex(this->c_impl(), src.c_impl(), &dst_pos, &src_pos); |
118 |
|
✗ |
GATEXX_CHECK_EXCEPTION(result); |
119 |
|
✗ |
} |
120 |
|
|
|
121 |
|
✗ |
void Graphics::line(Point const& from, Point const& to, Color const& color, uint32_t line_width) |
122 |
|
|
{ |
123 |
|
✗ |
result_t result = gate_ui_graphics_line(this->c_impl(), from, to, color.value, line_width); |
124 |
|
✗ |
GATEXX_CHECK_EXCEPTION(result); |
125 |
|
✗ |
} |
126 |
|
✗ |
void Graphics::rect(Position const& rect, Color const& lineColor, uint32_t lineWidth) |
127 |
|
|
{ |
128 |
|
✗ |
result_t result = gate_ui_graphics_rect(this->c_impl(), rect, lineColor.c_impl(), lineWidth, NULL); |
129 |
|
✗ |
GATEXX_CHECK_EXCEPTION(result); |
130 |
|
✗ |
} |
131 |
|
✗ |
void Graphics::rect(Position const& rect, Color const& lineColor, uint32_t lineWidth, Color const& fillColor) |
132 |
|
|
{ |
133 |
|
✗ |
result_t result = gate_ui_graphics_rect(this->c_impl(), rect, lineColor.c_impl(), lineWidth, fillColor.c_impl()); |
134 |
|
✗ |
GATEXX_CHECK_EXCEPTION(result); |
135 |
|
✗ |
} |
136 |
|
✗ |
void Graphics::polygon(Array<Point> const& points, Color const& lineColor, uint32_t lineWidth) |
137 |
|
|
{ |
138 |
|
|
gate_ui_point_t poly_points[1024]; |
139 |
|
✗ |
size_t index = 0; |
140 |
|
✗ |
gate_ui_point_t* ptr = &poly_points[0]; |
141 |
|
✗ |
for (Array<Point>::const_iterator p(points.begin()), pend(points.end()); p != pend; ++p) |
142 |
|
|
{ |
143 |
|
✗ |
*ptr = *p->c_impl(); |
144 |
|
✗ |
++ptr; |
145 |
|
|
} |
146 |
|
✗ |
result_t result = gate_ui_graphics_polygon(this->c_impl(), poly_points, points.size(), |
147 |
|
|
lineColor.c_impl(), lineWidth, NULL); |
148 |
|
✗ |
GATEXX_CHECK_EXCEPTION(result); |
149 |
|
✗ |
} |
150 |
|
✗ |
void Graphics::polygon(Array<Point> const& points, Color const& lineColor, uint32_t lineWidth, Color const& fillColor) |
151 |
|
|
{ |
152 |
|
|
gate_ui_point_t poly_points[1024]; |
153 |
|
✗ |
size_t index = 0; |
154 |
|
✗ |
gate_ui_point_t* ptr = &poly_points[0]; |
155 |
|
✗ |
for (Array<Point>::const_iterator p(points.begin()), pend(points.end()); p != pend; ++p) |
156 |
|
|
{ |
157 |
|
✗ |
*ptr = *p->c_impl(); |
158 |
|
✗ |
++ptr; |
159 |
|
|
} |
160 |
|
✗ |
result_t result = gate_ui_graphics_polygon(this->c_impl(), poly_points, points.size(), |
161 |
|
|
lineColor.c_impl(), lineWidth, fillColor.c_impl()); |
162 |
|
✗ |
GATEXX_CHECK_EXCEPTION(result); |
163 |
|
✗ |
} |
164 |
|
|
|
165 |
|
✗ |
Array<int32_t> Graphics::getCharWidths(Font const& font, char_32_t const* chars, size_t charcount) |
166 |
|
|
{ |
167 |
|
✗ |
ArrayList<int32_t> textlens; |
168 |
|
✗ |
textlens.add(0, charcount); |
169 |
|
|
|
170 |
|
✗ |
result_t result = gate_ui_graphics_get_char_size(this->c_impl(), font.c_impl(), chars, charcount, &textlens[0]); |
171 |
|
✗ |
GATEXX_CHECK_EXCEPTION(result); |
172 |
|
✗ |
return textlens.toArray(); |
173 |
|
|
} |
174 |
|
✗ |
Size Graphics::getTextSize(Font const& font, String const& text) |
175 |
|
|
{ |
176 |
|
✗ |
Size sz; |
177 |
|
✗ |
result_t result = gate_ui_graphics_get_text_size(this->c_impl(), font.c_impl(), text.c_impl(), &sz.width, &sz.height); |
178 |
|
✗ |
GATEXX_CHECK_EXCEPTION(result); |
179 |
|
✗ |
return sz; |
180 |
|
|
} |
181 |
|
✗ |
void Graphics::print(Font const& font, String const& text, Position const& pos) |
182 |
|
|
{ |
183 |
|
✗ |
result_t result = gate_ui_graphics_print(this->c_impl(), font.c_impl(), text.c_impl(), pos.c_impl()); |
184 |
|
✗ |
GATEXX_CHECK_EXCEPTION(result); |
185 |
|
✗ |
} |
186 |
|
|
|
187 |
|
|
|
188 |
|
|
|
189 |
|
|
|
190 |
|
|
|
191 |
|
|
|
192 |
|
✗ |
Icon::Icon(Host& host, StockIdEnum stockId, bool smallIcon) |
193 |
|
|
{ |
194 |
|
✗ |
result_t result = gate_ui_icon_create_stock(&this->impl, host.c_impl(), (gate_uint32_t)stockId, |
195 |
|
|
smallIcon ? GATE_UI_ICON_FLAG_SMALL : 0); |
196 |
|
✗ |
GATEXX_CHECK_EXCEPTION(result); |
197 |
|
✗ |
} |
198 |
|
✗ |
Icon::Icon(Host& host, void* nativeHandle, uint32_t flags) |
199 |
|
|
{ |
200 |
|
✗ |
result_t result = gate_ui_icon_create_native(&this->impl, host.c_impl(), nativeHandle, flags); |
201 |
|
✗ |
GATEXX_CHECK_EXCEPTION(result); |
202 |
|
✗ |
} |
203 |
|
✗ |
Icon::Icon(Host& host, RasterImage const& image) |
204 |
|
|
{ |
205 |
|
✗ |
result_t result = gate_ui_icon_create_image(&this->impl, host.c_impl(), image.c_impl()); |
206 |
|
✗ |
GATEXX_CHECK_EXCEPTION(result); |
207 |
|
✗ |
} |
208 |
|
✗ |
Icon::Icon(Host& host, String const& filePath) |
209 |
|
|
{ |
210 |
|
✗ |
result_t result = gate_ui_icon_create_file(&this->impl, *host, filePath.c_impl()); |
211 |
|
✗ |
GATEXX_CHECK_EXCEPTION(result); |
212 |
|
✗ |
} |
213 |
|
✗ |
Icon::Icon(Icon const& src) |
214 |
|
|
{ |
215 |
|
✗ |
result_t result = gate_ui_icon_copy(&this->impl, &src.impl); |
216 |
|
✗ |
GATEXX_CHECK_EXCEPTION(result); |
217 |
|
✗ |
} |
218 |
|
|
|
219 |
|
✗ |
Icon& Icon::operator=(Icon const& src) |
220 |
|
|
{ |
221 |
|
✗ |
if (this != &src) |
222 |
|
|
{ |
223 |
|
✗ |
Icon that(src); |
224 |
|
✗ |
this->swap(that); |
225 |
|
|
} |
226 |
|
✗ |
return *this; |
227 |
|
|
} |
228 |
|
✗ |
Icon::~Icon() noexcept |
229 |
|
|
{ |
230 |
|
✗ |
gate_ui_icon_destroy(&this->impl); |
231 |
|
✗ |
} |
232 |
|
|
|
233 |
|
✗ |
gate_ui_icon_t const* Icon::c_impl() const noexcept |
234 |
|
|
{ |
235 |
|
✗ |
return &this->impl; |
236 |
|
|
} |
237 |
|
|
|
238 |
|
✗ |
void Icon::swap(Icon& that) |
239 |
|
|
{ |
240 |
|
✗ |
gate::swapRefs(this->impl, that.impl); |
241 |
|
✗ |
} |
242 |
|
|
|
243 |
|
|
|
244 |
|
|
|
245 |
|
|
|
246 |
|
|
const uint32_t Cursor::Flag_Stock = GATE_UI_CURSOR_FLAG_STOCK; |
247 |
|
|
|
248 |
|
✗ |
Cursor::Cursor(Host& host, StockIdEnum stockId) |
249 |
|
|
{ |
250 |
|
✗ |
result_t result = gate_ui_cursor_create_stock(&this->impl, host.c_impl(), (gate_uint32_t)stockId); |
251 |
|
✗ |
GATEXX_CHECK_EXCEPTION(result); |
252 |
|
✗ |
} |
253 |
|
✗ |
Cursor::Cursor(Host& host, void* nativeHandle, uint32_t flags) |
254 |
|
|
{ |
255 |
|
✗ |
result_t result = gate_ui_cursor_create_native(&this->impl, host.c_impl(), nativeHandle, flags); |
256 |
|
✗ |
GATEXX_CHECK_EXCEPTION(result); |
257 |
|
✗ |
} |
258 |
|
✗ |
Cursor::Cursor(Host& host, RasterImage const& image, uint16_t x, uint16_t y) |
259 |
|
|
{ |
260 |
|
✗ |
result_t result = gate_ui_cursor_create_image(&this->impl, host.c_impl(), image.c_impl(), x, y); |
261 |
|
✗ |
GATEXX_CHECK_EXCEPTION(result); |
262 |
|
✗ |
} |
263 |
|
✗ |
Cursor::Cursor(Host& host, String const& filePath) |
264 |
|
|
{ |
265 |
|
✗ |
result_t result = gate_ui_cursor_create_file(&this->impl, host.c_impl(), filePath.c_impl()); |
266 |
|
✗ |
GATEXX_CHECK_EXCEPTION(result); |
267 |
|
✗ |
} |
268 |
|
✗ |
Cursor::Cursor(Cursor const& src) |
269 |
|
|
{ |
270 |
|
✗ |
result_t result = gate_ui_cursor_copy(&this->impl, &src.impl); |
271 |
|
✗ |
GATEXX_CHECK_EXCEPTION(result); |
272 |
|
✗ |
} |
273 |
|
|
|
274 |
|
✗ |
Cursor& Cursor::operator=(Cursor const& src) |
275 |
|
|
{ |
276 |
|
✗ |
if (this != &src) |
277 |
|
|
{ |
278 |
|
✗ |
Cursor that(src); |
279 |
|
✗ |
this->swap(that); |
280 |
|
|
} |
281 |
|
✗ |
return *this; |
282 |
|
|
} |
283 |
|
✗ |
Cursor::~Cursor() noexcept |
284 |
|
|
{ |
285 |
|
✗ |
gate_ui_cursor_destroy(&this->impl); |
286 |
|
✗ |
} |
287 |
|
|
|
288 |
|
✗ |
gate_ui_cursor_t const* Cursor::c_impl() const noexcept |
289 |
|
|
{ |
290 |
|
✗ |
return &this->impl; |
291 |
|
|
} |
292 |
|
✗ |
void Cursor::swap(Cursor& that) |
293 |
|
|
{ |
294 |
|
✗ |
gate::swapRefsNoExcept(this->impl, that.impl); |
295 |
|
✗ |
} |
296 |
|
|
|
297 |
|
|
|
298 |
|
|
|
299 |
|
|
|
300 |
|
|
|
301 |
|
|
|
302 |
|
|
|
303 |
|
|
} // end of namespace ui |
304 |
|
|
} // end of namespace gate |
305 |
|
|
|
306 |
|
|
|