GCC Code Coverage Report


Directory: src/gate/
File: src/gate/ui/cxx_graphics.cpp
Date: 2025-12-12 23:40:09
Exec Total Coverage
Lines: 66 166 39.8%
Functions: 16 40 40.0%
Branches: 22 108 20.4%

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 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 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 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 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 12 Graphics::~Graphics() noexcept
71 {
72
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2 times.
6 if (this->impl == &this->impl_internal)
73 {
74 // internal object -> default delete
75 4 gate_ui_graphics_destroy(this->impl);
76 }
77 else
78 {
79 // external object -> do nothing
80 }
81 6 }
82
83 20 gate_ui_graphics_t* Graphics::c_impl() const noexcept
84 {
85 20 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
121 4 void Graphics::line(Point const& from, Point const& to, Color const& color, uint32_t line_width)
122 {
123 4 result_t result = gate_ui_graphics_line(this->c_impl(), from, to, color.value, line_width);
124
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 GATEXX_CHECK_EXCEPTION(result);
125 4 }
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 2 void Graphics::rect(Position const& rect, Color const& lineColor, uint32_t lineWidth, Color const& fillColor)
132 {
133 2 result_t result = gate_ui_graphics_rect(this->c_impl(), rect, lineColor.c_impl(), lineWidth, fillColor.c_impl());
134
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 GATEXX_CHECK_EXCEPTION(result);
135 2 }
136 2 void Graphics::polygon(Array<Point> const& points, Color const& lineColor, uint32_t lineWidth)
137 {
138 gate_ui_point_t poly_points[1024];
139 2 gate_ui_point_t* ptr = &poly_points[0];
140
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)
141 {
142 10 *ptr = *p->c_impl();
143 10 ++ptr;
144 }
145
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(),
146 lineColor.c_impl(), lineWidth, NULL);
147
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
2 GATEXX_CHECK_EXCEPTION(result);
148 2 }
149 void Graphics::polygon(Array<Point> const& points, Color const& lineColor, uint32_t lineWidth, Color const& fillColor)
150 {
151 gate_ui_point_t poly_points[1024];
152 gate_ui_point_t* ptr = &poly_points[0];
153 for (Array<Point>::const_iterator p(points.begin()), pend(points.end()); p != pend; ++p)
154 {
155 *ptr = *p->c_impl();
156 ++ptr;
157 }
158 result_t result = gate_ui_graphics_polygon(this->c_impl(), poly_points, points.size(),
159 lineColor.c_impl(), lineWidth, fillColor.c_impl());
160 GATEXX_CHECK_EXCEPTION(result);
161 }
162
163 Array<int32_t> Graphics::getCharWidths(Font const& font, char_32_t const* chars, size_t charcount)
164 {
165 ArrayList<int32_t> textlens;
166 textlens.add(0, charcount);
167
168 result_t result = gate_ui_graphics_get_char_size(this->c_impl(), font.c_impl(), chars, charcount, &textlens[0]);
169 GATEXX_CHECK_EXCEPTION(result);
170 return textlens.toArray();
171 }
172 2 Size Graphics::getTextSize(Font const& font, String const& text)
173 {
174 2 Size sz;
175
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);
176
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
2 GATEXX_CHECK_EXCEPTION(result);
177 2 return sz;
178 }
179 2 void Graphics::print(Font const& font, String const& text, Position const& pos)
180 {
181 2 result_t result = gate_ui_graphics_print(this->c_impl(), font.c_impl(), text.c_impl(), pos.c_impl());
182
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 GATEXX_CHECK_EXCEPTION(result);
183 2 }
184
185
186
187
188
189
190 Icon::Icon(Host& host, StockIdEnum stockId, bool smallIcon)
191 {
192 result_t result = gate_ui_icon_create_stock(&this->impl, host.c_impl(), (gate_uint32_t)stockId,
193 smallIcon ? GATE_UI_ICON_FLAG_SMALL : 0);
194 GATEXX_CHECK_EXCEPTION(result);
195 }
196 Icon::Icon(Host& host, void* nativeHandle, uint32_t flags)
197 {
198 result_t result = gate_ui_icon_create_native(&this->impl, host.c_impl(), nativeHandle, flags);
199 GATEXX_CHECK_EXCEPTION(result);
200 }
201 Icon::Icon(Host& host, RasterImage const& image)
202 {
203 result_t result = gate_ui_icon_create_image(&this->impl, host.c_impl(), image.c_impl());
204 GATEXX_CHECK_EXCEPTION(result);
205 }
206 Icon::Icon(Host& host, String const& filePath)
207 {
208 result_t result = gate_ui_icon_create_file(&this->impl, *host, filePath.c_impl());
209 GATEXX_CHECK_EXCEPTION(result);
210 }
211 Icon::Icon(Icon const& src)
212 {
213 result_t result = gate_ui_icon_copy(&this->impl, &src.impl);
214 GATEXX_CHECK_EXCEPTION(result);
215 }
216
217 Icon& Icon::operator=(Icon const& src)
218 {
219 if (this != &src)
220 {
221 Icon that(src);
222 this->swap(that);
223 }
224 return *this;
225 }
226 Icon::~Icon() noexcept
227 {
228 gate_ui_icon_destroy(&this->impl);
229 }
230
231 gate_ui_icon_t const* Icon::c_impl() const noexcept
232 {
233 return &this->impl;
234 }
235
236 void Icon::swap(Icon& that)
237 {
238 gate::swapRefs(this->impl, that.impl);
239 }
240
241
242
243
244 const uint32_t Cursor::Flag_Stock = GATE_UI_CURSOR_FLAG_STOCK;
245
246 Cursor::Cursor(Host& host, StockIdEnum stockId)
247 {
248 result_t result = gate_ui_cursor_create_stock(&this->impl, host.c_impl(), (gate_uint32_t)stockId);
249 GATEXX_CHECK_EXCEPTION(result);
250 }
251 Cursor::Cursor(Host& host, void* nativeHandle, uint32_t flags)
252 {
253 result_t result = gate_ui_cursor_create_native(&this->impl, host.c_impl(), nativeHandle, flags);
254 GATEXX_CHECK_EXCEPTION(result);
255 }
256 Cursor::Cursor(Host& host, RasterImage const& image, uint16_t x, uint16_t y)
257 {
258 result_t result = gate_ui_cursor_create_image(&this->impl, host.c_impl(), image.c_impl(), x, y);
259 GATEXX_CHECK_EXCEPTION(result);
260 }
261 Cursor::Cursor(Host& host, String const& filePath)
262 {
263 result_t result = gate_ui_cursor_create_file(&this->impl, host.c_impl(), filePath.c_impl());
264 GATEXX_CHECK_EXCEPTION(result);
265 }
266 Cursor::Cursor(Cursor const& src)
267 {
268 result_t result = gate_ui_cursor_copy(&this->impl, &src.impl);
269 GATEXX_CHECK_EXCEPTION(result);
270 }
271
272 Cursor& Cursor::operator=(Cursor const& src)
273 {
274 if (this != &src)
275 {
276 Cursor that(src);
277 this->swap(that);
278 }
279 return *this;
280 }
281 Cursor::~Cursor() noexcept
282 {
283 gate_ui_cursor_destroy(&this->impl);
284 }
285
286 gate_ui_cursor_t const* Cursor::c_impl() const noexcept
287 {
288 return &this->impl;
289 }
290 void Cursor::swap(Cursor& that)
291 {
292 gate::swapRefsNoExcept(this->impl, that.impl);
293 }
294
295
296
297
298
299
300
301 } // end of namespace ui
302 } // end of namespace gate
303
304