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_pixelmap_button_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                                Button control block          */
53 /*                                                                        */
54 /*  OUTPUT                                                                */
55 /*                                                                        */
56 /*    None                                                                */
57 /*                                                                        */
58 /*  CALLS                                                                 */
59 /*                                                                        */
60 /*    _gx_context_pixelmap_get              Retrieve pixelmap image       */
61 /*    _gx_canvas_pixelmap_draw              Draw the pixelmap             */
62 /*    _gx_button_draw                       Draw the button               */
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 /*                                            resulting in version 6.1    */
77 /*                                                                        */
78 /**************************************************************************/
_gx_pixelmap_button_draw(GX_PIXELMAP_BUTTON * button)79 VOID  _gx_pixelmap_button_draw(GX_PIXELMAP_BUTTON *button)
80 {
81 GX_RESOURCE_ID pixelmap;
82 GX_PIXELMAP   *map;
83 GX_WIDGET     *widget = (GX_WIDGET *)button;
84 INT            xpos;
85 INT            ypos;
86 
87 
88     /* default to using the normal pixlemap */
89     pixelmap = button -> gx_pixelmap_button_normal_id;
90 
91     /* If the button is not enabled and the user provided
92        a disabled pixelmap, use that */
93     if (button -> gx_pixelmap_button_disabled_id &&
94         !(button -> gx_widget_style & GX_STYLE_ENABLED))
95     {
96         pixelmap = button -> gx_pixelmap_button_disabled_id;
97     }
98     else
99     {
100         /* otherwise, if the button is pushed used the selected pixelmap */
101         if (button -> gx_widget_style & GX_STYLE_BUTTON_PUSHED)
102         {
103             if (button -> gx_pixelmap_button_selected_id)
104             {
105                 pixelmap = button -> gx_pixelmap_button_selected_id;
106             }
107         }
108     }
109 
110     if (!(button -> gx_widget_style & GX_STYLE_ENABLED))
111     {
112         if (button -> gx_pixelmap_button_disabled_id)
113         {
114             pixelmap = button -> gx_pixelmap_button_disabled_id;
115         }
116     }
117 
118     _gx_context_pixelmap_get(pixelmap, &map);
119 
120     if (map)
121     {
122         switch (button -> gx_widget_style & GX_PIXELMAP_HALIGN_MASK)
123         {
124         case GX_STYLE_HALIGN_CENTER:
125             xpos = button -> gx_widget_size.gx_rectangle_right -
126                 button -> gx_widget_size.gx_rectangle_left -
127                 map -> gx_pixelmap_width + 1;
128 
129             xpos /= 2;
130             xpos += button -> gx_widget_size.gx_rectangle_left;
131             break;
132 
133         case GX_STYLE_HALIGN_RIGHT:
134             xpos = button -> gx_widget_size.gx_rectangle_right - map -> gx_pixelmap_width + 1;
135             break;
136 
137         default:
138             xpos = button -> gx_widget_size.gx_rectangle_left;
139             break;
140         }
141 
142         switch (button -> gx_widget_style & GX_PIXELMAP_VALIGN_MASK)
143         {
144         case GX_STYLE_VALIGN_CENTER:
145             ypos = button -> gx_widget_size.gx_rectangle_bottom -
146                 button -> gx_widget_size.gx_rectangle_top -
147                 map -> gx_pixelmap_height + 1;
148 
149             ypos /= 2;
150             ypos += button -> gx_widget_size.gx_rectangle_top;
151             break;
152 
153         case GX_STYLE_VALIGN_BOTTOM:
154             ypos = button -> gx_widget_size.gx_rectangle_bottom - map -> gx_pixelmap_height + 1;
155             break;
156 
157         default:
158             ypos = button -> gx_widget_size.gx_rectangle_top;
159             break;
160         }
161         _gx_widget_context_fill_set(widget);
162         _gx_canvas_pixelmap_draw((GX_VALUE)xpos, (GX_VALUE)ypos, map);
163     }
164     else
165     {
166         /* If I don't have a pixelmap and not transparent,
167            draw something
168          */
169         if (!(widget -> gx_widget_style & GX_STYLE_TRANSPARENT))
170         {
171             _gx_button_draw((GX_BUTTON *)button);
172         }
173     }
174 
175     /* Draw button's children.  */
176     _gx_widget_children_draw(widget);
177 }
178 
179