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 /* FUNCTION RELEASE */
35 /* */
36 /* _gx_canvas_circle_draw PORTABLE C */
37 /* 6.1 */
38 /* AUTHOR */
39 /* */
40 /* Kenneth Maxwell, Microsoft Corporation */
41 /* */
42 /* DESCRIPTION */
43 /* */
44 /* This draws a circle into the currrent context. */
45 /* */
46 /* INPUT */
47 /* */
48 /* xcenter x-coord of center of circle */
49 /* ycenter y-coord of center of circle */
50 /* r Radius of circle */
51 /* */
52 /* OUTPUT */
53 /* */
54 /* None */
55 /* */
56 /* CALLS */
57 /* */
58 /* _gx_utility_rectangle_define Define a rectangle */
59 /* _gx_utility_rectangle_overlap_detect Detects two rectangles being */
60 /* overlap */
61 /* [gx_display_driver_arc_draw] Display driver basic */
62 /* arc drawing routine */
63 /* */
64 /* CALLED BY */
65 /* */
66 /* Application code */
67 /* */
68 /* RELEASE HISTORY */
69 /* */
70 /* DATE NAME DESCRIPTION */
71 /* */
72 /* 05-19-2020 Kenneth Maxwell Initial Version 6.0 */
73 /* 09-30-2020 Kenneth Maxwell Modified comment(s), */
74 /* resulting in version 6.1 */
75 /* */
76 /**************************************************************************/
77 #if defined(GX_ARC_DRAWING_SUPPORT)
_gx_canvas_circle_draw(INT xcenter,INT ycenter,UINT r)78 UINT _gx_canvas_circle_draw(INT xcenter, INT ycenter, UINT r)
79 {
80 GX_DRAW_CONTEXT *context;
81 GX_DISPLAY *display;
82 GX_RECTANGLE bound;
83 GX_RECTANGLE clip_rect;
84 GX_VIEW *view;
85 GX_BRUSH *brush;
86 INT brush_width;
87 VOID (*outline_function)(GX_DRAW_CONTEXT *context, INT xcenter, INT ycenter, UINT r);
88
89 /* pick up the current drawing context */
90 context = _gx_system_current_draw_context;
91
92 brush = &context -> gx_draw_context_brush;
93
94 brush_width = (brush -> gx_brush_width + 1) >> 1;
95
96 _gx_utility_rectangle_define(&bound, (GX_VALUE)(xcenter - (INT)r - brush_width), (GX_VALUE)(ycenter - (INT)r - brush_width),
97 (GX_VALUE)(xcenter + (INT)r + brush_width), (GX_VALUE)(ycenter + (INT)r + brush_width));
98
99 brush_width = brush -> gx_brush_width;
100
101 /* clip the circle bounding box to the dirty rectangle */
102 if (!_gx_utility_rectangle_overlap_detect(&bound, &context -> gx_draw_context_dirty, &bound))
103 {
104 /* nothing to draw, return */
105 return GX_SUCCESS;
106 }
107
108 /* pick up current display driver */
109 display = context -> gx_draw_context_display;
110
111 /* configure outline function to utilize */
112 outline_function = GX_NULL;
113
114 /*Set normal outline draw function.*/
115 if (brush_width == 1)
116 {
117 /* if anti-alias is requested and this is supported by display, use it */
118 if ((brush -> gx_brush_style & GX_BRUSH_ALIAS) &&
119 display -> gx_display_driver_anti_aliased_circle_draw != GX_NULL)
120 {
121 outline_function = display -> gx_display_driver_anti_aliased_circle_draw;
122 }
123 else
124 {
125 /* otherwise use non-aliased outline */
126 outline_function = display -> gx_display_driver_circle_draw;
127 }
128 }
129 else
130 {
131 if (brush_width > 1)
132 {
133 /* if anti-alias is requested and this is supported by display, use it */
134 if ((brush -> gx_brush_style & GX_BRUSH_ALIAS) &&
135 display -> gx_display_driver_anti_aliased_wide_circle_draw != GX_NULL )
136 {
137 outline_function = display -> gx_display_driver_anti_aliased_wide_circle_draw;
138 }
139 else
140 {
141 /* otherwise use non-aliased outline */
142 outline_function = display -> gx_display_driver_wide_circle_draw;
143 }
144 }
145 }
146
147 /* test to determine if the bounding rectangle overlaps the region we are allowed to draw
148 into. For each view that overlaps the bounding rectangle, do some drawing.
149 */
150 view = context -> gx_draw_context_view_head;
151
152 while (view)
153 {
154 if (!_gx_utility_rectangle_overlap_detect(&view -> gx_view_rectangle, &bound, &clip_rect))
155 {
156 view = view -> gx_view_next;
157 continue;
158 }
159
160 /* we have a view into which we can draw the line, do it */
161 context -> gx_draw_context_clip = &clip_rect;
162
163 if (brush -> gx_brush_style & (GX_BRUSH_SOLID_FILL | GX_BRUSH_PIXELMAP_FILL))
164 {
165 display -> gx_display_driver_circle_fill(context, xcenter, ycenter, r);
166 }
167
168 if (outline_function)
169 {
170 outline_function(context, xcenter, ycenter, r);
171 }
172
173 view = view -> gx_view_next;
174 }
175
176 /* Return successful completion. */
177 return(GX_SUCCESS);
178 }
179 #endif
180
181