GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_scrollbar_draw.c Lines: 60 60 100.0 %
Date: 2026-03-06 19:21:09 Branches: 21 22 95.5 %

Line Branch Exec Source
1
/***************************************************************************
2
 * Copyright (c) 2024 Microsoft Corporation
3
 * Copyright (c) 2026-present Eclipse ThreadX contributors
4
 *
5
 * This program and the accompanying materials are made available under the
6
 * terms of the MIT License which is available at
7
 * https://opensource.org/licenses/MIT.
8
 *
9
 * SPDX-License-Identifier: MIT
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.3.0        */
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
/**************************************************************************/
80
17459
VOID  _gx_scrollbar_draw(GX_SCROLLBAR *scrollbar)
81
{
82
GX_PIXELMAP *map;
83
GX_VALUE     xpos;
84
GX_VALUE     ypos;
85
GX_VALUE     widget_width;
86
GX_VALUE     widget_height;
87
GX_RECTANGLE size;
88
GX_RECTANGLE old_dirty;
89
GX_COLOR     fill_color;
90
91
17459
    if (scrollbar -> gx_widget_style & GX_STYLE_ENABLED)
92
    {
93
5606
        if (scrollbar -> gx_widget_style & GX_STYLE_DRAW_SELECTED)
94
        {
95
8
            fill_color = scrollbar -> gx_widget_selected_fill_color;
96
        }
97
        else
98
        {
99
5598
            fill_color = scrollbar -> gx_widget_normal_fill_color;
100
        }
101
    }
102
    else
103
    {
104
11853
        fill_color = scrollbar -> gx_widget_disabled_fill_color;
105
    }
106
107
17459
    if ((scrollbar -> gx_widget_style & GX_STYLE_TRANSPARENT) == 0)
108
    {
109
17269
        size = scrollbar -> gx_widget_size;
110
111
        /* Draw background.  */
112
17269
        if (scrollbar -> gx_widget_style & GX_STYLE_BORDER_THIN)
113
        {
114
342
            _gx_context_brush_define(GX_COLOR_ID_SHADOW,
115
                                     fill_color,
116
                                     GX_BRUSH_SOLID_FILL);
117
342
            _gx_context_brush_width_set(1);
118
        }
119
        else
120
        {
121
16927
            _gx_context_brush_define(fill_color,
122
                                     fill_color,
123
                                     GX_BRUSH_SOLID_FILL);
124
16927
            _gx_context_brush_width_set(0);
125
16927
            _gx_canvas_rectangle_draw(&size);
126
        }
127
17269
        _gx_canvas_rectangle_draw(&size);
128
129
        /* Draw pixelmaps.  */
130
17269
        _gx_context_pixelmap_get(scrollbar -> gx_scrollbar_appearance.gx_scroll_up_pixelmap, &map);
131
132
17269
        if (map)
133
        {
134
406
            if (scrollbar -> gx_widget_type == GX_TYPE_VERTICAL_SCROLL)
135
            {
136
                /* Draw up pixelmap.  */
137
158
                xpos = size.gx_rectangle_left;
138
158
                _gx_widget_width_get((GX_WIDGET *)scrollbar, &widget_width);
139
158
                xpos = (GX_VALUE)(xpos + (widget_width - map -> gx_pixelmap_width) / 2);
140
141
158
                ypos = size.gx_rectangle_top;
142
143
158
                size.gx_rectangle_top = (GX_VALUE)(size.gx_rectangle_top + map -> gx_pixelmap_height);
144
            }
145
            else
146
            {
147
                /* Draw left pixelmap.  */
148
248
                xpos = size.gx_rectangle_left;
149
150
248
                ypos = size.gx_rectangle_top;
151
248
                _gx_widget_height_get((GX_WIDGET *)scrollbar, &widget_height);
152
248
                ypos = (GX_VALUE)(ypos + (widget_height - map -> gx_pixelmap_height) / 2);
153
154
248
                size.gx_rectangle_left = (GX_VALUE)(size.gx_rectangle_left + map -> gx_pixelmap_width);
155
            }
156
157
406
            _gx_canvas_pixelmap_draw(xpos, ypos, map);
158
        }
159
160
17269
        _gx_context_pixelmap_get(scrollbar -> gx_scrollbar_appearance.gx_scroll_down_pixelmap, &map);
161
162
17269
        if (map)
163
        {
164
406
            if (scrollbar -> gx_widget_type == GX_TYPE_VERTICAL_SCROLL)
165
            {
166
                /* Draw down pixelmap.  */
167
158
                size.gx_rectangle_bottom = (GX_VALUE)(size.gx_rectangle_bottom - map -> gx_pixelmap_height);
168
169
158
                xpos = size.gx_rectangle_left;
170
158
                _gx_widget_width_get((GX_WIDGET *)scrollbar, &widget_width);
171
158
                xpos = (GX_VALUE)(xpos + (widget_width - map -> gx_pixelmap_width) / 2);
172
173
158
                ypos = size.gx_rectangle_bottom;
174
            }
175
            else
176
            {
177
                /* Draw right pixelmap.  */
178
248
                size.gx_rectangle_right = (GX_VALUE)(size.gx_rectangle_right - map -> gx_pixelmap_width);
179
180
248
                xpos = size.gx_rectangle_right;
181
182
248
                ypos = size.gx_rectangle_top;
183
248
                _gx_widget_height_get((GX_WIDGET *)scrollbar, &widget_height);
184
248
                ypos = (GX_VALUE)(ypos + (widget_height - map -> gx_pixelmap_height) / 2);
185
            }
186
187
406
            _gx_canvas_pixelmap_draw(xpos, ypos, map);
188
        }
189
190
17269
        _gx_context_pixelmap_get(scrollbar -> gx_scrollbar_appearance.gx_scroll_fill_pixelmap, &map);
191
192
17269
        if (map)
193
        {
194
            /* Draw background pixelmap.  */
195
2584
            if (scrollbar -> gx_widget_style & GX_STYLE_TILE_BACKGROUND)
196
            {
197
2426
                _gx_canvas_pixelmap_tile(&size, map);
198
            }
199
            else
200
            {
201
158
                xpos = size.gx_rectangle_left;
202
158
                _gx_widget_width_get((GX_WIDGET *)scrollbar, &widget_width);
203
158
                xpos = (GX_VALUE)(xpos + (widget_width - map -> gx_pixelmap_width) / 2);
204
205
158
                ypos = size.gx_rectangle_top;
206
158
                _gx_widget_height_get((GX_WIDGET *)scrollbar, &widget_height);
207
158
                ypos = (GX_VALUE)(ypos + (widget_height - map -> gx_pixelmap_height) / 2);
208
209
                /* Reset dirty area temporarily to avoid cover the end pixelmap area. */
210
158
                old_dirty = _gx_system_current_draw_context -> gx_draw_context_dirty;
211
158
                if(_gx_utility_rectangle_overlap_detect(&old_dirty, &size, &size) == GX_TRUE)
212
                {
213
158
                    _gx_system_current_draw_context -> gx_draw_context_dirty = size;
214
215
158
                    _gx_canvas_pixelmap_draw(xpos, ypos, map);
216
217
                    /* Set dirty area back. */
218
158
                    _gx_system_current_draw_context -> gx_draw_context_dirty = old_dirty;
219
                }
220
            }
221
        }
222
    }
223
224
    /* Draw children widgets of prompt widget.  */
225
17459
    _gx_widget_children_draw((GX_WIDGET *)scrollbar);
226
17459
}
227