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