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 /** Text Button Management (Button) */
18 /** */
19 /**************************************************************************/
20
21 #define GX_SOURCE_CODE
22
23 /* Include necessary system files. */
24
25 #include "gx_api.h"
26 #include "gx_widget.h"
27 #include "gx_button.h"
28 #include "gx_canvas.h"
29 #include "gx_system.h"
30 #include "gx_context.h"
31 #include "gx_utility.h"
32
33 /**************************************************************************/
34 /* */
35 /* FUNCTION RELEASE */
36 /* */
37 /* _gx_multi_line_text_button_text_draw PORTABLE C */
38 /* 6.1 */
39 /* AUTHOR */
40 /* */
41 /* Kenneth Maxwell, Microsoft Corporation */
42 /* */
43 /* DESCRIPTION */
44 /* */
45 /* This function draws the text of a multi-line text button. */
46 /* */
47 /* INPUT */
48 /* */
49 /* button Button control block */
50 /* */
51 /* OUTPUT */
52 /* */
53 /* None */
54 /* */
55 /* CALLS */
56 /* */
57 /* _gx_widget_font_get Get the font */
58 /* _gx_widget_border_width_get Get border width */
59 /* _gx_context_font_set Set font */
60 /* _gx_context_line_color_set Set line color */
61 /* _gx_system_string_width_get Get the width of the string */
62 /* _gx_canvas_text_draw Draw text string */
63 /* */
64 /* CALLED BY */
65 /* */
66 /* System and Application Code */
67 /* */
68 /* RELEASE HISTORY */
69 /* */
70 /* DATE NAME DESCRIPTION */
71 /* */
72 /* 05-19-2020 Kenneth Maxwell Initial Version 6.0 */
73 /* 09-30-2020 Kenneth Maxwell Modified comment(s), */
74 /* removed dynamic bidi text */
75 /* processing logic, */
76 /* resulting in version 6.1 */
77 /* */
78 /**************************************************************************/
_gx_multi_line_text_button_text_draw(GX_MULTI_LINE_TEXT_BUTTON * button)79 VOID _gx_multi_line_text_button_text_draw(GX_MULTI_LINE_TEXT_BUTTON *button)
80 {
81 GX_WIDGET *widget;
82 INT xtextoffset = 0;
83 INT ytextoffset = 0;
84 INT xtextpos;
85 INT ytextpos;
86 INT text_height;
87 GX_VALUE text_width;
88 INT widget_height;
89 GX_VALUE widget_width;
90 INT line_index;
91 GX_FONT *font;
92 GX_RESOURCE_ID color;
93 GX_VALUE border_width;
94 GX_STRING *line;
95
96 /* Setup the button. */
97 widget = (GX_WIDGET *)button;
98
99 /* draw the text lines */
100
101 if (widget -> gx_widget_style & GX_STYLE_ENABLED)
102 {
103 if (widget -> gx_widget_style & GX_STYLE_BUTTON_PUSHED)
104 {
105 xtextoffset = ytextoffset = 1;
106 color = button -> gx_text_button_selected_text_color;
107 }
108 else
109 {
110 color = button -> gx_text_button_normal_text_color;
111 }
112 }
113 else
114 {
115 color = button -> gx_text_button_disabled_text_color;
116 }
117
118 _gx_context_font_get(button -> gx_text_button_font_id, &font);
119
120 if (font)
121 {
122 text_height = button -> gx_multi_line_text_button_line_count * font -> gx_font_line_height;
123 widget_height = button -> gx_widget_size.gx_rectangle_bottom - button -> gx_widget_size.gx_rectangle_top + 1;
124 ytextpos = (widget_height - text_height) / 2;
125 ytextpos += button -> gx_widget_size.gx_rectangle_top;
126
127 _gx_widget_border_width_get(widget, &border_width);
128 _gx_context_font_set(button -> gx_text_button_font_id);
129
130 _gx_context_line_color_set(color);
131
132 for (line_index = 0; line_index < button -> gx_multi_line_text_button_line_count; line_index++)
133 {
134 xtextpos = button -> gx_widget_size.gx_rectangle_left;
135 line = &button -> gx_multi_line_text_button_lines[line_index];
136
137 if (line -> gx_string_ptr != GX_NULL)
138 {
139 switch (widget -> gx_widget_style & GX_STYLE_TEXT_ALIGNMENT_MASK)
140 {
141 case GX_STYLE_TEXT_RIGHT:
142 _gx_system_string_width_get_ext(font, line, &text_width);
143 _gx_widget_width_get(widget, &widget_width);
144 xtextpos += widget_width - 1;
145 xtextpos -= text_width + border_width;
146 break;
147
148 case GX_STYLE_TEXT_LEFT:
149 xtextpos += border_width;
150 break;
151
152 case GX_STYLE_TEXT_CENTER:
153 default:
154 _gx_system_string_width_get_ext(font, line, &text_width);
155 _gx_widget_width_get(widget, &widget_width);
156 xtextpos += ((widget_width - text_width) / 2);
157 break;
158 }
159
160 /* Draw the text. */
161 _gx_canvas_text_draw_ext((GX_VALUE)(xtextpos + xtextoffset), (GX_VALUE)(ytextpos + ytextoffset), line);
162 }
163 ytextpos += font -> gx_font_line_height;
164 }
165 }
166 }
167
168