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_icon_button_draw                                PORTABLE C      */
40 /*                                                           6.1.9        */
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                                Icon button control block     */
53 /*                                                                        */
54 /*  OUTPUT                                                                */
55 /*                                                                        */
56 /*    None                                                                */
57 /*                                                                        */
58 /*  CALLS                                                                 */
59 /*                                                                        */
60 /*    _gx_button_background_draw            Draw the button background    */
61 /*    _gx_context_pixelmap_get              Retrieve pixelmap image       */
62 /*    _gx_widget_border_width_get           Get the border width          */
63 /*    _gx_canvas_pixelmap_draw              Draw the pixelmap             */
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 /*                                            resulting in version 6.1    */
78 /*  10-15-2021     Ting Zhu                 Modified comment(s),          */
79 /*                                            fixed pixelmap draw offset, */
80 /*                                            resulting in version 6.1.9  */
81 /*                                                                        */
82 /**************************************************************************/
_gx_icon_button_draw(GX_ICON_BUTTON * button)83 VOID  _gx_icon_button_draw(GX_ICON_BUTTON *button)
84 {
85 GX_WIDGET   *widget;
86 GX_PIXELMAP *map;
87 GX_VALUE     xpos;
88 GX_VALUE     ypos;
89 GX_VALUE     border;
90 INT          shift = 0;
91 
92     /* Setup the widget.  */
93     widget =  (GX_WIDGET *)button;
94 
95     /* draw the background button */
96     _gx_button_background_draw((GX_BUTTON *)button);
97 
98     /* draw the button icon */
99     _gx_context_pixelmap_get(button -> gx_icon_button_icon_id, &map);
100 
101     if (map)
102     {
103         _gx_widget_border_width_get(widget, &border);
104 
105         if (widget -> gx_widget_style & GX_STYLE_BUTTON_PUSHED)
106         {
107             shift = 1;
108         }
109 
110         switch (widget -> gx_widget_style & GX_PIXELMAP_HALIGN_MASK)
111         {
112         case GX_STYLE_HALIGN_CENTER:
113             xpos = (GX_VALUE)(widget -> gx_widget_size.gx_rectangle_right -
114                               widget -> gx_widget_size.gx_rectangle_left -
115                               map -> gx_pixelmap_width + 1);
116 
117             xpos /= 2;
118             xpos = (GX_VALUE)(xpos + widget -> gx_widget_size.gx_rectangle_left + shift);
119             break;
120 
121         case GX_STYLE_HALIGN_RIGHT:
122             xpos = (GX_VALUE)(widget -> gx_widget_size.gx_rectangle_right - map -> gx_pixelmap_width - border + shift + 1);
123             break;
124 
125         default:
126             xpos = (GX_VALUE)(widget -> gx_widget_size.gx_rectangle_left + border + shift);
127             break;
128         }
129 
130         switch (widget -> gx_widget_style & GX_PIXELMAP_VALIGN_MASK)
131         {
132         case GX_STYLE_VALIGN_CENTER:
133             ypos = (GX_VALUE)(widget -> gx_widget_size.gx_rectangle_bottom -
134                               widget -> gx_widget_size.gx_rectangle_top -
135                               map -> gx_pixelmap_height + 1);
136 
137             ypos /= 2;
138             ypos = (GX_VALUE)(ypos + widget -> gx_widget_size.gx_rectangle_top + shift);
139             break;
140 
141         case GX_STYLE_VALIGN_BOTTOM:
142             ypos = (GX_VALUE)(widget -> gx_widget_size.gx_rectangle_bottom - map -> gx_pixelmap_height - border + shift + 1);
143             break;
144 
145         default:
146             ypos = (GX_VALUE)(widget -> gx_widget_size.gx_rectangle_top + border + shift);
147             break;
148         }
149         _gx_widget_context_fill_set(widget);
150         _gx_canvas_pixelmap_draw(xpos, ypos, map);
151     }
152 
153 
154     /* Draw button's children.  */
155     _gx_widget_children_draw(widget);
156 }
157 
158