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 |
|
|
/** Canvas Management (Canvas) */ |
19 |
|
|
/** */ |
20 |
|
|
/**************************************************************************/ |
21 |
|
|
|
22 |
|
|
#define GX_SOURCE_CODE |
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_canvas.h" |
30 |
|
|
|
31 |
|
|
/**************************************************************************/ |
32 |
|
|
/* */ |
33 |
|
|
/* FUNCTION RELEASE */ |
34 |
|
|
/* */ |
35 |
|
|
/* _gx_canvas_rotated_text_draw PORTABLE C */ |
36 |
|
|
/* 6.1 */ |
37 |
|
|
/* AUTHOR */ |
38 |
|
|
/* */ |
39 |
|
|
/* Kenneth Maxwell, Microsoft Corporation */ |
40 |
|
|
/* */ |
41 |
|
|
/* DESCRIPTION (deprecated) */ |
42 |
|
|
/* */ |
43 |
|
|
/* This function draws rotated text. */ |
44 |
|
|
/* This function is superseded by gx_canvas_rotated_text_draw_ext() */ |
45 |
|
|
/* */ |
46 |
|
|
/* INPUT */ |
47 |
|
|
/* */ |
48 |
|
|
/* text Pointer to string */ |
49 |
|
|
/* xcenter Center point for text drawing */ |
50 |
|
|
/* ycenter Center point for text drawing */ |
51 |
|
|
/* angle Angle at which to rotate text */ |
52 |
|
|
/* */ |
53 |
|
|
/* OUTPUT */ |
54 |
|
|
/* */ |
55 |
|
|
/* status Completion status */ |
56 |
|
|
/* */ |
57 |
|
|
/* CALLS */ |
58 |
|
|
/* */ |
59 |
|
|
/* _gx_utility_string_length_check Calculate string length */ |
60 |
|
|
/* _gx_canvas_rotated_text_draw_ext Extended rotated text draw */ |
61 |
|
|
/* */ |
62 |
|
|
/* CALLED BY */ |
63 |
|
|
/* */ |
64 |
|
|
/* Application Software */ |
65 |
|
|
/* */ |
66 |
|
|
/**************************************************************************/ |
67 |
|
|
#if defined(GX_ENABLE_DEPRECATED_STRING_API) |
68 |
|
6 |
UINT _gx_canvas_rotated_text_draw(GX_CONST GX_CHAR *text, |
69 |
|
|
GX_VALUE xcenter, |
70 |
|
|
GX_VALUE ycenter, |
71 |
|
|
INT angle) |
72 |
|
|
{ |
73 |
|
|
GX_STRING string; |
74 |
|
|
UINT status; |
75 |
|
|
|
76 |
|
6 |
string.gx_string_ptr = text; |
77 |
|
|
|
78 |
|
|
/* Calcualte text length. */ |
79 |
|
6 |
status = _gx_utility_string_length_check(text, &string.gx_string_length, GX_MAX_STRING_LENGTH); |
80 |
✓✓ |
6 |
if (status != GX_SUCCESS) |
81 |
|
|
{ |
82 |
|
1 |
return status; |
83 |
|
|
} |
84 |
|
|
|
85 |
|
5 |
status = _gx_canvas_rotated_text_draw_ext(&string, xcenter, ycenter, angle); |
86 |
|
|
|
87 |
|
5 |
return status; |
88 |
|
|
} |
89 |
|
|
#endif |
90 |
|
|
|
91 |
|
|
/**************************************************************************/ |
92 |
|
|
/* */ |
93 |
|
|
/* FUNCTION RELEASE */ |
94 |
|
|
/* */ |
95 |
|
|
/* _gx_canvas_rotated_text_draw_ext PORTABLE C */ |
96 |
|
|
/* 6.1.7 */ |
97 |
|
|
/* AUTHOR */ |
98 |
|
|
/* */ |
99 |
|
|
/* Kenneth Maxwell, Microsoft Corporation */ |
100 |
|
|
/* */ |
101 |
|
|
/* DESCRIPTION */ |
102 |
|
|
/* */ |
103 |
|
|
/* This function draws rotated text. */ |
104 |
|
|
/* */ |
105 |
|
|
/* INPUT */ |
106 |
|
|
/* */ |
107 |
|
|
/* text Pointer to string */ |
108 |
|
|
/* xcenter Center point for text drawing */ |
109 |
|
|
/* ycenter Center point for text drawing */ |
110 |
|
|
/* angle Angle at which to rotate text */ |
111 |
|
|
/* */ |
112 |
|
|
/* OUTPUT */ |
113 |
|
|
/* */ |
114 |
|
|
/* status Completion status */ |
115 |
|
|
/* */ |
116 |
|
|
/* CALLS */ |
117 |
|
|
/* */ |
118 |
|
|
/* _gx_system_string_width_get_ext Get width of the string in */ |
119 |
|
|
/* pixels */ |
120 |
|
|
/* _gx_canvas_text_draw Draw glyphs on canvas */ |
121 |
|
|
/* _gx_utility_string_to_alphamap Convert string to alpha-map */ |
122 |
|
|
/* _gx_utiity_pixelmap_rotate Rotate alphaap to desired */ |
123 |
|
|
/* angle */ |
124 |
|
|
/* _gx_canvas_pixelmap_draw Draw text alphamap */ |
125 |
|
|
/* _gx_system_memory_free Free memory used for rotated */ |
126 |
|
|
/* alphamap and canvas */ |
127 |
|
|
/* */ |
128 |
|
|
/* CALLED BY */ |
129 |
|
|
/* */ |
130 |
|
|
/* Application Software */ |
131 |
|
|
/* */ |
132 |
|
|
/**************************************************************************/ |
133 |
|
368 |
UINT _gx_canvas_rotated_text_draw_ext(GX_CONST GX_STRING *text, |
134 |
|
|
GX_VALUE xcenter, |
135 |
|
|
GX_VALUE ycenter, |
136 |
|
|
INT angle) |
137 |
|
|
{ |
138 |
|
|
GX_PIXELMAP textmap; |
139 |
|
|
GX_PIXELMAP rotated_map; |
140 |
|
|
INT x_pos; |
141 |
|
|
INT y_pos; |
142 |
|
|
GX_FONT *font; |
143 |
|
|
GX_VALUE alphamap_width; |
144 |
|
|
|
145 |
|
|
/* pickup pointer to current context */ |
146 |
|
368 |
GX_DRAW_CONTEXT *context = _gx_system_current_draw_context; |
147 |
|
|
|
148 |
✓✓ |
368 |
if (!context) |
149 |
|
|
{ |
150 |
|
1 |
return GX_FAILURE; |
151 |
|
|
} |
152 |
|
|
|
153 |
|
|
/* get pointer to current font */ |
154 |
|
367 |
font = context -> gx_draw_context_brush.gx_brush_font; |
155 |
|
|
|
156 |
✓✓ |
367 |
if (!font) |
157 |
|
|
{ |
158 |
|
1 |
return GX_FAILURE; |
159 |
|
|
} |
160 |
|
|
|
161 |
✓✓ |
547 |
while (angle >= 360) |
162 |
|
|
{ |
163 |
|
181 |
angle -= 360; |
164 |
|
|
} |
165 |
✓✓ |
545 |
while (angle <= -360) |
166 |
|
|
{ |
167 |
|
179 |
angle += 360; |
168 |
|
|
} |
169 |
|
|
|
170 |
✓✓ |
366 |
if (!angle) |
171 |
|
|
{ |
172 |
|
1 |
_gx_system_string_width_get_ext(font, text, &alphamap_width); |
173 |
|
1 |
x_pos = xcenter - (alphamap_width / 2); |
174 |
|
1 |
y_pos = ycenter - (font -> gx_font_line_height / 2); |
175 |
|
|
|
176 |
|
1 |
_gx_canvas_text_draw_ext((GX_VALUE)x_pos, (GX_VALUE)y_pos, text); |
177 |
|
1 |
return GX_SUCCESS; |
178 |
|
|
} |
179 |
|
|
|
180 |
✓✓ |
365 |
if (_gx_utility_string_to_alphamap_ext(text, font, &textmap) == GX_SUCCESS) |
181 |
|
|
{ |
182 |
|
|
/* Rotate the alpha map */ |
183 |
|
364 |
x_pos = y_pos = 0; |
184 |
|
|
|
185 |
✓✓ |
364 |
if (_gx_utility_pixelmap_rotate(&textmap, angle, &rotated_map, &x_pos, &y_pos) == GX_SUCCESS) |
186 |
|
|
{ |
187 |
|
363 |
x_pos = xcenter - (rotated_map.gx_pixelmap_width / 2); |
188 |
|
363 |
y_pos = ycenter - (rotated_map.gx_pixelmap_height / 2); |
189 |
|
|
|
190 |
|
|
/* draw the alpha-map to render the text */ |
191 |
|
|
#if defined(GX_RENESAS_DAVE2D_DRAW) |
192 |
|
|
rotated_map.gx_pixelmap_flags |= GX_PIXELMAP_DYNAMICALLY_ALLOCATED; |
193 |
|
|
#endif |
194 |
|
363 |
_gx_canvas_pixelmap_draw((GX_VALUE)x_pos, (GX_VALUE)y_pos, &rotated_map); |
195 |
|
|
|
196 |
|
|
/* free the rotated alphamap memory */ |
197 |
|
363 |
_gx_system_memory_free((void *)rotated_map.gx_pixelmap_data); |
198 |
|
|
} |
199 |
|
|
|
200 |
|
|
/* free the temporary canvas memory */ |
201 |
|
364 |
_gx_system_memory_free((void *)(textmap.gx_pixelmap_data)); |
202 |
|
|
} |
203 |
|
365 |
return GX_SUCCESS; |
204 |
|
|
} |
205 |
|
|
|