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_utility.h"
28 #include "gx_display.h"
29
30
31 /**************************************************************************/
32 /* */
33 /* FUNCTION RELEASE */
34 /* */
35 /* _gx_display_driver_generic_simple_wide_line_draw PORTABLE C */
36 /* 6.1.3 */
37 /* AUTHOR */
38 /* */
39 /* Kenneth Maxwell, Microsoft Corporation */
40 /* */
41 /* DESCRIPTION */
42 /* */
43 /* Generic display driver function for non-aliased wide line. */
44 /* */
45 /* INPUT */
46 /* */
47 /* context Drawing context */
48 /* xstart x-coord of endpoint */
49 /* ystart y-coord of endpoint */
50 /* xend x-coord of endpoint */
51 /* yend y-coord of endpoint */
52 /* */
53 /* OUTPUT */
54 /* */
55 /* None */
56 /* */
57 /* CALLS */
58 /* */
59 /* _gx_display_driver_generic_wide_line_points_calculate */
60 /* Calculate corners of wide line*/
61 /* _gx_display_driver_generic_filled_circle_draw */
62 /* Basic display driver solid */
63 /* circle draw function */
64 /* _gx_display_driver_generic_wide_line_fill */
65 /* Basic display driver wide */
66 /* line draw function */
67 /* */
68 /* CALLED BY */
69 /* */
70 /* GUIX Internal 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 /* 12-31-2020 Kenneth Maxwell Modified comment(s), */
80 /* supported display rotation, */
81 /* resulting in version 6.1.3 */
82 /* */
83 /**************************************************************************/
_gx_display_driver_generic_simple_wide_line_draw(GX_DRAW_CONTEXT * context,INT xstart,INT ystart,INT xend,INT yend)84 VOID _gx_display_driver_generic_simple_wide_line_draw(GX_DRAW_CONTEXT *context, INT xstart, INT ystart,
85 INT xend, INT yend)
86 {
87 GX_DISPLAY *display = context -> gx_draw_context_display;
88 GX_FIXED_POINT *line_points;
89 INT brush_width = context -> gx_draw_context_brush.gx_brush_width;
90 GX_RECTANGLE clip_rect;
91 GX_FIXED_VAL sxcenter;
92 GX_FIXED_VAL sycenter;
93 GX_FIXED_VAL excenter;
94 GX_FIXED_VAL eycenter;
95
96 #if defined(GX_BRUSH_ALPHA_SUPPORT)
97 GX_UBYTE old_alpha;
98 old_alpha = context -> gx_draw_context_brush.gx_brush_alpha;
99 if (context -> gx_draw_context_brush.gx_brush_style & GX_BRUSH_ROUND)
100 {
101 context -> gx_draw_context_brush.gx_brush_alpha = GX_ALPHA_VALUE_OPAQUE;
102 }
103 #endif
104
105 if ((context -> gx_draw_context_brush.gx_brush_style & GX_BRUSH_ROUND) &&
106 (brush_width > 2))
107 {
108 sxcenter = GX_FIXED_VAL_MAKE(xstart);
109 sycenter = GX_FIXED_VAL_MAKE(ystart);
110 excenter = GX_FIXED_VAL_MAKE(xend);
111 eycenter = GX_FIXED_VAL_MAKE(yend);
112
113 if (!(brush_width & 0x01))
114 {
115 if (ystart == yend)
116 {
117 /* Horizontal line. */
118 sycenter -= GX_FIXED_VAL_HALF;
119 eycenter -= GX_FIXED_VAL_HALF;
120 }
121 else if (xstart == xend)
122 {
123 /* Vertical line. */
124 sxcenter -= GX_FIXED_VAL_HALF;
125 excenter -= GX_FIXED_VAL_HALF;
126 }
127 }
128
129 _gx_display_driver_generic_filled_circle_draw(context, sxcenter, sycenter,
130 GX_FIXED_VAL_MAKE(brush_width) >> 1);
131
132 _gx_display_driver_generic_filled_circle_draw(context, excenter, eycenter,
133 GX_FIXED_VAL_MAKE(brush_width) >> 1);
134 }
135
136 if (ystart == yend)
137 {
138 /* Horizontal line. */
139
140 if (xstart > xend)
141 {
142 GX_SWAP_VALS(xstart, xend);
143 }
144
145 clip_rect.gx_rectangle_left = (GX_VALUE)xstart;
146 clip_rect.gx_rectangle_right = (GX_VALUE)xend;
147 clip_rect.gx_rectangle_top = (GX_VALUE)(ystart - (brush_width >> 1));
148 clip_rect.gx_rectangle_bottom = (GX_VALUE)(clip_rect.gx_rectangle_top + brush_width - 1);
149
150 if (_gx_utility_rectangle_overlap_detect(&clip_rect, context -> gx_draw_context_clip, &clip_rect))
151 {
152 display -> gx_display_driver_horizontal_line_draw(context,
153 clip_rect.gx_rectangle_left,
154 clip_rect.gx_rectangle_right,
155 clip_rect.gx_rectangle_top,
156 clip_rect.gx_rectangle_bottom - clip_rect.gx_rectangle_top + 1,
157 context -> gx_draw_context_brush.gx_brush_line_color);
158 }
159 }
160 else if (xstart == xend)
161 {
162 /* Vertical line. */
163
164 if (ystart > yend)
165 {
166 GX_SWAP_VALS(ystart, yend);
167 }
168
169 clip_rect.gx_rectangle_left = (GX_VALUE)(xstart - (brush_width >> 1));
170 clip_rect.gx_rectangle_right = (GX_VALUE)(clip_rect.gx_rectangle_left + brush_width - 1);
171 clip_rect.gx_rectangle_top = (GX_VALUE)ystart;
172 clip_rect.gx_rectangle_bottom = (GX_VALUE)yend;
173
174 if (_gx_utility_rectangle_overlap_detect(&clip_rect, context -> gx_draw_context_clip, &clip_rect))
175 {
176 display -> gx_display_driver_vertical_line_draw(context,
177 clip_rect.gx_rectangle_top,
178 clip_rect.gx_rectangle_bottom,
179 clip_rect.gx_rectangle_left,
180 clip_rect.gx_rectangle_right - clip_rect.gx_rectangle_left + 1,
181 context -> gx_draw_context_brush.gx_brush_line_color);
182 }
183 }
184 else
185 {
186 /* calcualte the corners of this line, save them
187 to our points array
188 */
189 line_points = _gx_display_driver_generic_wide_line_points_calculate(context, xstart, ystart,
190 xend, yend, brush_width, GX_FALSE);
191 if (display -> gx_display_rotation_angle)
192 {
193 _gx_display_driver_generic_rotated_wide_line_fill(context, line_points);
194 }
195 else
196 {
197 _gx_display_driver_generic_wide_line_fill(context, line_points);
198 }
199 }
200 #if defined(GX_BRUSH_ALPHA_SUPPORT)
201 context -> gx_draw_context_brush.gx_brush_alpha = old_alpha;
202 #endif
203 }
204
205