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 |
|
|
/** Widget Management (Widget) */ |
19 |
|
|
/** */ |
20 |
|
|
/**************************************************************************/ |
21 |
|
|
|
22 |
|
|
#define GX_SOURCE_CODE |
23 |
|
|
|
24 |
|
|
|
25 |
|
|
/* Include necessary system files. */ |
26 |
|
|
|
27 |
|
|
#include "gx_api.h" |
28 |
|
|
#include "gx_system.h" |
29 |
|
|
#include "gx_canvas.h" |
30 |
|
|
#include "gx_context.h" |
31 |
|
|
#include "gx_widget.h" |
32 |
|
|
#include "gx_utility.h" |
33 |
|
|
|
34 |
|
|
/**************************************************************************/ |
35 |
|
|
/* */ |
36 |
|
|
/* FUNCTION RELEASE */ |
37 |
|
|
/* */ |
38 |
|
|
/* _gx_widget_text_blend PORTABLE C */ |
39 |
|
|
/* 6.1 */ |
40 |
|
|
/* AUTHOR */ |
41 |
|
|
/* */ |
42 |
|
|
/* Kenneth Maxwell, Microsoft Corporation */ |
43 |
|
|
/* */ |
44 |
|
|
/* DESCRIPTION (deprecated) */ |
45 |
|
|
/* */ |
46 |
|
|
/* This function blends the specified text using current brush and */ |
47 |
|
|
/* text alignment. */ |
48 |
|
|
/* */ |
49 |
|
|
/* INPUT */ |
50 |
|
|
/* */ |
51 |
|
|
/* widget Widget control block */ |
52 |
|
|
/* tColor Text Color */ |
53 |
|
|
/* font_id Font Id */ |
54 |
|
|
/* string Drawing string */ |
55 |
|
|
/* x_offset Drawing position adjustment */ |
56 |
|
|
/* y_offset Drawing position adjustment */ |
57 |
|
|
/* alpha Blending value 0-255 */ |
58 |
|
|
/* */ |
59 |
|
|
/* OUTPUT */ |
60 |
|
|
/* */ |
61 |
|
|
/* status Completion status */ |
62 |
|
|
/* */ |
63 |
|
|
/* CALLS */ |
64 |
|
|
/* */ |
65 |
|
|
/* _gx_utility_string_length_check Validate string length */ |
66 |
|
|
/* _gx_widget_text_blend_ext New version of this function */ |
67 |
|
|
/* */ |
68 |
|
|
/* CALLED BY */ |
69 |
|
|
/* */ |
70 |
|
|
/* GUIX Internal Code */ |
71 |
|
|
/* */ |
72 |
|
|
/**************************************************************************/ |
73 |
|
|
#if defined(GX_ENABLE_DEPRECATED_STRING_API) |
74 |
|
73 |
UINT _gx_widget_text_blend(GX_WIDGET *widget, |
75 |
|
|
UINT tColor, UINT font_id, |
76 |
|
|
GX_CONST GX_CHAR *string, INT x_offset, INT y_offset, UCHAR alpha) |
77 |
|
|
{ |
78 |
|
|
UINT status; |
79 |
|
|
GX_STRING new_string; |
80 |
|
|
|
81 |
|
73 |
new_string.gx_string_ptr = string; |
82 |
|
|
|
83 |
|
|
/* Calcualte text length. */ |
84 |
|
73 |
status = _gx_utility_string_length_check(string, &new_string.gx_string_length, GX_MAX_STRING_LENGTH); |
85 |
✓✓ |
73 |
if (status != GX_SUCCESS) |
86 |
|
|
{ |
87 |
|
1 |
return status; |
88 |
|
|
} |
89 |
|
|
|
90 |
|
72 |
status = _gx_widget_text_blend_ext(widget, tColor, font_id, &new_string, x_offset, y_offset, alpha); |
91 |
|
|
|
92 |
|
72 |
return status; |
93 |
|
|
} |
94 |
|
|
#endif |
95 |
|
|
|
96 |
|
|
|
97 |
|
|
/**************************************************************************/ |
98 |
|
|
/* */ |
99 |
|
|
/* FUNCTION RELEASE */ |
100 |
|
|
/* */ |
101 |
|
|
/* _gx_widget_text_blend_ext PORTABLE C */ |
102 |
|
|
/* 6.1 */ |
103 |
|
|
/* AUTHOR */ |
104 |
|
|
/* */ |
105 |
|
|
/* Kenneth Maxwell, Microsoft Corporation */ |
106 |
|
|
/* */ |
107 |
|
|
/* DESCRIPTION */ |
108 |
|
|
/* */ |
109 |
|
|
/* This function blends the specified text using current brush and */ |
110 |
|
|
/* text alignment. */ |
111 |
|
|
/* */ |
112 |
|
|
/* INPUT */ |
113 |
|
|
/* */ |
114 |
|
|
/* widget Widget control block */ |
115 |
|
|
/* tColor Text Color */ |
116 |
|
|
/* font_id Font Id */ |
117 |
|
|
/* string Drawing string */ |
118 |
|
|
/* x_offset Drawing position adjustment */ |
119 |
|
|
/* y_offset Drawing position adjustment */ |
120 |
|
|
/* alpha Blending value 0-255 */ |
121 |
|
|
/* */ |
122 |
|
|
/* OUTPUT */ |
123 |
|
|
/* */ |
124 |
|
|
/* status Completion status */ |
125 |
|
|
/* */ |
126 |
|
|
/* CALLS */ |
127 |
|
|
/* */ |
128 |
|
|
/* _gx_context_line_color_set Set the line color */ |
129 |
|
|
/* _gx_context_font_set Set the font in the context */ |
130 |
|
|
/* _gx_context_brush_get Get the context brush */ |
131 |
|
|
/* _gx_widget_height_get Get widget height */ |
132 |
|
|
/* _gx_widget_width_get Get widget width */ |
133 |
|
|
/* _gx_widget_border_width_get Get widget border width */ |
134 |
|
|
/* _gx_system_string_width_get Get string width */ |
135 |
|
|
/* _gx_canvas_text_draw Draw text on the canvas */ |
136 |
|
|
/* */ |
137 |
|
|
/* CALLED BY */ |
138 |
|
|
/* */ |
139 |
|
|
/* GUIX Internal Code */ |
140 |
|
|
/* */ |
141 |
|
|
/**************************************************************************/ |
142 |
|
219 |
UINT _gx_widget_text_blend_ext(GX_WIDGET *widget, |
143 |
|
|
UINT tColor, UINT font_id, |
144 |
|
|
GX_CONST GX_STRING *string, INT x_offset, INT y_offset, UCHAR alpha) |
145 |
|
|
{ |
146 |
|
|
GX_VALUE text_width; |
147 |
|
|
GX_VALUE text_height; |
148 |
|
|
GX_VALUE widget_width; |
149 |
|
|
GX_VALUE widget_height; |
150 |
|
|
GX_VALUE x_pos; |
151 |
|
|
GX_VALUE y_pos; |
152 |
|
|
GX_VALUE border_width; |
153 |
|
|
|
154 |
|
|
GX_BRUSH *brush; |
155 |
|
|
|
156 |
|
|
/* Is there a string? */ |
157 |
✓✓✓✓
|
219 |
if (string && string -> gx_string_ptr) |
158 |
|
|
{ |
159 |
|
217 |
_gx_context_line_color_set(tColor); |
160 |
|
217 |
_gx_context_font_set(font_id); |
161 |
|
217 |
_gx_context_brush_get(&brush); |
162 |
|
|
|
163 |
✓✓ |
217 |
if (!brush -> gx_brush_font) |
164 |
|
|
{ |
165 |
|
1 |
return(GX_SUCCESS); |
166 |
|
|
} |
167 |
|
216 |
brush -> gx_brush_alpha = alpha; |
168 |
|
|
|
169 |
|
216 |
text_height = brush -> gx_brush_font -> gx_font_line_height; |
170 |
|
216 |
_gx_widget_height_get(widget, &widget_height); |
171 |
|
|
|
172 |
|
216 |
_gx_widget_border_width_get(widget, &border_width); |
173 |
|
|
|
174 |
|
216 |
x_pos = widget -> gx_widget_size.gx_rectangle_left; |
175 |
|
216 |
y_pos = widget -> gx_widget_size.gx_rectangle_top; |
176 |
|
216 |
y_pos = (GX_VALUE)(y_pos + (widget_height - text_height) / 2); |
177 |
|
|
|
178 |
✓✓✓ |
216 |
switch (widget -> gx_widget_style & GX_STYLE_TEXT_ALIGNMENT_MASK) |
179 |
|
|
{ |
180 |
|
71 |
case GX_STYLE_TEXT_RIGHT: |
181 |
|
71 |
_gx_system_string_width_get_ext(brush -> gx_brush_font, string, &text_width); |
182 |
|
71 |
_gx_widget_width_get(widget, &widget_width); |
183 |
|
71 |
x_pos = (GX_VALUE)(x_pos + widget_width - 1); |
184 |
|
71 |
x_pos = (GX_VALUE)(x_pos - text_width - border_width); |
185 |
|
71 |
break; |
186 |
|
|
|
187 |
|
72 |
case GX_STYLE_TEXT_LEFT: |
188 |
|
72 |
x_pos = (GX_VALUE)(x_pos + border_width); |
189 |
|
72 |
break; |
190 |
|
|
|
191 |
|
73 |
case GX_STYLE_TEXT_CENTER: |
192 |
|
|
default: |
193 |
|
73 |
_gx_system_string_width_get_ext(brush -> gx_brush_font, string, &text_width); |
194 |
|
73 |
_gx_widget_width_get(widget, &widget_width); |
195 |
|
73 |
x_pos = (GX_VALUE)(x_pos + ((widget_width - text_width) / 2)); |
196 |
|
73 |
break; |
197 |
|
|
} |
198 |
|
|
|
199 |
|
|
/* Draw the text. */ |
200 |
|
216 |
_gx_canvas_text_draw_ext((GX_VALUE)(x_pos + x_offset), (GX_VALUE)(y_pos + y_offset), string); |
201 |
|
|
} |
202 |
|
|
|
203 |
|
218 |
return(GX_SUCCESS); |
204 |
|
|
} |
205 |
|
|
|