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_draw PORTABLE C */ |
39 |
|
|
/* 6.1 */ |
40 |
|
|
/* AUTHOR */ |
41 |
|
|
/* */ |
42 |
|
|
/* Kenneth Maxwell, Microsoft Corporation */ |
43 |
|
|
/* */ |
44 |
|
|
/* DESCRIPTION (Deprecated) */ |
45 |
|
|
/* */ |
46 |
|
|
/* This function draws 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 |
|
|
/* */ |
58 |
|
|
/* OUTPUT */ |
59 |
|
|
/* */ |
60 |
|
|
/* None */ |
61 |
|
|
/* */ |
62 |
|
|
/* CALLS */ |
63 |
|
|
/* */ |
64 |
|
|
/* _gx_utility_string_length_check Validate string length */ |
65 |
|
|
/* _gx_widget_text_draw_ext */ |
66 |
|
|
/* */ |
67 |
|
|
/* CALLED BY */ |
68 |
|
|
/* */ |
69 |
|
|
/* GUIX Internal Code */ |
70 |
|
|
/* */ |
71 |
|
|
/**************************************************************************/ |
72 |
|
|
#if defined(GX_ENABLE_DEPRECATED_STRING_API) |
73 |
|
2 |
VOID _gx_widget_text_draw(GX_WIDGET *widget, |
74 |
|
|
UINT tColor, UINT font_id, |
75 |
|
|
GX_CONST GX_CHAR *text, INT x_offset, INT y_offset) |
76 |
|
|
{ |
77 |
|
|
UINT status; |
78 |
|
2 |
UINT length = 0; |
79 |
|
|
GX_STRING string; |
80 |
|
|
|
81 |
|
2 |
string.gx_string_ptr = text; |
82 |
|
2 |
status = _gx_utility_string_length_check(text, &length, GX_MAX_STRING_LENGTH); |
83 |
✓✓ |
2 |
if (status == GX_SUCCESS) |
84 |
|
|
{ |
85 |
|
1 |
string.gx_string_length = length; |
86 |
|
1 |
_gx_widget_text_draw_ext(widget, tColor, font_id, &string, x_offset, y_offset); |
87 |
|
|
} |
88 |
|
2 |
} |
89 |
|
|
#endif |
90 |
|
|
|
91 |
|
|
/**************************************************************************/ |
92 |
|
|
/* */ |
93 |
|
|
/* FUNCTION RELEASE */ |
94 |
|
|
/* */ |
95 |
|
|
/* _gx_widget_text_draw_ext PORTABLE C */ |
96 |
|
|
/* 6.1 */ |
97 |
|
|
/* AUTHOR */ |
98 |
|
|
/* */ |
99 |
|
|
/* Kenneth Maxwell, Microsoft Corporation */ |
100 |
|
|
/* */ |
101 |
|
|
/* DESCRIPTION */ |
102 |
|
|
/* */ |
103 |
|
|
/* This function draws the specified text using current brush and */ |
104 |
|
|
/* text alignment. */ |
105 |
|
|
/* */ |
106 |
|
|
/* INPUT */ |
107 |
|
|
/* */ |
108 |
|
|
/* widget Widget control block */ |
109 |
|
|
/* tColor Text Color */ |
110 |
|
|
/* font_id Font Id */ |
111 |
|
|
/* string Drawing string */ |
112 |
|
|
/* x_offset Drawing position adjustment */ |
113 |
|
|
/* y_offset Drawing position adjustment */ |
114 |
|
|
/* */ |
115 |
|
|
/* OUTPUT */ |
116 |
|
|
/* */ |
117 |
|
|
/* None */ |
118 |
|
|
/* */ |
119 |
|
|
/* CALLS */ |
120 |
|
|
/* */ |
121 |
|
|
/* _gx_context_line_color_set Set the line color */ |
122 |
|
|
/* _gx_context_font_set Set the font in the context */ |
123 |
|
|
/* _gx_context_brush_get Get the context brush */ |
124 |
|
|
/* _gx_widget_height_get Get widget height */ |
125 |
|
|
/* _gx_widget_width_get Get widget width */ |
126 |
|
|
/* _gx_system_string_width_get Get string width */ |
127 |
|
|
/* _gx_canvas_text_draw Draw text on the canvas */ |
128 |
|
|
/* _gx_utility_string_length_check Test string length */ |
129 |
|
|
/* */ |
130 |
|
|
/* CALLED BY */ |
131 |
|
|
/* */ |
132 |
|
|
/* GUIX Internal Code */ |
133 |
|
|
/* */ |
134 |
|
|
/**************************************************************************/ |
135 |
|
|
|
136 |
|
829823 |
VOID _gx_widget_text_draw_ext(GX_WIDGET *widget, |
137 |
|
|
UINT tColor, UINT font_id, |
138 |
|
|
GX_CONST GX_STRING *string, INT x_offset, INT y_offset) |
139 |
|
|
{ |
140 |
|
|
|
141 |
|
|
GX_VALUE text_width; |
142 |
|
|
GX_VALUE text_height; |
143 |
|
|
GX_VALUE widget_width; |
144 |
|
|
GX_VALUE widget_height; |
145 |
|
|
GX_VALUE x_pos; |
146 |
|
|
GX_VALUE y_pos; |
147 |
|
|
GX_VALUE border_width; |
148 |
|
|
|
149 |
|
|
GX_BRUSH *brush; |
150 |
|
|
|
151 |
|
|
/* Is there a string? */ |
152 |
✓✓ |
829823 |
if (string) |
153 |
|
|
{ |
154 |
|
829822 |
_gx_context_line_color_set(tColor); |
155 |
|
829822 |
_gx_context_font_set(font_id); |
156 |
|
829822 |
_gx_context_brush_get(&brush); |
157 |
|
|
|
158 |
✓✓ |
829822 |
if (!brush -> gx_brush_font) |
159 |
|
|
{ |
160 |
|
42 |
return; |
161 |
|
|
} |
162 |
|
|
|
163 |
|
829780 |
text_height = brush -> gx_brush_font -> gx_font_line_height; |
164 |
|
829780 |
_gx_widget_height_get(widget, &widget_height); |
165 |
|
|
|
166 |
|
829780 |
_gx_widget_border_width_get(widget, &border_width); |
167 |
|
|
|
168 |
|
829780 |
x_pos = widget -> gx_widget_size.gx_rectangle_left; |
169 |
|
829780 |
y_pos = widget -> gx_widget_size.gx_rectangle_top; |
170 |
|
829780 |
y_pos = (GX_VALUE)(y_pos + (widget_height - text_height) / 2); |
171 |
|
|
|
172 |
✓✓✓ |
829780 |
switch (widget -> gx_widget_style & GX_STYLE_TEXT_ALIGNMENT_MASK) |
173 |
|
|
{ |
174 |
|
52125 |
case GX_STYLE_TEXT_RIGHT: |
175 |
|
52125 |
_gx_system_string_width_get_ext(brush -> gx_brush_font, string, &text_width); |
176 |
|
52125 |
_gx_widget_width_get(widget, &widget_width); |
177 |
|
52125 |
x_pos = (GX_VALUE)(x_pos + widget_width - 1); |
178 |
|
52125 |
x_pos = (GX_VALUE)(x_pos - text_width - border_width); |
179 |
|
52125 |
break; |
180 |
|
|
|
181 |
|
414709 |
case GX_STYLE_TEXT_LEFT: |
182 |
|
414709 |
x_pos = (GX_VALUE)(x_pos + border_width); |
183 |
|
414709 |
break; |
184 |
|
|
|
185 |
|
362946 |
case GX_STYLE_TEXT_CENTER: |
186 |
|
|
default: |
187 |
|
362946 |
_gx_system_string_width_get_ext(brush -> gx_brush_font, string, &text_width); |
188 |
|
362946 |
_gx_widget_width_get(widget, &widget_width); |
189 |
|
362946 |
x_pos = (GX_VALUE)(x_pos + ((widget_width - text_width) / 2)); |
190 |
|
362946 |
break; |
191 |
|
|
} |
192 |
|
|
|
193 |
|
|
/* Draw the text. */ |
194 |
|
829780 |
_gx_canvas_text_draw_ext((GX_VALUE)(x_pos + x_offset), (GX_VALUE)(y_pos + y_offset), string); |
195 |
|
|
} |
196 |
|
|
} |
197 |
|
|
|