GCC Code Coverage Report


Directory: src/gate/
File: src/gate/ui/cxx_graphics.cpp
Date: 2026-08-06 22:46:24
Exec Total Coverage
Lines: 92 172 53.5%
Functions: 21 41 51.2%
Branches: 33 114 28.9%

Line Branch Exec Source
1 /* GATE PROJECT LICENSE:
2 +----------------------------------------------------------------------------+
3 | Copyright (c) 2018-2026, 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 2 Graphics::Graphics(gate_ui_graphics_t& external_reference)
36 2 : impl_internal(gate_ui_graphics_t())
37 {
38 2 this->impl = &external_reference;
39 2 }
40 2 Graphics::Graphics(Host& host, uint32_t width, uint32_t height)
41 {
42 2 result_t result = gate_ui_graphics_create_virtual(&this->impl_internal, host.c_impl(), width, height);
43
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 GATEXX_CHECK_EXCEPTION(result);
44 2 this->impl = &this->impl_internal;
45 2 }
46 2 Graphics::Graphics(Host& host, uint32_t width, uint32_t height, uint32_t depth)
47 {
48 2 result_t result = gate_ui_graphics_create_image(&this->impl_internal, host.c_impl(), width, height, depth);
49
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 GATEXX_CHECK_EXCEPTION(result);
50 2 this->impl = &this->impl_internal;
51 2 }
52 2 Graphics::Graphics(Host& host, RasterImage const& image)
53 {
54 2 result_t result = gate_ui_graphics_create_image_from(&this->impl_internal, host.c_impl(), image.c_impl());
55
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 GATEXX_CHECK_EXCEPTION(result);
56 2 this->impl = &this->impl_internal;
57 2 }
58 2 Graphics::Graphics(Control const& ctrl)
59 {
60 2 result_t result = gate_ui_graphics_create_ctrl(&this->impl_internal, ctrl.c_impl());
61
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 GATEXX_CHECK_EXCEPTION(result);
62 2 this->impl = &this->impl_internal;
63 2 }
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 20 Graphics::~Graphics() noexcept
71 {
72
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 2 times.
10 if (this->impl == &this->impl_internal)
73 {
74 // internal object -> default delete
75 8 gate_ui_graphics_destroy(this->impl);
76 }
77 else
78 {
79 // external object -> do nothing
80 }
81 10 }
82
83 26 gate_ui_graphics_t* Graphics::c_impl() const noexcept
84 {
85 26 return this->impl;
86 }
87
88 2 int32_t Graphics::getWidth()
89 {
90 2 return gate_ui_graphics_width(this->impl);
91 }
92 2 int32_t Graphics::getHeight()
93 {
94 2 return gate_ui_graphics_height(this->impl);
95 }
96
97 2 void Graphics::setPixel(Point const& pos, Color const& col)
98 {
99 2 result_t result = gate_ui_graphics_set_pixel(this->impl, pos, col.value);
100
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 GATEXX_CHECK_EXCEPTION(result);
101 2 }
102 2 Color Graphics::getPixel(Point const& pos)
103 {
104
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 Color ret;
105
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 result_t result = gate_ui_graphics_get_pixel(this->impl, pos, &ret.value);
106
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
2 GATEXX_CHECK_EXCEPTION(result);
107 return ret;
108 }
109 2 void Graphics::draw(Graphics& src, Point const& dst_pos, Size const& size, Point const& src_pos)
110 {
111
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
6 result_t result = gate_ui_graphics_draw(this->c_impl(), src.c_impl(), dst_pos.c_impl(),
112 4 !size ? NULL : size.c_impl(), src_pos.c_impl());
113
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 GATEXX_CHECK_EXCEPTION(result);
114 2 }
115 2 void Graphics::drawEx(Graphics& src, Position const& dst_pos, Position const& src_pos)
116 {
117 2 result_t result = gate_ui_graphics_draw_ex(this->c_impl(), src.c_impl(), &dst_pos, &src_pos);
118
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 GATEXX_CHECK_EXCEPTION(result);
119 2 }
120 2 void Graphics::drawImage(RasterImage const& srcImage, Point const& dstPos, Size const& size, Point const& srcPos)
121 {
122
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
4 result_t result = gate_ui_graphics_draw_image(this->c_impl(),
123 srcImage.c_impl(),
124 dstPos.c_impl(),
125 2 !size ? NULL : size.c_impl(),
126 2 !srcPos ? NULL : srcPos.c_impl()
127 );
128
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 GATEXX_CHECK_EXCEPTION(result);
129 2 }
130
131 4 void Graphics::line(Point const& from, Point const& to, Color const& color, uint32_t line_width)
132 {
133 4 result_t result = gate_ui_graphics_line(this->c_impl(), from, to, color.value, line_width);
134
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 GATEXX_CHECK_EXCEPTION(result);
135 4 }
136 2 void Graphics::rect(Position const& rect, Color const& lineColor, uint32_t lineWidth)
137 {
138 2 result_t result = gate_ui_graphics_rect(this->c_impl(), rect, lineColor.c_impl(), lineWidth, NULL);
139
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 GATEXX_CHECK_EXCEPTION(result);
140 2 }
141 2 void Graphics::rect(Position const& rect, Color const& lineColor, uint32_t lineWidth, Color const& fillColor)
142 {
143 2 result_t result = gate_ui_graphics_rect(this->c_impl(), rect, lineColor.c_impl(), lineWidth, fillColor.c_impl());
144
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 GATEXX_CHECK_EXCEPTION(result);
145 2 }
146 2 void Graphics::polygon(Array<Point> const& points, Color const& lineColor, uint32_t lineWidth)
147 {
148 gate_ui_point_t poly_points[1024];
149 2 gate_ui_point_t* ptr = &poly_points[0];
150
2/2
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 2 times.
12 for (Array<Point>::const_iterator p(points.begin()), pend(points.end()); p != pend; ++p)
151 {
152 10 *ptr = *p->c_impl();
153 10 ++ptr;
154 }
155
2/4
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
2 result_t result = gate_ui_graphics_polygon(this->c_impl(), poly_points, points.size(),
156 lineColor.c_impl(), lineWidth, NULL);
157
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
2 GATEXX_CHECK_EXCEPTION(result);
158 2 }
159 void Graphics::polygon(Array<Point> const& points, Color const& lineColor, uint32_t lineWidth, Color const& fillColor)
160 {
161 gate_ui_point_t poly_points[1024];
162 gate_ui_point_t* ptr = &poly_points[0];
163 for (Array<Point>::const_iterator p(points.begin()), pend(points.end()); p != pend; ++p)
164 {
165 *ptr = *p->c_impl();
166 ++ptr;
167 }
168 result_t result = gate_ui_graphics_polygon(this->c_impl(), poly_points, points.size(),
169 lineColor.c_impl(), lineWidth, fillColor.c_impl());
170 GATEXX_CHECK_EXCEPTION(result);
171 }
172
173 2 Array<int32_t> Graphics::getCharWidths(Font const& font, char_32_t const* chars, size_t charcount)
174 {
175
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
4 ArrayList<int32_t> textlens;
176
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 textlens.add(0, charcount);
177
178
1/2
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
2 result_t result = gate_ui_graphics_get_char_size(this->c_impl(), font.c_impl(), chars, charcount, &textlens[0]);
179
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
2 GATEXX_CHECK_EXCEPTION(result);
180
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
4 return textlens.toArray();
181 }
182 2 Size Graphics::getTextSize(Font const& font, String const& text)
183 {
184 2 Size sz;
185
1/2
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
2 result_t result = gate_ui_graphics_get_text_size(this->c_impl(), font.c_impl(), text.c_impl(), &sz.width, &sz.height);
186
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
2 GATEXX_CHECK_EXCEPTION(result);
187 2 return sz;
188 }
189 2 void Graphics::print(Font const& font, String const& text, Position const& pos)
190 {
191 2 result_t result = gate_ui_graphics_print(this->c_impl(), font.c_impl(), text.c_impl(), pos.c_impl());
192
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 GATEXX_CHECK_EXCEPTION(result);
193 2 }
194
195
196
197
198
199
200 Icon::Icon(Host& host, StockIdEnum stockId, bool smallIcon)
201 {
202 result_t result = gate_ui_icon_create_stock(&this->impl, host.c_impl(), (gate_uint32_t)stockId,
203 smallIcon ? GATE_UI_ICON_FLAG_SMALL : 0);
204 GATEXX_CHECK_EXCEPTION(result);
205 }
206 Icon::Icon(Host& host, void* nativeHandle, uint32_t flags)
207 {
208 result_t result = gate_ui_icon_create_native(&this->impl, host.c_impl(), nativeHandle, flags);
209 GATEXX_CHECK_EXCEPTION(result);
210 }
211 Icon::Icon(Host& host, RasterImage const& image)
212 {
213 result_t result = gate_ui_icon_create_image(&this->impl, host.c_impl(), image.c_impl());
214 GATEXX_CHECK_EXCEPTION(result);
215 }
216 Icon::Icon(Host& host, String const& filePath)
217 {
218 result_t result = gate_ui_icon_create_file(&this->impl, *host, filePath.c_impl());
219 GATEXX_CHECK_EXCEPTION(result);
220 }
221 Icon::Icon(Icon const& src)
222 {
223 result_t result = gate_ui_icon_copy(&this->impl, &src.impl);
224 GATEXX_CHECK_EXCEPTION(result);
225 }
226
227 Icon& Icon::operator=(Icon const& src)
228 {
229 if (this != &src)
230 {
231 Icon that(src);
232 this->swap(that);
233 }
234 return *this;
235 }
236 Icon::~Icon() noexcept
237 {
238 gate_ui_icon_destroy(&this->impl);
239 }
240
241 gate_ui_icon_t const* Icon::c_impl() const noexcept
242 {
243 return &this->impl;
244 }
245
246 void Icon::swap(Icon& that)
247 {
248 gate::swapRefs(this->impl, that.impl);
249 }
250
251
252
253
254 const uint32_t Cursor::Flag_Stock = GATE_UI_CURSOR_FLAG_STOCK;
255
256 Cursor::Cursor(Host& host, StockIdEnum stockId)
257 {
258 result_t result = gate_ui_cursor_create_stock(&this->impl, host.c_impl(), (gate_uint32_t)stockId);
259 GATEXX_CHECK_EXCEPTION(result);
260 }
261 Cursor::Cursor(Host& host, void* nativeHandle, uint32_t flags)
262 {
263 result_t result = gate_ui_cursor_create_native(&this->impl, host.c_impl(), nativeHandle, flags);
264 GATEXX_CHECK_EXCEPTION(result);
265 }
266 Cursor::Cursor(Host& host, RasterImage const& image, uint16_t x, uint16_t y)
267 {
268 result_t result = gate_ui_cursor_create_image(&this->impl, host.c_impl(), image.c_impl(), x, y);
269 GATEXX_CHECK_EXCEPTION(result);
270 }
271 Cursor::Cursor(Host& host, String const& filePath)
272 {
273 result_t result = gate_ui_cursor_create_file(&this->impl, host.c_impl(), filePath.c_impl());
274 GATEXX_CHECK_EXCEPTION(result);
275 }
276 Cursor::Cursor(Cursor const& src)
277 {
278 result_t result = gate_ui_cursor_copy(&this->impl, &src.impl);
279 GATEXX_CHECK_EXCEPTION(result);
280 }
281
282 Cursor& Cursor::operator=(Cursor const& src)
283 {
284 if (this != &src)
285 {
286 Cursor that(src);
287 this->swap(that);
288 }
289 return *this;
290 }
291 Cursor::~Cursor() noexcept
292 {
293 gate_ui_cursor_destroy(&this->impl);
294 }
295
296 gate_ui_cursor_t const* Cursor::c_impl() const noexcept
297 {
298 return &this->impl;
299 }
300 void Cursor::swap(Cursor& that)
301 {
302 gate::swapRefsNoExcept(this->impl, that.impl);
303 }
304
305
306
307
308
309
310
311 } // end of namespace ui
312 } // end of namespace gate
313
314