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 /**   Scroll Management (Scroll)                                          */
19 /**                                                                       */
20 /**************************************************************************/
21 
22 #define GX_SOURCE_CODE
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_icon.h"
32 #include "gx_scrollbar.h"
33 #include "gx_utility.h"
34 
35 /**************************************************************************/
36 /*                                                                        */
37 /*  FUNCTION                                               RELEASE        */
38 /*                                                                        */
39 /*    _gx_scrollbar_draw                                  PORTABLE C      */
40 /*                                                           6.1          */
41 /*  AUTHOR                                                                */
42 /*                                                                        */
43 /*    Kenneth Maxwell, Microsoft Corporation                              */
44 /*                                                                        */
45 /*  DESCRIPTION                                                           */
46 /*                                                                        */
47 /*    This function draws the specified scroll bar, which is a            */
48 /*      special type of widget.                                           */
49 /*                                                                        */
50 /*  INPUT                                                                 */
51 /*                                                                        */
52 /*    scrollbar                             Scrollbar widget to draw      */
53 /*                                                                        */
54 /*  OUTPUT                                                                */
55 /*                                                                        */
56 /*    None                                                                */
57 /*                                                                        */
58 /*  CALLS                                                                 */
59 /*                                                                        */
60 /*    _gx_context_brush_define              Define the brush for the      */
61 /*                                            context                     */
62 /*    _gx_context_brush_width_set           Set the width of the brush    */
63 /*    _gx_canvas_rectangle_draw             Draw rectangle                */
64 /*    _gx_context_pixelmap_get              Retrieve pixelmap image       */
65 /*    _gx_canvas_pixelmap_tile              Tile the canvas area with     */
66 /*                                            pixelmap                    */
67 /*    _gx_canvas_pixelmap_draw              Draw pixelmap                 */
68 /*    _gx_widget_width_get                  Retrieve the width of the     */
69 /*                                            widget                      */
70 /*    _gx_widget_height_get                 Retrieve the height of the    */
71 /*                                            widget                      */
72 /*    _gx_widget_children_draw              Draw children widgets         */
73 /*                                                                        */
74 /*  CALLED BY                                                             */
75 /*                                                                        */
76 /*    Application Code                                                    */
77 /*    GUIX Internal Code                                                  */
78 /*                                                                        */
79 /*  RELEASE HISTORY                                                       */
80 /*                                                                        */
81 /*    DATE              NAME                      DESCRIPTION             */
82 /*                                                                        */
83 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
84 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
85 /*                                            resulting in version 6.1    */
86 /*                                                                        */
87 /**************************************************************************/
_gx_scrollbar_draw(GX_SCROLLBAR * scrollbar)88 VOID  _gx_scrollbar_draw(GX_SCROLLBAR *scrollbar)
89 {
90 GX_PIXELMAP *map;
91 GX_VALUE     xpos;
92 GX_VALUE     ypos;
93 GX_VALUE     widget_width;
94 GX_VALUE     widget_height;
95 GX_RECTANGLE size;
96 GX_RECTANGLE old_dirty;
97 GX_COLOR     fill_color;
98 
99     if (scrollbar -> gx_widget_style & GX_STYLE_ENABLED)
100     {
101         if (scrollbar -> gx_widget_style & GX_STYLE_DRAW_SELECTED)
102         {
103             fill_color = scrollbar -> gx_widget_selected_fill_color;
104         }
105         else
106         {
107             fill_color = scrollbar -> gx_widget_normal_fill_color;
108         }
109     }
110     else
111     {
112         fill_color = scrollbar -> gx_widget_disabled_fill_color;
113     }
114 
115     if ((scrollbar -> gx_widget_style & GX_STYLE_TRANSPARENT) == 0)
116     {
117         size = scrollbar -> gx_widget_size;
118 
119         /* Draw background.  */
120         if (scrollbar -> gx_widget_style & GX_STYLE_BORDER_THIN)
121         {
122             _gx_context_brush_define(GX_COLOR_ID_SHADOW,
123                                      fill_color,
124                                      GX_BRUSH_SOLID_FILL);
125             _gx_context_brush_width_set(1);
126         }
127         else
128         {
129             _gx_context_brush_define(fill_color,
130                                      fill_color,
131                                      GX_BRUSH_SOLID_FILL);
132             _gx_context_brush_width_set(0);
133             _gx_canvas_rectangle_draw(&size);
134         }
135         _gx_canvas_rectangle_draw(&size);
136 
137         /* Draw pixelmaps.  */
138         _gx_context_pixelmap_get(scrollbar -> gx_scrollbar_appearance.gx_scroll_up_pixelmap, &map);
139 
140         if (map)
141         {
142             if (scrollbar -> gx_widget_type == GX_TYPE_VERTICAL_SCROLL)
143             {
144                 /* Draw up pixelmap.  */
145                 xpos = size.gx_rectangle_left;
146                 _gx_widget_width_get((GX_WIDGET *)scrollbar, &widget_width);
147                 xpos = (GX_VALUE)(xpos + (widget_width - map -> gx_pixelmap_width) / 2);
148 
149                 ypos = size.gx_rectangle_top;
150 
151                 size.gx_rectangle_top = (GX_VALUE)(size.gx_rectangle_top + map -> gx_pixelmap_height);
152             }
153             else
154             {
155                 /* Draw left pixelmap.  */
156                 xpos = size.gx_rectangle_left;
157 
158                 ypos = size.gx_rectangle_top;
159                 _gx_widget_height_get((GX_WIDGET *)scrollbar, &widget_height);
160                 ypos = (GX_VALUE)(ypos + (widget_height - map -> gx_pixelmap_height) / 2);
161 
162                 size.gx_rectangle_left = (GX_VALUE)(size.gx_rectangle_left + map -> gx_pixelmap_width);
163             }
164 
165             _gx_canvas_pixelmap_draw(xpos, ypos, map);
166         }
167 
168         _gx_context_pixelmap_get(scrollbar -> gx_scrollbar_appearance.gx_scroll_down_pixelmap, &map);
169 
170         if (map)
171         {
172             if (scrollbar -> gx_widget_type == GX_TYPE_VERTICAL_SCROLL)
173             {
174                 /* Draw down pixelmap.  */
175                 size.gx_rectangle_bottom = (GX_VALUE)(size.gx_rectangle_bottom - map -> gx_pixelmap_height);
176 
177                 xpos = size.gx_rectangle_left;
178                 _gx_widget_width_get((GX_WIDGET *)scrollbar, &widget_width);
179                 xpos = (GX_VALUE)(xpos + (widget_width - map -> gx_pixelmap_width) / 2);
180 
181                 ypos = size.gx_rectangle_bottom;
182             }
183             else
184             {
185                 /* Draw right pixelmap.  */
186                 size.gx_rectangle_right = (GX_VALUE)(size.gx_rectangle_right - map -> gx_pixelmap_width);
187 
188                 xpos = size.gx_rectangle_right;
189 
190                 ypos = size.gx_rectangle_top;
191                 _gx_widget_height_get((GX_WIDGET *)scrollbar, &widget_height);
192                 ypos = (GX_VALUE)(ypos + (widget_height - map -> gx_pixelmap_height) / 2);
193             }
194 
195             _gx_canvas_pixelmap_draw(xpos, ypos, map);
196         }
197 
198         _gx_context_pixelmap_get(scrollbar -> gx_scrollbar_appearance.gx_scroll_fill_pixelmap, &map);
199 
200         if (map)
201         {
202             /* Draw background pixelmap.  */
203             if (scrollbar -> gx_widget_style & GX_STYLE_TILE_BACKGROUND)
204             {
205                 _gx_canvas_pixelmap_tile(&size, map);
206             }
207             else
208             {
209                 xpos = size.gx_rectangle_left;
210                 _gx_widget_width_get((GX_WIDGET *)scrollbar, &widget_width);
211                 xpos = (GX_VALUE)(xpos + (widget_width - map -> gx_pixelmap_width) / 2);
212 
213                 ypos = size.gx_rectangle_top;
214                 _gx_widget_height_get((GX_WIDGET *)scrollbar, &widget_height);
215                 ypos = (GX_VALUE)(ypos + (widget_height - map -> gx_pixelmap_height) / 2);
216 
217                 /* Reset dirty area temporarily to avoid cover the end pixelmap area. */
218                 old_dirty = _gx_system_current_draw_context -> gx_draw_context_dirty;
219                 _gx_utility_rectangle_combine(&old_dirty, &size);
220                 _gx_system_current_draw_context -> gx_draw_context_dirty = size;
221 
222                 _gx_canvas_pixelmap_draw(xpos, ypos, map);
223 
224                 /* Set dirty area back. */
225                 _gx_system_current_draw_context -> gx_draw_context_dirty = old_dirty;
226             }
227         }
228     }
229 
230     /* Draw children widgets of prompt widget.  */
231     _gx_widget_children_draw((GX_WIDGET *)scrollbar);
232 }
233 
234