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 /** Button Management (Button) */
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_button.h"
32
33
34 /**************************************************************************/
35 /* */
36 /* FUNCTION RELEASE */
37 /* */
38 /* _gx_checkbox_draw PORTABLE C */
39 /* 6.1 */
40 /* AUTHOR */
41 /* */
42 /* Kenneth Maxwell, Microsoft Corporation */
43 /* */
44 /* DESCRIPTION */
45 /* */
46 /* This function draws the specified button, which is a special type */
47 /* of widget. */
48 /* */
49 /* INPUT */
50 /* */
51 /* button Checkbox control block */
52 /* */
53 /* OUTPUT */
54 /* */
55 /* None */
56 /* */
57 /* CALLS */
58 /* */
59 /* _gx_context_pixelmap_get Retrieve pixelmap image */
60 /* _gx_widget_height_get Gets the height of the widget */
61 /* _gx_canvas_pixelmap_draw Draw the pixelmap image */
62 /* _gx_widget_text_id_draw Draw the text based on ID */
63 /* _gx_widget_text_draw Draw the text string */
64 /* _gx_widget_children_draw Draw children widgets */
65 /* */
66 /* CALLED BY */
67 /* */
68 /* Application Code */
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 /* improved logic, */
78 /* resulting in version 6.1 */
79 /* */
80 /**************************************************************************/
_gx_checkbox_draw(GX_CHECKBOX * checkbox)81 VOID _gx_checkbox_draw(GX_CHECKBOX *checkbox)
82 {
83 GX_WIDGET *widget = (GX_WIDGET *)checkbox;
84 GX_VALUE xoffset = 0;
85 GX_VALUE yoffset = 0;
86 GX_RESOURCE_ID fill_color;
87 GX_RESOURCE_ID text_color;
88 GX_RESOURCE_ID pixelmap_id;
89 GX_PIXELMAP *pixelmap = GX_NULL;
90 GX_STRING string;
91
92 if (widget -> gx_widget_style & GX_STYLE_ENABLED)
93 {
94 if (widget -> gx_widget_style & GX_STYLE_BUTTON_PUSHED)
95 {
96 fill_color = widget -> gx_widget_selected_fill_color;
97 text_color = checkbox -> gx_text_button_selected_text_color;
98 pixelmap_id = checkbox -> gx_checkbox_checked_pixelmap_id;
99 }
100 else
101 {
102 fill_color = widget -> gx_widget_normal_fill_color;
103 text_color = checkbox -> gx_text_button_normal_text_color;
104 pixelmap_id = checkbox -> gx_checkbox_unchecked_pixelmap_id;
105 }
106 }
107 else
108 {
109 fill_color = checkbox -> gx_widget_disabled_fill_color;
110 text_color = checkbox -> gx_text_button_disabled_text_color;
111 if (widget -> gx_widget_style & GX_STYLE_BUTTON_PUSHED)
112 {
113 pixelmap_id = checkbox -> gx_checkbox_checked_disabled_pixelmap_id;
114 }
115 else
116 {
117 pixelmap_id = checkbox -> gx_checkbox_unchecked_disabled_pixelmap_id;
118 }
119 }
120
121 /* If I am not transparent, draw my border and background */
122
123 if (!(widget -> gx_widget_status & GX_STATUS_TRANSPARENT))
124 {
125 _gx_widget_border_draw(widget, GX_COLOR_ID_DEFAULT_BORDER, fill_color, fill_color, GX_TRUE);
126 }
127
128 /* draw the pixelmap */
129
130 if (pixelmap_id)
131 {
132 _gx_context_pixelmap_get(pixelmap_id, &pixelmap);
133 }
134
135 if (pixelmap)
136 {
137 _gx_widget_height_get((GX_WIDGET *)checkbox, &yoffset);
138 yoffset = (GX_VALUE)((yoffset - pixelmap -> gx_pixelmap_height) / 2);
139
140 switch (checkbox -> gx_widget_style & GX_STYLE_TEXT_ALIGNMENT_MASK)
141 {
142 case GX_STYLE_TEXT_RIGHT:
143 _gx_widget_width_get((GX_WIDGET *)checkbox, &xoffset);
144 xoffset = (GX_VALUE)(xoffset - pixelmap -> gx_pixelmap_width + 1);
145 /* draw the pixelmap on the right */
146 _gx_canvas_pixelmap_draw((GX_VALUE)(checkbox -> gx_widget_size.gx_rectangle_right -
147 pixelmap -> gx_pixelmap_width + 1),
148 (GX_VALUE)(checkbox -> gx_widget_size.gx_rectangle_top + yoffset), pixelmap);
149
150 /* draw the text to the left of the bitmap */
151 xoffset = (GX_VALUE)(-(pixelmap -> gx_pixelmap_width * 3 / 2));
152 break;
153
154 case GX_STYLE_TEXT_CENTER:
155 /* draw the pixelmap and text centered */
156 _gx_widget_width_get((GX_WIDGET *)checkbox, &xoffset);
157 xoffset = (GX_VALUE)((xoffset - pixelmap -> gx_pixelmap_width) / 2);
158
159 /* draw the pixelmap centered */
160 _gx_canvas_pixelmap_draw((GX_VALUE)(checkbox -> gx_widget_size.gx_rectangle_left + xoffset),
161 (GX_VALUE)(checkbox -> gx_widget_size.gx_rectangle_top + yoffset), pixelmap);
162 /* draw the text centered: */
163 xoffset = 0;
164 break;
165
166 case GX_STYLE_TEXT_LEFT:
167 /* draw the pixelmap on the left */
168 _gx_canvas_pixelmap_draw(checkbox -> gx_widget_size.gx_rectangle_left,
169 (GX_VALUE)(checkbox -> gx_widget_size.gx_rectangle_top + yoffset), pixelmap);
170
171 /* draw the text to the right of the pixelmap */
172 xoffset = (GX_VALUE)(pixelmap -> gx_pixelmap_width * 3 / 2);
173 break;
174 }
175 }
176
177 _gx_text_button_text_get_ext((GX_TEXT_BUTTON *)checkbox, &string);
178
179 if (string.gx_string_ptr)
180 {
181 _gx_widget_text_draw_ext(widget, text_color,
182 checkbox -> gx_text_button_font_id,
183 &string, xoffset, 0);
184 }
185
186 /* Draw checkbox's children. */
187 _gx_widget_children_draw(widget);
188 }
189
190