1 /**************************************************************************/
2 /* */
3 /* Copyright (c) Microsoft Corporation. All rights reserved. */
4 /* */
5 /* This software is licensed under the Microsoft Software License */
6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */
7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
8 /* and in the root directory of this software. */
9 /* */
10 /**************************************************************************/
11
12
13 /**************************************************************************/
14 /**************************************************************************/
15 /** */
16 /** GUIX Component */
17 /** */
18 /** Button Management (Button) */
19 /** */
20 /**************************************************************************/
21
22 #define GX_SOURCE_CODE
23
24
25 /* Include necessary system files. */
26
27 #include "gx_api.h"
28 #include "gx_system.h"
29 #include "gx_canvas.h"
30 #include "gx_context.h"
31 #include "gx_widget.h"
32 #include "gx_button.h"
33
34
35 /**************************************************************************/
36 /* */
37 /* FUNCTION RELEASE */
38 /* */
39 /* _gx_checkbox_draw PORTABLE C */
40 /* 6.1 */
41 /* AUTHOR */
42 /* */
43 /* Kenneth Maxwell, Microsoft Corporation */
44 /* */
45 /* DESCRIPTION */
46 /* */
47 /* This function draws the specified button, which is a special type */
48 /* of widget. */
49 /* */
50 /* INPUT */
51 /* */
52 /* button Checkbox control block */
53 /* */
54 /* OUTPUT */
55 /* */
56 /* None */
57 /* */
58 /* CALLS */
59 /* */
60 /* _gx_context_pixelmap_get Retrieve pixelmap image */
61 /* _gx_widget_height_get Gets the height of the widget */
62 /* _gx_canvas_pixelmap_draw Draw the pixelmap image */
63 /* _gx_widget_text_id_draw Draw the text based on ID */
64 /* _gx_widget_text_draw Draw the text string */
65 /* _gx_widget_children_draw Draw children widgets */
66 /* */
67 /* CALLED BY */
68 /* */
69 /* Application Code */
70 /* GUIX Internal Code */
71 /* */
72 /* RELEASE HISTORY */
73 /* */
74 /* DATE NAME DESCRIPTION */
75 /* */
76 /* 05-19-2020 Kenneth Maxwell Initial Version 6.0 */
77 /* 09-30-2020 Kenneth Maxwell Modified comment(s), */
78 /* improved logic, */
79 /* resulting in version 6.1 */
80 /* */
81 /**************************************************************************/
_gx_checkbox_draw(GX_CHECKBOX * checkbox)82 VOID _gx_checkbox_draw(GX_CHECKBOX *checkbox)
83 {
84 GX_WIDGET *widget = (GX_WIDGET *)checkbox;
85 GX_VALUE xoffset = 0;
86 GX_VALUE yoffset = 0;
87 GX_RESOURCE_ID fill_color;
88 GX_RESOURCE_ID text_color;
89 GX_RESOURCE_ID pixelmap_id;
90 GX_PIXELMAP *pixelmap = GX_NULL;
91 GX_STRING string;
92
93 if (widget -> gx_widget_style & GX_STYLE_ENABLED)
94 {
95 if (widget -> gx_widget_style & GX_STYLE_BUTTON_PUSHED)
96 {
97 fill_color = widget -> gx_widget_selected_fill_color;
98 text_color = checkbox -> gx_text_button_selected_text_color;
99 pixelmap_id = checkbox -> gx_checkbox_checked_pixelmap_id;
100 }
101 else
102 {
103 fill_color = widget -> gx_widget_normal_fill_color;
104 text_color = checkbox -> gx_text_button_normal_text_color;
105 pixelmap_id = checkbox -> gx_checkbox_unchecked_pixelmap_id;
106 }
107 }
108 else
109 {
110 fill_color = checkbox -> gx_widget_disabled_fill_color;
111 text_color = checkbox -> gx_text_button_disabled_text_color;
112 if (widget -> gx_widget_style & GX_STYLE_BUTTON_PUSHED)
113 {
114 pixelmap_id = checkbox -> gx_checkbox_checked_disabled_pixelmap_id;
115 }
116 else
117 {
118 pixelmap_id = checkbox -> gx_checkbox_unchecked_disabled_pixelmap_id;
119 }
120 }
121
122 /* If I am not transparent, draw my border and background */
123
124 if (!(widget -> gx_widget_status & GX_STATUS_TRANSPARENT))
125 {
126 _gx_widget_border_draw(widget, GX_COLOR_ID_DEFAULT_BORDER, fill_color, fill_color, GX_TRUE);
127 }
128
129 /* draw the pixelmap */
130
131 if (pixelmap_id)
132 {
133 _gx_context_pixelmap_get(pixelmap_id, &pixelmap);
134 }
135
136 if (pixelmap)
137 {
138 _gx_widget_height_get((GX_WIDGET *)checkbox, &yoffset);
139 yoffset = (GX_VALUE)((yoffset - pixelmap -> gx_pixelmap_height) / 2);
140
141 switch (checkbox -> gx_widget_style & GX_STYLE_TEXT_ALIGNMENT_MASK)
142 {
143 case GX_STYLE_TEXT_RIGHT:
144 _gx_widget_width_get((GX_WIDGET *)checkbox, &xoffset);
145 xoffset = (GX_VALUE)(xoffset - pixelmap -> gx_pixelmap_width + 1);
146 /* draw the pixelmap on the right */
147 _gx_canvas_pixelmap_draw((GX_VALUE)(checkbox -> gx_widget_size.gx_rectangle_right -
148 pixelmap -> gx_pixelmap_width + 1),
149 (GX_VALUE)(checkbox -> gx_widget_size.gx_rectangle_top + yoffset), pixelmap);
150
151 /* draw the text to the left of the bitmap */
152 xoffset = (GX_VALUE)(-(pixelmap -> gx_pixelmap_width * 3 / 2));
153 break;
154
155 case GX_STYLE_TEXT_CENTER:
156 /* draw the pixelmap and text centered */
157 _gx_widget_width_get((GX_WIDGET *)checkbox, &xoffset);
158 xoffset = (GX_VALUE)((xoffset - pixelmap -> gx_pixelmap_width) / 2);
159
160 /* draw the pixelmap centered */
161 _gx_canvas_pixelmap_draw((GX_VALUE)(checkbox -> gx_widget_size.gx_rectangle_left + xoffset),
162 (GX_VALUE)(checkbox -> gx_widget_size.gx_rectangle_top + yoffset), pixelmap);
163 /* draw the text centered: */
164 xoffset = 0;
165 break;
166
167 case GX_STYLE_TEXT_LEFT:
168 /* draw the pixelmap on the left */
169 _gx_canvas_pixelmap_draw(checkbox -> gx_widget_size.gx_rectangle_left,
170 (GX_VALUE)(checkbox -> gx_widget_size.gx_rectangle_top + yoffset), pixelmap);
171
172 /* draw the text to the right of the pixelmap */
173 xoffset = (GX_VALUE)(pixelmap -> gx_pixelmap_width * 3 / 2);
174 break;
175 }
176 }
177
178 _gx_text_button_text_get_ext((GX_TEXT_BUTTON *)checkbox, &string);
179
180 if (string.gx_string_ptr)
181 {
182 _gx_widget_text_draw_ext(widget, text_color,
183 checkbox -> gx_text_button_font_id,
184 &string, xoffset, 0);
185 }
186
187 /* Draw checkbox's children. */
188 _gx_widget_children_draw(widget);
189 }
190
191