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_utility.h" |
29 |
|
|
#include "gx_display.h" |
30 |
|
|
|
31 |
|
|
|
32 |
|
|
/* Internal scratch area. */ |
33 |
|
|
static GX_FIXED_POINT LinePoints[5]; |
34 |
|
|
|
35 |
|
|
/**************************************************************************/ |
36 |
|
|
/* */ |
37 |
|
|
/* FUNCTION RELEASE */ |
38 |
|
|
/* */ |
39 |
|
|
/* _gx_display_driver_generic_wide_line_points_calculate */ |
40 |
|
|
/* PORTABLE C */ |
41 |
|
|
/* 6.1 */ |
42 |
|
|
/* */ |
43 |
|
|
/* AUTHOR */ |
44 |
|
|
/* */ |
45 |
|
|
/* Kenneth Maxwell, Microsoft Corporation */ |
46 |
|
|
/* */ |
47 |
|
|
/* DESCRIPTION */ |
48 |
|
|
/* */ |
49 |
|
|
/* Calculate corners of wide line. Used by all versions (anti-aliased */ |
50 |
|
|
/* or not, square or round ends) of wide line drawinggeneric display */ |
51 |
|
|
/* driver wide line drawing function. */ |
52 |
|
|
/* */ |
53 |
|
|
/* INPUT */ |
54 |
|
|
/* */ |
55 |
|
|
/* context Drawing context */ |
56 |
|
|
/* xStart x-coord of endpoint */ |
57 |
|
|
/* yStart y-coord of endpoint */ |
58 |
|
|
/* xEnd x-coord of endpoint */ |
59 |
|
|
/* yEnd y-coord of endpoint */ |
60 |
|
|
/* outline Whether or not to draw */ |
61 |
|
|
/* outline */ |
62 |
|
|
/* */ |
63 |
|
|
/* OUTPUT */ |
64 |
|
|
/* */ |
65 |
|
|
/* GX_POINT* Calculated end points */ |
66 |
|
|
/* */ |
67 |
|
|
/* CALLS */ |
68 |
|
|
/* */ |
69 |
|
|
/* GX_ABS Compute the absolute value */ |
70 |
|
|
/* GX_SWAP_VALS Swap two values */ |
71 |
|
|
/* GX_FIXED_VAL_MAKE */ |
72 |
|
|
/* GX_FIXED_VAL_RND */ |
73 |
|
|
/* _gx_utility_math_sqrt Compute the square root value */ |
74 |
|
|
/* [gx_display_driver_anti_aliased_line_draw */ |
75 |
|
|
/* Driver function that draws */ |
76 |
|
|
/* anti-aliased lines. */ |
77 |
|
|
/* */ |
78 |
|
|
/* CALLED BY */ |
79 |
|
|
/* */ |
80 |
|
|
/* _gx_display_driver_generic_simple_wide_line_draw */ |
81 |
|
|
/* _gx_display_driver_generic_aliased_wide_line_draw */ |
82 |
|
|
/* */ |
83 |
|
|
/**************************************************************************/ |
84 |
|
12565 |
GX_FIXED_POINT *_gx_display_driver_generic_wide_line_points_calculate(GX_DRAW_CONTEXT *context, INT xStart, INT yStart, |
85 |
|
|
INT xEnd, INT yEnd, INT brush_width, GX_BOOL outline) |
86 |
|
|
{ |
87 |
|
|
GX_FIXED_VAL distance; |
88 |
|
|
GX_FIXED_VAL brush_distance; |
89 |
|
|
GX_FIXED_POINT FixedPoints[5]; |
90 |
|
|
INT LineDirection[4]; |
91 |
|
|
int xsign; |
92 |
|
|
int ysign; |
93 |
|
|
int xside; |
94 |
|
|
int yside; |
95 |
|
|
VOID (*aliased_line)(GX_DRAW_CONTEXT *context, GX_FIXED_VAL x1, GX_FIXED_VAL y1, GX_FIXED_VAL x2, GX_FIXED_VAL y2); |
96 |
|
|
|
97 |
|
12565 |
int dx = GX_ABS(xEnd - xStart); |
98 |
|
12565 |
int dy = GX_ABS(yEnd - yStart); |
99 |
|
|
|
100 |
✓✓✓✓ ✓✓✓✓
|
12565 |
if (((dx >= dy && (xStart > xEnd)) || ((dy > dx) && yStart > yEnd))) |
101 |
|
|
{ |
102 |
|
5538 |
GX_SWAP_VALS(xEnd, xStart); |
103 |
|
5538 |
GX_SWAP_VALS(yEnd, yStart); |
104 |
|
|
} |
105 |
|
|
|
106 |
|
12565 |
distance = (GX_FIXED_VAL)_gx_utility_math_sqrt((UINT)(GX_FIXED_VAL_MAKE(dx * dx) + GX_FIXED_VAL_MAKE(dy * dy))); |
107 |
|
12565 |
distance <<= (GX_FIXED_VAL_SHIFT >> 1); |
108 |
|
12565 |
brush_distance = GX_FIXED_VAL_MAKE(brush_width - 1); |
109 |
|
12565 |
brush_distance >>= 1; |
110 |
|
12565 |
xsign = ysign = 1; |
111 |
|
|
|
112 |
✓✓ |
12565 |
if (dx) |
113 |
|
|
{ |
114 |
|
12562 |
xsign = (xEnd - xStart) / dx; |
115 |
|
|
} |
116 |
✓✓ |
12565 |
if (dy) |
117 |
|
|
{ |
118 |
|
12562 |
ysign = (yEnd - yStart) / dy; |
119 |
|
|
} |
120 |
|
|
|
121 |
|
12565 |
xside = dy; |
122 |
|
12565 |
xside *= brush_distance; |
123 |
|
12565 |
xside /= (distance >> GX_FIXED_VAL_SHIFT); |
124 |
|
12565 |
xside *= xsign; |
125 |
|
|
|
126 |
|
12565 |
yside = dx; |
127 |
|
12565 |
yside *= brush_distance; |
128 |
|
12565 |
yside /= (distance >> GX_FIXED_VAL_SHIFT); |
129 |
|
12565 |
yside *= ysign; |
130 |
|
|
|
131 |
|
12565 |
LineDirection[0] = 0; |
132 |
|
12565 |
LineDirection[1] = 1; |
133 |
|
12565 |
LineDirection[2] = 2; |
134 |
|
12565 |
LineDirection[3] = 3; |
135 |
|
|
|
136 |
✓✓ |
12565 |
if (yEnd < yStart) |
137 |
|
|
{ |
138 |
|
2749 |
LineDirection[1] = 3; |
139 |
|
2749 |
LineDirection[3] = 1; |
140 |
|
|
} |
141 |
|
|
|
142 |
✓✓ |
12565 |
if (xEnd < xStart) |
143 |
|
|
{ |
144 |
|
2349 |
LineDirection[0] = 2; |
145 |
|
2349 |
LineDirection[2] = 0; |
146 |
|
|
} |
147 |
|
|
|
148 |
|
12565 |
FixedPoints[LineDirection[0]].x = GX_FIXED_VAL_MAKE(xStart) - xside; |
149 |
|
12565 |
FixedPoints[LineDirection[0]].y = GX_FIXED_VAL_MAKE(yStart) + yside; |
150 |
|
12565 |
FixedPoints[LineDirection[1]].x = GX_FIXED_VAL_MAKE(xStart) + xside; |
151 |
|
12565 |
FixedPoints[LineDirection[1]].y = GX_FIXED_VAL_MAKE(yStart) - yside; |
152 |
|
12565 |
FixedPoints[LineDirection[2]].x = GX_FIXED_VAL_MAKE(xEnd) + xside; |
153 |
|
12565 |
FixedPoints[LineDirection[2]].y = GX_FIXED_VAL_MAKE(yEnd) - yside; |
154 |
|
12565 |
FixedPoints[LineDirection[3]].x = GX_FIXED_VAL_MAKE(xEnd) - xside; |
155 |
|
12565 |
FixedPoints[LineDirection[3]].y = GX_FIXED_VAL_MAKE(yEnd) + yside; |
156 |
|
|
|
157 |
|
12565 |
LinePoints[0] = FixedPoints[0]; |
158 |
|
12565 |
LinePoints[1] = FixedPoints[1]; |
159 |
|
12565 |
LinePoints[2] = FixedPoints[2]; |
160 |
|
12565 |
LinePoints[3] = FixedPoints[3]; |
161 |
|
|
|
162 |
✓✓ |
12565 |
if (outline) |
163 |
|
|
{ |
164 |
|
5208 |
aliased_line = _gx_display_driver_generic_aliased_fixed_point_line_draw; |
165 |
|
|
|
166 |
|
5208 |
aliased_line(context, FixedPoints[0].x, |
167 |
|
|
FixedPoints[0].y, |
168 |
|
|
FixedPoints[1].x, |
169 |
|
|
FixedPoints[1].y); |
170 |
|
|
|
171 |
|
5208 |
aliased_line(context, FixedPoints[1].x, |
172 |
|
|
FixedPoints[1].y, |
173 |
|
|
FixedPoints[2].x, |
174 |
|
|
FixedPoints[2].y); |
175 |
|
|
|
176 |
|
5208 |
aliased_line(context, FixedPoints[2].x, |
177 |
|
|
FixedPoints[2].y, |
178 |
|
|
FixedPoints[3].x, |
179 |
|
|
FixedPoints[3].y); |
180 |
|
|
|
181 |
|
5208 |
aliased_line(context, FixedPoints[3].x, |
182 |
|
|
FixedPoints[3].y, |
183 |
|
|
FixedPoints[0].x, |
184 |
|
|
FixedPoints[0].y); |
185 |
|
|
} |
186 |
|
|
|
187 |
|
|
/* close the polygon */ |
188 |
|
12565 |
LinePoints[4] = LinePoints[0]; |
189 |
|
|
|
190 |
|
12565 |
return(LinePoints); |
191 |
|
|
} |
192 |
|
|
|