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 /*  FUNCTION                                               RELEASE        */
37 /*                                                                        */
38 /*    _gx_radio_button_draw                               PORTABLE C      */
39 /*                                                           6.1          */
40 /*  AUTHOR                                                                */
41 /*                                                                        */
42 /*    Kenneth Maxwell, Microsoft Corporation                              */
43 /*                                                                        */
44 /*  DESCRIPTION                                                           */
45 /*                                                                        */
46 /*    This service draws a radio button widget.                           */
47 /*                                                                        */
48 /*  INPUT                                                                 */
49 /*                                                                        */
50 /*    button                                Pointer to radio button       */
51 /*                                            widget control block        */
52 /*                                                                        */
53 /*  OUTPUT                                                                */
54 /*                                                                        */
55 /*    None                                                                */
56 /*                                                                        */
57 /*  CALLS                                                                 */
58 /*                                                                        */
59 /*    _gx_context_pixelmap_get              Retrieve pixelmap image       */
60 /*    _gx_canvas_pixelmap_draw              Draw the pixelmap             */
61 /*    _gx_widget_text_id_draw               Draw the text based on ID     */
62 /*    _gx_widget_text_draw                  Draw the text string          */
63 /*    _gx_widget_children_draw              Draw children widgets         */
64 /*                                                                        */
65 /*  CALLED BY                                                             */
66 /*                                                                        */
67 /*    Application Code                                                    */
68 /*    GUIX Internal Code                                                  */
69 /*                                                                        */
70 /*  RELEASE HISTORY                                                       */
71 /*                                                                        */
72 /*    DATE              NAME                      DESCRIPTION             */
73 /*                                                                        */
74 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
75 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
76 /*                                            improved logic,             */
77 /*                                            resulting in version 6.1    */
78 /*                                                                        */
79 /**************************************************************************/
_gx_radio_button_draw(GX_RADIO_BUTTON * button)80 VOID  _gx_radio_button_draw(GX_RADIO_BUTTON *button)
81 {
82 
83 GX_VALUE       xoffset = 0;
84 GX_VALUE       yoffset = 0;
85 GX_RESOURCE_ID text_color;
86 GX_RESOURCE_ID fill_color;
87 GX_RESOURCE_ID pixelmap_id;
88 GX_PIXELMAP   *pixelmap = GX_NULL;
89 GX_STRING      string;
90 
91     if (button -> gx_widget_style & GX_STYLE_ENABLED)
92     {
93 
94         if (button -> gx_widget_style & GX_STYLE_BUTTON_PUSHED)
95         {
96             fill_color = button -> gx_widget_selected_fill_color;
97             text_color = button -> gx_text_button_selected_text_color;
98             pixelmap_id = button -> gx_radio_button_on_pixelmap_id;
99         }
100         else
101         {
102             fill_color = button -> gx_widget_normal_fill_color;
103             text_color = button -> gx_text_button_normal_text_color;
104             pixelmap_id = button -> gx_radio_button_off_pixelmap_id;
105         }
106     }
107     else
108     {
109         fill_color = button -> gx_widget_disabled_fill_color;
110         text_color = button -> gx_text_button_disabled_text_color;
111 
112         if (button -> gx_widget_style & GX_STYLE_BUTTON_PUSHED)
113         {
114             pixelmap_id = button -> gx_radio_button_on_disabled_pixelmap_id;
115         }
116         else
117         {
118             pixelmap_id = button -> gx_radio_button_off_disabled_pixelmap_id;
119         }
120     }
121 
122     if (!(button -> gx_widget_status & GX_STATUS_TRANSPARENT))
123     {
124         _gx_widget_border_draw((GX_WIDGET *)button, GX_COLOR_ID_DEFAULT_BORDER, fill_color, fill_color, GX_TRUE);
125     }
126 
127     if (pixelmap_id)
128     {
129         _gx_context_pixelmap_get(pixelmap_id, &pixelmap);
130     }
131     if (pixelmap)
132     {
133         _gx_widget_height_get((GX_WIDGET *)button, &yoffset);
134         yoffset = (GX_VALUE)((yoffset - pixelmap -> gx_pixelmap_height) / 2);
135 
136         switch (button -> gx_widget_style & GX_STYLE_TEXT_ALIGNMENT_MASK)
137         {
138         case GX_STYLE_TEXT_RIGHT:
139             _gx_widget_width_get((GX_WIDGET *)button, &xoffset);
140             xoffset = (GX_VALUE)(xoffset - pixelmap -> gx_pixelmap_width + 1);
141             /* draw the pixelmap on the right */
142             _gx_canvas_pixelmap_draw((GX_VALUE)(button -> gx_widget_size.gx_rectangle_right -
143                                                 pixelmap -> gx_pixelmap_width + 1),
144                                      (GX_VALUE)(button -> gx_widget_size.gx_rectangle_top + yoffset), pixelmap);
145 
146             /* draw the text to the left of the bitmap */
147             xoffset = (GX_VALUE)(-(pixelmap -> gx_pixelmap_width * 3 / 2));
148             break;
149 
150         case GX_STYLE_TEXT_CENTER:
151             /* draw the pixelmap and text centered         */
152             _gx_widget_width_get((GX_WIDGET *)button, &xoffset);
153             xoffset = (GX_VALUE)((xoffset - pixelmap -> gx_pixelmap_width) / 2);
154 
155             /* draw the pixelmap centered */
156             _gx_canvas_pixelmap_draw((GX_VALUE)(button -> gx_widget_size.gx_rectangle_left + xoffset),
157                                      (GX_VALUE)(button -> gx_widget_size.gx_rectangle_top + yoffset), pixelmap);
158             /* draw the text centered: */
159             xoffset = 0;
160             break;
161 
162         case GX_STYLE_TEXT_LEFT:
163         default:
164             /* draw the pixelmap on the left */
165             _gx_canvas_pixelmap_draw(button -> gx_widget_size.gx_rectangle_left,
166                                      (GX_VALUE)(button -> gx_widget_size.gx_rectangle_top + yoffset), pixelmap);
167 
168             /* draw the text to the right of the pixelmap */
169             xoffset = (GX_VALUE)(pixelmap -> gx_pixelmap_width * 3 / 2);
170             break;
171         }
172     }
173 
174 
175     _gx_text_button_text_get_ext((GX_TEXT_BUTTON *)button, &string);
176 
177     if (string.gx_string_ptr)
178     {
179         _gx_widget_text_draw_ext((GX_WIDGET *)button, text_color,
180                                  button -> gx_text_button_font_id,
181                                  &string, xoffset, 0);
182     }
183 
184     /* Draw button's children.  */
185     _gx_widget_children_draw((GX_WIDGET *)button);
186 }
187 
188