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