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 |
|
|
|
32 |
|
|
|
33 |
|
|
/**************************************************************************/ |
34 |
|
|
/* */ |
35 |
|
|
/* FUNCTION RELEASE */ |
36 |
|
|
/* */ |
37 |
|
|
/* _gx_display_driver_generic_circle_draw PORTABLE C */ |
38 |
|
|
/* 6.1 */ |
39 |
|
|
/* AUTHOR */ |
40 |
|
|
/* */ |
41 |
|
|
/* Kenneth Maxwell, Microsoft Corporation */ |
42 |
|
|
/* */ |
43 |
|
|
/* DESCRIPTION */ |
44 |
|
|
/* */ |
45 |
|
|
/* Display driver to draw circle. */ |
46 |
|
|
/* */ |
47 |
|
|
/* INPUT */ |
48 |
|
|
/* */ |
49 |
|
|
/* context Drawing context */ |
50 |
|
|
/* xcenter x-coord of center of circle */ |
51 |
|
|
/* ycenter y-coord of center of circle */ |
52 |
|
|
/* r Radius of circle */ |
53 |
|
|
/* */ |
54 |
|
|
/* OUTPUT */ |
55 |
|
|
/* */ |
56 |
|
|
/* None */ |
57 |
|
|
/* */ |
58 |
|
|
/* CALLS */ |
59 |
|
|
/* */ |
60 |
|
|
/* [gx_display_driver_pixel_blend] Basic display driver pixel */ |
61 |
|
|
/* blend function */ |
62 |
|
|
/* _gx_utility_rectangle_point_detect Detect whether a pixel is */ |
63 |
|
|
/* inside rectangle */ |
64 |
|
|
/* [gx_display_driver_pixel_write] Basic display driver pixel */ |
65 |
|
|
/* write function */ |
66 |
|
|
/* */ |
67 |
|
|
/* CALLED BY */ |
68 |
|
|
/* */ |
69 |
|
|
/* GUIX Internal Code */ |
70 |
|
|
/* */ |
71 |
|
|
/**************************************************************************/ |
72 |
|
|
#if defined(GX_ARC_DRAWING_SUPPORT) |
73 |
|
|
|
74 |
|
387 |
VOID _gx_display_driver_generic_circle_draw(GX_DRAW_CONTEXT *context, INT xcenter, INT ycenter, UINT r) |
75 |
|
|
{ |
76 |
|
|
/* The circle draw function is implemented from midpoint circle algorithm. */ |
77 |
|
|
INT x; |
78 |
|
|
INT y; |
79 |
|
|
INT d; |
80 |
|
|
GX_POINT point; |
81 |
|
387 |
INT sign[4][2] = { {1, 1}, {-1, 1}, {1, -1}, {-1, -1} }; |
82 |
|
|
INT index; |
83 |
|
|
|
84 |
|
387 |
GX_RECTANGLE *clip = context -> gx_draw_context_clip; |
85 |
|
387 |
GX_DISPLAY *display = context -> gx_draw_context_display; |
86 |
|
387 |
GX_BRUSH *brush = &context -> gx_draw_context_brush; |
87 |
|
|
|
88 |
|
|
#if defined(GX_BRUSH_ALPHA_SUPPORT) |
89 |
|
387 |
GX_UBYTE brush_alpha = brush -> gx_brush_alpha; |
90 |
|
|
|
91 |
✓✓ |
387 |
if (display -> gx_display_driver_pixel_blend == GX_NULL) |
92 |
|
|
{ |
93 |
|
|
/* Pixel blend function is null means alpha isn't supported in this driver. |
94 |
|
|
So set alpha value to 0xff to make it draw the original color in case GX_BRUSH_ALPHA_SUPPORT is defined. */ |
95 |
|
52 |
brush_alpha = 0xff; |
96 |
|
|
} |
97 |
|
|
else |
98 |
|
|
{ |
99 |
✓✓ |
335 |
if (brush_alpha == 0) |
100 |
|
|
{ |
101 |
|
|
/* Nothing to draw here. */ |
102 |
|
96 |
return; |
103 |
|
|
} |
104 |
|
|
} |
105 |
|
|
#endif |
106 |
|
|
|
107 |
|
291 |
x = 0; |
108 |
|
291 |
y = (INT)r; |
109 |
|
291 |
d = 5 - (INT)(4 * r); |
110 |
|
|
#if defined (GX_BRUSH_ALPHA_SUPPORT) |
111 |
✓✓ |
291 |
if (brush_alpha != 0xff) |
112 |
|
|
{ |
113 |
✓✓ |
10188 |
while (x <= y) |
114 |
|
|
{ |
115 |
✓✓ |
50400 |
for (index = 0; index < 4; index++) |
116 |
|
|
{ |
117 |
|
40320 |
point.gx_point_x = (GX_VALUE)(x * sign[index][0] + xcenter); |
118 |
|
40320 |
point.gx_point_y = (GX_VALUE)(y * sign[index][1] + ycenter); |
119 |
|
|
|
120 |
✓✓ |
40320 |
if (_gx_utility_rectangle_point_detect(clip, point)) |
121 |
|
|
{ |
122 |
|
31776 |
display -> gx_display_driver_pixel_blend(context, point.gx_point_x, point.gx_point_y, brush -> gx_brush_line_color, brush_alpha); |
123 |
|
|
} |
124 |
|
|
|
125 |
|
40320 |
point.gx_point_x = (GX_VALUE)(y * sign[index][0] + xcenter); |
126 |
|
40320 |
point.gx_point_y = (GX_VALUE)(x * sign[index][1] + ycenter); |
127 |
|
|
|
128 |
✓✓ |
40320 |
if (_gx_utility_rectangle_point_detect(clip, point)) |
129 |
|
|
{ |
130 |
|
23040 |
display -> gx_display_driver_pixel_blend(context, point.gx_point_x, point.gx_point_y, brush -> gx_brush_line_color, brush_alpha); |
131 |
|
|
} |
132 |
|
|
} |
133 |
|
|
|
134 |
✓✓ |
10080 |
if (d < 0) |
135 |
|
|
{ |
136 |
|
5856 |
d += 8 * x + 12; |
137 |
|
|
} |
138 |
|
|
else |
139 |
|
|
{ |
140 |
|
4224 |
d += 8 * (x - y) + 20; |
141 |
|
4224 |
y--; |
142 |
|
|
} |
143 |
|
10080 |
x++; |
144 |
|
|
} |
145 |
|
|
} |
146 |
|
|
else |
147 |
|
|
{ |
148 |
|
|
#endif |
149 |
✓✓ |
16838 |
while (x <= y) |
150 |
|
|
{ |
151 |
✓✓ |
83275 |
for (index = 0; index < 4; index++) |
152 |
|
|
{ |
153 |
|
66620 |
point.gx_point_x = (GX_VALUE)(x * sign[index][0] + xcenter); |
154 |
|
66620 |
point.gx_point_y = (GX_VALUE)(y * sign[index][1] + ycenter); |
155 |
|
|
|
156 |
✓✓ |
66620 |
if (_gx_utility_rectangle_point_detect(clip, point)) |
157 |
|
|
{ |
158 |
|
56024 |
display -> gx_display_driver_pixel_write(context, point.gx_point_x, point.gx_point_y, brush -> gx_brush_line_color); |
159 |
|
|
} |
160 |
|
|
|
161 |
|
66620 |
point.gx_point_x = (GX_VALUE)(y * sign[index][0] + xcenter); |
162 |
|
66620 |
point.gx_point_y = (GX_VALUE)(x * sign[index][1] + ycenter); |
163 |
|
|
|
164 |
✓✓ |
66620 |
if (_gx_utility_rectangle_point_detect(clip, point)) |
165 |
|
|
{ |
166 |
|
47074 |
display -> gx_display_driver_pixel_write(context, point.gx_point_x, point.gx_point_y, brush -> gx_brush_line_color); |
167 |
|
|
} |
168 |
|
|
} |
169 |
|
|
|
170 |
✓✓ |
16655 |
if (d < 0) |
171 |
|
|
{ |
172 |
|
9657 |
d += 8 * x + 12; |
173 |
|
|
} |
174 |
|
|
else |
175 |
|
|
{ |
176 |
|
6998 |
d += 8 * (x - y) + 20; |
177 |
|
6998 |
y--; |
178 |
|
|
} |
179 |
|
16655 |
x++; |
180 |
|
|
} |
181 |
|
|
#if defined (GX_BRUSH_ALPHA_SUPPORT) |
182 |
|
|
} |
183 |
|
|
#endif |
184 |
|
|
} |
185 |
|
|
|
186 |
|
|
#endif |
187 |
|
|
|