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