1 |
|
|
/*************************************************************************** |
2 |
|
|
* Copyright (c) 2024 Microsoft Corporation |
3 |
|
|
* Copyright (c) 2026-present Eclipse ThreadX contributors |
4 |
|
|
* |
5 |
|
|
* This program and the accompanying materials are made available under the |
6 |
|
|
* terms of the MIT License which is available at |
7 |
|
|
* https://opensource.org/licenses/MIT. |
8 |
|
|
* |
9 |
|
|
* SPDX-License-Identifier: MIT |
10 |
|
|
**************************************************************************/ |
11 |
|
|
|
12 |
|
|
|
13 |
|
|
/**************************************************************************/ |
14 |
|
|
/**************************************************************************/ |
15 |
|
|
/** */ |
16 |
|
|
/** GUIX Component */ |
17 |
|
|
/** */ |
18 |
|
|
/** Display Management (Display) */ |
19 |
|
|
/** */ |
20 |
|
|
/**************************************************************************/ |
21 |
|
|
|
22 |
|
|
#define GX_SOURCE_CODE |
23 |
|
|
|
24 |
|
|
|
25 |
|
|
/* Include necessary system files. */ |
26 |
|
|
|
27 |
|
|
#include "gx_api.h" |
28 |
|
|
#include "gx_system.h" |
29 |
|
|
#include "gx_utility.h" |
30 |
|
|
#include "gx_display.h" |
31 |
|
|
#include "gx_canvas.h" |
32 |
|
|
|
33 |
|
|
|
34 |
|
|
/**************************************************************************/ |
35 |
|
|
/* */ |
36 |
|
|
/* FUNCTION RELEASE */ |
37 |
|
|
/* */ |
38 |
|
|
/* _gx_canvas_arc_draw PORTABLE C */ |
39 |
|
|
/* 6.1 */ |
40 |
|
|
/* AUTHOR */ |
41 |
|
|
/* */ |
42 |
|
|
/* Kenneth Maxwell, Microsoft Corporation */ |
43 |
|
|
/* */ |
44 |
|
|
/* DESCRIPTION */ |
45 |
|
|
/* */ |
46 |
|
|
/* This draws a circle arc into the currrent context. */ |
47 |
|
|
/* */ |
48 |
|
|
/* INPUT */ |
49 |
|
|
/* */ |
50 |
|
|
/* xcenter x-coord of center of circle */ |
51 |
|
|
/* arc */ |
52 |
|
|
/* ycenter y-coord of center of circle */ |
53 |
|
|
/* arc */ |
54 |
|
|
/* r Radius of circle arc */ |
55 |
|
|
/* start_angle The start angle of circle arc */ |
56 |
|
|
/* end_angle The end angle of circle arc */ |
57 |
|
|
/* */ |
58 |
|
|
/* OUTPUT */ |
59 |
|
|
/* */ |
60 |
|
|
/* None */ |
61 |
|
|
/* */ |
62 |
|
|
/* CALLS */ |
63 |
|
|
/* */ |
64 |
|
|
/* _gx_utility_rectangle_define */ |
65 |
|
|
/* _gx_utility_rectangle_overlap_detect */ |
66 |
|
|
/* _gx_display_driver_arc_draw */ |
67 |
|
|
/* _gx_display_driver_anti_aliased_arc_draw */ |
68 |
|
|
/* */ |
69 |
|
|
/* CALLED BY */ |
70 |
|
|
/* */ |
71 |
|
|
/* Application code */ |
72 |
|
|
/* */ |
73 |
|
|
/**************************************************************************/ |
74 |
|
|
#if defined(GX_ARC_DRAWING_SUPPORT) |
75 |
|
7236 |
UINT _gx_canvas_arc_draw(INT xcenter, INT ycenter, UINT r, INT start_angle, INT end_angle) |
76 |
|
|
{ |
77 |
|
|
GX_DRAW_CONTEXT *context; |
78 |
|
|
GX_DISPLAY *display; |
79 |
|
|
GX_RECTANGLE bound; |
80 |
|
|
GX_RECTANGLE clip_rect; |
81 |
|
|
GX_VIEW *view; |
82 |
|
|
GX_BRUSH *brush; |
83 |
|
|
UINT brush_width; |
84 |
|
|
VOID (*outline_function)(GX_DRAW_CONTEXT *context, INT xcenter, INT ycenter, UINT r, INT start_angle, INT end_angle); |
85 |
|
|
|
86 |
✓✓ |
10241 |
while (start_angle < 0) |
87 |
|
|
{ |
88 |
|
3005 |
start_angle += 360; |
89 |
|
|
} |
90 |
|
|
|
91 |
✓✓ |
7309 |
while (end_angle < 0) |
92 |
|
|
{ |
93 |
|
73 |
end_angle += 360; |
94 |
|
|
} |
95 |
|
|
|
96 |
✓✓ |
7236 |
if (start_angle >= 360) |
97 |
|
|
{ |
98 |
|
138 |
start_angle %= 360; |
99 |
|
|
} |
100 |
|
|
|
101 |
✓✓ |
7236 |
if (end_angle >= 360) |
102 |
|
|
{ |
103 |
|
807 |
end_angle %= 360; |
104 |
|
|
} |
105 |
|
|
|
106 |
✓✓ |
7236 |
if (end_angle <= start_angle) |
107 |
|
|
{ |
108 |
|
3684 |
end_angle += 360; |
109 |
|
|
} |
110 |
|
|
|
111 |
|
|
|
112 |
|
|
/* pick up the current drawing context */ |
113 |
|
7236 |
context = _gx_system_current_draw_context; |
114 |
|
|
|
115 |
|
7236 |
brush = &context -> gx_draw_context_brush; |
116 |
|
|
|
117 |
|
7236 |
brush_width = (UINT)((brush -> gx_brush_width + 1) >> 1); |
118 |
|
|
|
119 |
|
7236 |
_gx_utility_rectangle_define(&bound, (GX_VALUE)((UINT)xcenter - r - brush_width), (GX_VALUE)((UINT)ycenter - r - brush_width), |
120 |
|
7236 |
(GX_VALUE)((UINT)xcenter + r + brush_width), (GX_VALUE)((UINT)ycenter + r + brush_width)); |
121 |
|
|
|
122 |
|
7236 |
brush_width = (UINT)brush -> gx_brush_width; |
123 |
|
|
|
124 |
|
|
/* clip the arc bounding box to the dirty rectangle */ |
125 |
✓✓ |
7236 |
if (!_gx_utility_rectangle_overlap_detect(&bound, &context -> gx_draw_context_dirty, &bound)) |
126 |
|
|
{ |
127 |
|
|
/* nothing to draw, return */ |
128 |
|
5 |
return GX_SUCCESS; |
129 |
|
|
} |
130 |
|
|
|
131 |
|
|
/* pick up current display driver */ |
132 |
|
7231 |
display = context -> gx_draw_context_display; |
133 |
|
|
|
134 |
|
|
/* Default to no outline */ |
135 |
|
7231 |
outline_function = GX_NULL; |
136 |
|
|
|
137 |
|
|
/* Determine which outline function to use.*/ |
138 |
✓✓ |
7231 |
if (brush_width == 1) |
139 |
|
|
{ |
140 |
|
|
/* if anti-alias is requested and this is supported by display, use it */ |
141 |
✓✓ |
295 |
if ((brush -> gx_brush_style & GX_BRUSH_ALIAS) && |
142 |
✓✓ |
190 |
display -> gx_display_driver_anti_aliased_arc_draw != GX_NULL) |
143 |
|
|
{ |
144 |
|
126 |
outline_function = display -> gx_display_driver_anti_aliased_arc_draw; |
145 |
|
|
} |
146 |
|
|
else |
147 |
|
|
{ |
148 |
|
|
/* otherwise use non-aliased outline */ |
149 |
|
169 |
outline_function = display -> gx_display_driver_arc_draw; |
150 |
|
|
} |
151 |
|
|
} |
152 |
|
|
else |
153 |
|
|
{ |
154 |
✓✓ |
6936 |
if (brush_width > 1) |
155 |
|
|
{ |
156 |
|
|
/* if anti-alias is requested and this is supported by display, use it */ |
157 |
✓✓ |
6807 |
if ((brush -> gx_brush_style & GX_BRUSH_ALIAS) && |
158 |
✓✓ |
6142 |
display -> gx_display_driver_anti_aliased_wide_arc_draw) |
159 |
|
|
{ |
160 |
|
5770 |
outline_function = display -> gx_display_driver_anti_aliased_wide_arc_draw; |
161 |
|
|
} |
162 |
|
|
else |
163 |
|
|
{ |
164 |
|
|
/* otherwise use non-aliased outline */ |
165 |
|
1037 |
outline_function = display -> gx_display_driver_wide_arc_draw; |
166 |
|
|
} |
167 |
|
|
} |
168 |
|
|
} |
169 |
|
|
|
170 |
|
|
/* test to determine if the bounding rectangle overlaps the region we are allowed to draw |
171 |
|
|
into. For each view that overlaps the bounding rectangle, do some drawing. |
172 |
|
|
*/ |
173 |
|
7231 |
view = context -> gx_draw_context_view_head; |
174 |
|
|
|
175 |
✓✓ |
14465 |
while (view) |
176 |
|
|
{ |
177 |
✓✓ |
7234 |
if (!_gx_utility_rectangle_overlap_detect(&view -> gx_view_rectangle, &bound, &clip_rect)) |
178 |
|
|
{ |
179 |
|
4 |
view = view -> gx_view_next; |
180 |
|
4 |
continue; |
181 |
|
|
} |
182 |
|
|
|
183 |
|
|
/* we have a view into which we can draw the arc, do it */ |
184 |
|
7230 |
GX_RECTANGLE *original_clip = context->gx_draw_context_clip; |
185 |
|
7230 |
context -> gx_draw_context_clip = &clip_rect; |
186 |
|
|
|
187 |
✓✓ |
7230 |
if (brush -> gx_brush_style & (GX_BRUSH_SOLID_FILL | GX_BRUSH_PIXELMAP_FILL)) |
188 |
|
|
{ |
189 |
|
919 |
display -> gx_display_driver_arc_fill(context, xcenter, ycenter, r, start_angle, end_angle); |
190 |
|
|
} |
191 |
|
|
|
192 |
✓✓ |
7230 |
if (outline_function) |
193 |
|
|
{ |
194 |
|
7101 |
outline_function(context, xcenter, ycenter, r, start_angle, end_angle); |
195 |
|
|
} |
196 |
|
7230 |
view = view -> gx_view_next; |
197 |
|
7230 |
context -> gx_draw_context_clip = original_clip; |
198 |
|
|
} |
199 |
|
|
|
200 |
|
|
/* Return successful completion. */ |
201 |
|
7231 |
return(GX_SUCCESS); |
202 |
|
|
} |
203 |
|
|
|
204 |
|
|
#endif |
205 |
|
|
|