GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_radial_progress_bar_background_draw.c Lines: 74 74 100.0 %
Date: 2026-03-06 19:21:09 Branches: 36 36 100.0 %

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
/**   Progress Bar Management (Radial Progress Bar)                       */
19
/**                                                                       */
20
/**************************************************************************/
21
22
#define GX_SOURCE_CODE
23
24
/* Include necessary system files.  */
25
26
#include "gx_api.h"
27
#include "gx_context.h"
28
#include "gx_widget.h"
29
#include "gx_canvas.h"
30
#include "gx_utility.h"
31
#include "gx_radial_progress_bar.h"
32
#include "gx_system.h"
33
34
/**************************************************************************/
35
/*                                                                        */
36
/*  FUNCTION                                               RELEASE        */
37
/*                                                                        */
38
/*    _gx_radial_progress_bar_background_draw             PORTABLE C      */
39
/*                                                           6.1.8        */
40
/*  AUTHOR                                                                */
41
/*                                                                        */
42
/*    Kenneth Maxwell, Microsoft Corporation                              */
43
/*                                                                        */
44
/*  DESCRIPTION                                                           */
45
/*                                                                        */
46
/*    This service draws a radial progress bar background.                */
47
/*                                                                        */
48
/*  INPUT                                                                 */
49
/*                                                                        */
50
/*    progress_bar                          Radial Progress Bar control   */
51
/*                                            block                       */
52
/*                                                                        */
53
/*  OUTPUT                                                                */
54
/*                                                                        */
55
/*    None                                                                */
56
/*                                                                        */
57
/*  CALLS                                                                 */
58
/*                                                                        */
59
/*    _gx_widget_background_draw                                          */
60
/*    _gx_context_brush_get                                               */
61
/*    _gx_context_line_color_set                                          */
62
/*    _gx_context_brush_width_set                                         */
63
/*    _gx_canvas_circle_draw                                              */
64
/*    _gx_canvas_arc_draw                                                 */
65
/*                                                                        */
66
/*  CALLED BY                                                             */
67
/*                                                                        */
68
/*    Application Code                                                    */
69
/*    GUIX Internal Code                                                  */
70
/*                                                                        */
71
/**************************************************************************/
72
6180
VOID  _gx_radial_progress_bar_background_draw(GX_RADIAL_PROGRESS_BAR *progress_bar)
73
{
74
GX_RADIAL_PROGRESS_BAR_INFO *info;
75
GX_VALUE                     xcenter;
76
GX_VALUE                     ycenter;
77
GX_BRUSH                    *brush;
78
GX_RECTANGLE                *size;
79
80
#if defined(GX_BRUSH_ALPHA_SUPPORT)
81
GX_UBYTE     brush_alpha;
82
GX_RECTANGLE dirty;
83
GX_PIXELMAP  map;
84
VOID        *canvas_memory;
85
INT          canvas_size;
86
GX_DISPLAY  *display;
87
GX_CANVAS   *canvas;
88
6180
GX_VALUE     old_xpos = 0;
89
6180
GX_VALUE     old_ypos = 0;
90
#endif
91
92
6180
    _gx_context_brush_get(&brush);
93
94
#if defined(GX_BRUSH_ALPHA_SUPPORT)
95
6180
    brush_alpha = brush -> gx_brush_alpha;
96
6180
    if (brush_alpha == 0)
97
    {
98
1
        return;
99
    }
100
101
6179
    if (brush_alpha != GX_ALPHA_VALUE_OPAQUE)
102
    {
103
535
        size = &progress_bar -> gx_widget_size;
104
535
        map.gx_pixelmap_width = (GX_VALUE)(size -> gx_rectangle_right - size -> gx_rectangle_left + 1);
105
535
        map.gx_pixelmap_height = (GX_VALUE)(size -> gx_rectangle_bottom - size -> gx_rectangle_top + 1);
106
107
535
        display = _gx_system_current_draw_context -> gx_draw_context_display;
108
109

535
        if ((progress_bar -> gx_radial_progress_bar_canvas.gx_canvas_id != GX_CANVAS_ID) &&
110
            _gx_system_memory_allocator)
111
        {
112
113
            /* Pixelmap width and height is GX_VALUE type, overflow cannot occur. */
114
266
            canvas_size = display -> gx_display_driver_row_pitch_get((USHORT)map.gx_pixelmap_width);
115
266
            canvas_size *= map.gx_pixelmap_height;
116
117
266
            canvas_memory = _gx_system_memory_allocator((ULONG)canvas_size);
118
119
266
            if (canvas_memory)
120
            {
121
265
                _gx_canvas_create(&progress_bar -> gx_radial_progress_bar_canvas, "progress_bar_canvas",
122
265
                                  display, GX_CANVAS_SIMPLE, (UINT)map.gx_pixelmap_width,
123
265
                                  (UINT)map.gx_pixelmap_height, (GX_COLOR *)canvas_memory, (ULONG)canvas_size);
124
            }
125
        }
126
127
535
        if (progress_bar -> gx_radial_progress_bar_canvas.gx_canvas_id == GX_CANVAS_ID)
128
        {
129
            /* Remove resize notify temporary. */
130
533
            progress_bar -> gx_widget_status &= ~GX_STATUS_RESIZE_NOTIFY;
131
132
533
            old_xpos = size -> gx_rectangle_left;
133
533
            old_ypos = size -> gx_rectangle_top;
134
135

533
            if (old_xpos || old_ypos)
136
            {
137
531
                _gx_widget_shift((GX_WIDGET *)progress_bar, (GX_VALUE)(-old_xpos), (GX_VALUE)(-old_ypos), GX_FALSE);
138
            }
139
140
533
            canvas = _gx_system_current_draw_context -> gx_draw_context_canvas;
141
533
            dirty = canvas -> gx_canvas_dirty_area;
142
533
            _gx_utility_rectangle_shift(&dirty, (GX_VALUE)(-old_xpos), (GX_VALUE)(-old_ypos));
143
533
            _gx_utility_rectangle_overlap_detect(&dirty, &progress_bar -> gx_widget_size, &dirty);
144
145
533
            _gx_canvas_drawing_initiate(&progress_bar -> gx_radial_progress_bar_canvas, GX_NULL, &dirty);
146
147
533
            if (progress_bar -> gx_widget_status & GX_STATUS_TRANSPARENT)
148
            {
149
522
                xcenter = canvas -> gx_canvas_display_offset_x;
150
522
                ycenter = canvas -> gx_canvas_display_offset_y;
151
522
                _gx_canvas_offset_set(canvas, (GX_VALUE)(-old_xpos), (GX_VALUE)(-old_ypos));
152
522
                display -> gx_display_driver_canvas_copy(canvas, &progress_bar -> gx_radial_progress_bar_canvas);
153
522
                _gx_canvas_offset_set(canvas, xcenter, ycenter);
154
            }
155
156
533
            _gx_context_brush_get(&brush);
157
        }
158
    }
159
160
#endif
161
162
    /* Draw progress bar background.  */
163
6179
    _gx_widget_background_draw((GX_WIDGET *)progress_bar);
164
165
    /* Draw circular track.  */
166
6179
    info = &progress_bar -> gx_radial_progress_bar_info;
167
168
6179
    size = &progress_bar -> gx_widget_size;
169
170
6179
    xcenter = (GX_VALUE)(size -> gx_rectangle_right + size -> gx_rectangle_left);
171
6179
    xcenter >>= 1;
172
173
6179
    ycenter = (GX_VALUE)(size -> gx_rectangle_bottom + size -> gx_rectangle_top);
174
6179
    ycenter >>= 1;
175
176
6179
    brush -> gx_brush_style &= (ULONG)(~GX_BRUSH_SOLID_FILL);
177
178
6179
    if (progress_bar -> gx_widget_style & GX_STYLE_RADIAL_PROGRESS_ALIAS)
179
    {
180
5701
        brush -> gx_brush_style |= GX_BRUSH_ALIAS;
181
    }
182
183
6179
    if (progress_bar -> gx_widget_style & GX_STYLE_RADIAL_PROGRESS_ROUND)
184
    {
185
5702
        brush -> gx_brush_style |= GX_BRUSH_ROUND;
186
    }
187
188
6179
    if (!(progress_bar -> gx_widget_style & GX_STYLE_RADIAL_PROGRESS_NO_BACKTRACK))
189
    {
190
4068
        _gx_context_line_color_set(info -> gx_radial_progress_bar_info_normal_brush_color);
191
4068
        _gx_context_brush_width_set((UINT)(info -> gx_radial_progress_bar_info_normal_brush_width));
192
193
4068
        _gx_canvas_circle_draw(xcenter, ycenter, (UINT)(info -> gx_radial_progress_bar_info_radius));
194
    }
195
196
6179
    if (info -> gx_radial_progress_bar_info_current_val != 0)
197
    {
198
6147
        _gx_context_line_color_set(info -> gx_radial_progress_bar_info_selected_brush_color);
199
6147
        brush -> gx_brush_width = info -> gx_radial_progress_bar_info_selected_brush_width;
200
201
6147
        if (info -> gx_radial_progress_bar_info_current_val > 0)
202
        {
203
782
            _gx_canvas_arc_draw(xcenter, ycenter,
204
782
                                (UINT)(info -> gx_radial_progress_bar_info_radius),
205
782
                                info -> gx_radial_progress_bar_info_anchor_val,
206
782
                                info -> gx_radial_progress_bar_info_current_val + info -> gx_radial_progress_bar_info_anchor_val);
207
        }
208
        else
209
        {
210
5365
            _gx_canvas_arc_draw(xcenter, ycenter,
211
5365
                                (UINT)(info -> gx_radial_progress_bar_info_radius),
212
5365
                                info -> gx_radial_progress_bar_info_current_val + info -> gx_radial_progress_bar_info_anchor_val,
213
5365
                                info -> gx_radial_progress_bar_info_anchor_val);
214
        }
215
    }
216
217
#if defined(GX_BRUSH_ALPHA_SUPPORT)
218
6179
    if ((brush_alpha != GX_ALPHA_VALUE_OPAQUE) &&
219
535
        (progress_bar -> gx_radial_progress_bar_canvas.gx_canvas_id == GX_CANVAS_ID))
220
    {
221

533
        if (old_xpos || old_ypos)
222
        {
223
531
            _gx_widget_shift((GX_WIDGET *)progress_bar, old_xpos, old_ypos, GX_FALSE);
224
        }
225
226
533
        _gx_canvas_pixelmap_get(&map);
227
533
        _gx_canvas_drawing_complete(&progress_bar -> gx_radial_progress_bar_canvas, GX_FALSE);
228
533
        _gx_canvas_pixelmap_blend(old_xpos, old_ypos, &map, brush_alpha);
229
230
        /* Added resize notification back. */
231
533
        progress_bar -> gx_widget_status |= GX_STATUS_RESIZE_NOTIFY;
232
    }
233
#endif
234
}
235