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 |
|
|
/**************************************************************************/ |
79 |
|
1219 |
VOID _gx_multi_line_text_button_text_draw(GX_MULTI_LINE_TEXT_BUTTON *button) |
80 |
|
|
{ |
81 |
|
|
GX_WIDGET *widget; |
82 |
|
1219 |
INT xtextoffset = 0; |
83 |
|
1219 |
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 |
|
1219 |
widget = (GX_WIDGET *)button; |
98 |
|
|
|
99 |
|
|
/* draw the text lines */ |
100 |
|
|
|
101 |
✓✓ |
1219 |
if (widget -> gx_widget_style & GX_STYLE_ENABLED) |
102 |
|
|
{ |
103 |
✓✓ |
1195 |
if (widget -> gx_widget_style & GX_STYLE_BUTTON_PUSHED) |
104 |
|
|
{ |
105 |
|
20 |
xtextoffset = ytextoffset = 1; |
106 |
|
20 |
color = button -> gx_text_button_selected_text_color; |
107 |
|
|
} |
108 |
|
|
else |
109 |
|
|
{ |
110 |
|
1175 |
color = button -> gx_text_button_normal_text_color; |
111 |
|
|
} |
112 |
|
|
} |
113 |
|
|
else |
114 |
|
|
{ |
115 |
|
24 |
color = button -> gx_text_button_disabled_text_color; |
116 |
|
|
} |
117 |
|
|
|
118 |
|
1219 |
_gx_context_font_get(button -> gx_text_button_font_id, &font); |
119 |
|
|
|
120 |
✓✓ |
1219 |
if (font) |
121 |
|
|
{ |
122 |
|
1218 |
text_height = button -> gx_multi_line_text_button_line_count * font -> gx_font_line_height; |
123 |
|
1218 |
widget_height = button -> gx_widget_size.gx_rectangle_bottom - button -> gx_widget_size.gx_rectangle_top + 1; |
124 |
|
1218 |
ytextpos = (widget_height - text_height) / 2; |
125 |
|
1218 |
ytextpos += button -> gx_widget_size.gx_rectangle_top; |
126 |
|
|
|
127 |
|
1218 |
_gx_widget_border_width_get(widget, &border_width); |
128 |
|
1218 |
_gx_context_font_set(button -> gx_text_button_font_id); |
129 |
|
|
|
130 |
|
1218 |
_gx_context_line_color_set(color); |
131 |
|
|
|
132 |
✓✓ |
4887 |
for (line_index = 0; line_index < button -> gx_multi_line_text_button_line_count; line_index++) |
133 |
|
|
{ |
134 |
|
3669 |
xtextpos = button -> gx_widget_size.gx_rectangle_left; |
135 |
|
3669 |
line = &button -> gx_multi_line_text_button_lines[line_index]; |
136 |
|
|
|
137 |
✓✓ |
3669 |
if (line -> gx_string_ptr != GX_NULL) |
138 |
|
|
{ |
139 |
✓✓✓ |
3668 |
switch (widget -> gx_widget_style & GX_STYLE_TEXT_ALIGNMENT_MASK) |
140 |
|
|
{ |
141 |
|
20 |
case GX_STYLE_TEXT_RIGHT: |
142 |
|
20 |
_gx_system_string_width_get_ext(font, line, &text_width); |
143 |
|
20 |
_gx_widget_width_get(widget, &widget_width); |
144 |
|
20 |
xtextpos += widget_width - 1; |
145 |
|
20 |
xtextpos -= text_width + border_width; |
146 |
|
20 |
break; |
147 |
|
|
|
148 |
|
111 |
case GX_STYLE_TEXT_LEFT: |
149 |
|
111 |
xtextpos += border_width; |
150 |
|
111 |
break; |
151 |
|
|
|
152 |
|
3537 |
case GX_STYLE_TEXT_CENTER: |
153 |
|
|
default: |
154 |
|
3537 |
_gx_system_string_width_get_ext(font, line, &text_width); |
155 |
|
3537 |
_gx_widget_width_get(widget, &widget_width); |
156 |
|
3537 |
xtextpos += ((widget_width - text_width) / 2); |
157 |
|
3537 |
break; |
158 |
|
|
} |
159 |
|
|
|
160 |
|
|
/* Draw the text. */ |
161 |
|
3668 |
_gx_canvas_text_draw_ext((GX_VALUE)(xtextpos + xtextoffset), (GX_VALUE)(ytextpos + ytextoffset), line); |
162 |
|
|
} |
163 |
|
3669 |
ytextpos += font -> gx_font_line_height; |
164 |
|
|
} |
165 |
|
|
} |
166 |
|
1219 |
} |
167 |
|
|
|