GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_radio_button_draw.c Lines: 51 51 100.0 %
Date: 2026-03-06 19:21:09 Branches: 17 17 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
/**   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
/*  FUNCTION                                               RELEASE        */
37
/*                                                                        */
38
/*    _gx_radio_button_draw                               PORTABLE C      */
39
/*                                                           6.1          */
40
/*  AUTHOR                                                                */
41
/*                                                                        */
42
/*    Kenneth Maxwell, Microsoft Corporation                              */
43
/*                                                                        */
44
/*  DESCRIPTION                                                           */
45
/*                                                                        */
46
/*    This service draws a radio button widget.                           */
47
/*                                                                        */
48
/*  INPUT                                                                 */
49
/*                                                                        */
50
/*    button                                Pointer to radio button       */
51
/*                                            widget control block        */
52
/*                                                                        */
53
/*  OUTPUT                                                                */
54
/*                                                                        */
55
/*    None                                                                */
56
/*                                                                        */
57
/*  CALLS                                                                 */
58
/*                                                                        */
59
/*    _gx_context_pixelmap_get              Retrieve pixelmap image       */
60
/*    _gx_canvas_pixelmap_draw              Draw the pixelmap             */
61
/*    _gx_widget_text_id_draw               Draw the text based on ID     */
62
/*    _gx_widget_text_draw                  Draw the text string          */
63
/*    _gx_widget_children_draw              Draw children widgets         */
64
/*                                                                        */
65
/*  CALLED BY                                                             */
66
/*                                                                        */
67
/*    Application Code                                                    */
68
/*    GUIX Internal Code                                                  */
69
/*                                                                        */
70
/**************************************************************************/
71
174470
VOID  _gx_radio_button_draw(GX_RADIO_BUTTON *button)
72
{
73
74
174470
GX_VALUE       xoffset = 0;
75
174470
GX_VALUE       yoffset = 0;
76
GX_RESOURCE_ID text_color;
77
GX_RESOURCE_ID fill_color;
78
GX_RESOURCE_ID pixelmap_id;
79
174470
GX_PIXELMAP   *pixelmap = GX_NULL;
80
GX_STRING      string;
81
82
174470
    if (button -> gx_widget_style & GX_STYLE_ENABLED)
83
    {
84
85
174432
        if (button -> gx_widget_style & GX_STYLE_BUTTON_PUSHED)
86
        {
87
54809
            fill_color = button -> gx_widget_selected_fill_color;
88
54809
            text_color = button -> gx_text_button_selected_text_color;
89
54809
            pixelmap_id = button -> gx_radio_button_on_pixelmap_id;
90
        }
91
        else
92
        {
93
119623
            fill_color = button -> gx_widget_normal_fill_color;
94
119623
            text_color = button -> gx_text_button_normal_text_color;
95
119623
            pixelmap_id = button -> gx_radio_button_off_pixelmap_id;
96
        }
97
    }
98
    else
99
    {
100
38
        fill_color = button -> gx_widget_disabled_fill_color;
101
38
        text_color = button -> gx_text_button_disabled_text_color;
102
103
38
        if (button -> gx_widget_style & GX_STYLE_BUTTON_PUSHED)
104
        {
105
7
            pixelmap_id = button -> gx_radio_button_on_disabled_pixelmap_id;
106
        }
107
        else
108
        {
109
31
            pixelmap_id = button -> gx_radio_button_off_disabled_pixelmap_id;
110
        }
111
    }
112
113
174470
    if (!(button -> gx_widget_status & GX_STATUS_TRANSPARENT))
114
    {
115
46
        _gx_widget_border_draw((GX_WIDGET *)button, GX_COLOR_ID_DEFAULT_BORDER, fill_color, fill_color, GX_TRUE);
116
    }
117
118
174470
    if (pixelmap_id)
119
    {
120
174469
        _gx_context_pixelmap_get(pixelmap_id, &pixelmap);
121
    }
122
174470
    if (pixelmap)
123
    {
124
174467
        _gx_widget_height_get((GX_WIDGET *)button, &yoffset);
125
174467
        yoffset = (GX_VALUE)((yoffset - pixelmap -> gx_pixelmap_height) / 2);
126
127
174467
        switch (button -> gx_widget_style & GX_STYLE_TEXT_ALIGNMENT_MASK)
128
        {
129
4
        case GX_STYLE_TEXT_RIGHT:
130
4
            _gx_widget_width_get((GX_WIDGET *)button, &xoffset);
131
4
            xoffset = (GX_VALUE)(xoffset - pixelmap -> gx_pixelmap_width + 1);
132
            /* draw the pixelmap on the right */
133
4
            _gx_canvas_pixelmap_draw((GX_VALUE)(button -> gx_widget_size.gx_rectangle_right -
134
4
                                                pixelmap -> gx_pixelmap_width + 1),
135
4
                                     (GX_VALUE)(button -> gx_widget_size.gx_rectangle_top + yoffset), pixelmap);
136
137
            /* draw the text to the left of the bitmap */
138
4
            xoffset = (GX_VALUE)(-(pixelmap -> gx_pixelmap_width * 3 / 2));
139
4
            break;
140
141
4
        case GX_STYLE_TEXT_CENTER:
142
            /* draw the pixelmap and text centered         */
143
4
            _gx_widget_width_get((GX_WIDGET *)button, &xoffset);
144
4
            xoffset = (GX_VALUE)((xoffset - pixelmap -> gx_pixelmap_width) / 2);
145
146
            /* draw the pixelmap centered */
147
4
            _gx_canvas_pixelmap_draw((GX_VALUE)(button -> gx_widget_size.gx_rectangle_left + xoffset),
148
4
                                     (GX_VALUE)(button -> gx_widget_size.gx_rectangle_top + yoffset), pixelmap);
149
            /* draw the text centered: */
150
4
            xoffset = 0;
151
4
            break;
152
153
174459
        case GX_STYLE_TEXT_LEFT:
154
        default:
155
            /* draw the pixelmap on the left */
156
174459
            _gx_canvas_pixelmap_draw(button -> gx_widget_size.gx_rectangle_left,
157
174459
                                     (GX_VALUE)(button -> gx_widget_size.gx_rectangle_top + yoffset), pixelmap);
158
159
            /* draw the text to the right of the pixelmap */
160
174459
            xoffset = (GX_VALUE)(pixelmap -> gx_pixelmap_width * 3 / 2);
161
174459
            break;
162
        }
163
    }
164
165
166
174470
    _gx_text_button_text_get_ext((GX_TEXT_BUTTON *)button, &string);
167
168
174470
    if (string.gx_string_ptr)
169
    {
170
174469
        _gx_widget_text_draw_ext((GX_WIDGET *)button, text_color,
171
174469
                                 button -> gx_text_button_font_id,
172
                                 &string, xoffset, 0);
173
    }
174
175
    /* Draw button's children.  */
176
174470
    _gx_widget_children_draw((GX_WIDGET *)button);
177
174470
}
178