GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_radio_button_draw.c Lines: 51 51 100.0 %
Date: 2024-12-05 08:52:37 Branches: 17 17 100.0 %

Line Branch Exec Source
1
/***************************************************************************
2
 * Copyright (c) 2024 Microsoft Corporation
3
 *
4
 * This program and the accompanying materials are made available under the
5
 * terms of the MIT License which is available at
6
 * https://opensource.org/licenses/MIT.
7
 *
8
 * SPDX-License-Identifier: MIT
9
 **************************************************************************/
10
11
12
/**************************************************************************/
13
/**************************************************************************/
14
/**                                                                       */
15
/** GUIX Component                                                        */
16
/**                                                                       */
17
/**   Button Management (Button)                                          */
18
/**                                                                       */
19
/**************************************************************************/
20
21
#define GX_SOURCE_CODE
22
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_button.h"
32
33
/**************************************************************************/
34
/*                                                                        */
35
/*  FUNCTION                                               RELEASE        */
36
/*                                                                        */
37
/*    _gx_radio_button_draw                               PORTABLE C      */
38
/*                                                           6.1          */
39
/*  AUTHOR                                                                */
40
/*                                                                        */
41
/*    Kenneth Maxwell, Microsoft Corporation                              */
42
/*                                                                        */
43
/*  DESCRIPTION                                                           */
44
/*                                                                        */
45
/*    This service draws a radio button widget.                           */
46
/*                                                                        */
47
/*  INPUT                                                                 */
48
/*                                                                        */
49
/*    button                                Pointer to radio button       */
50
/*                                            widget control block        */
51
/*                                                                        */
52
/*  OUTPUT                                                                */
53
/*                                                                        */
54
/*    None                                                                */
55
/*                                                                        */
56
/*  CALLS                                                                 */
57
/*                                                                        */
58
/*    _gx_context_pixelmap_get              Retrieve pixelmap image       */
59
/*    _gx_canvas_pixelmap_draw              Draw the pixelmap             */
60
/*    _gx_widget_text_id_draw               Draw the text based on ID     */
61
/*    _gx_widget_text_draw                  Draw the text string          */
62
/*    _gx_widget_children_draw              Draw children widgets         */
63
/*                                                                        */
64
/*  CALLED BY                                                             */
65
/*                                                                        */
66
/*    Application Code                                                    */
67
/*    GUIX Internal Code                                                  */
68
/*                                                                        */
69
/*  RELEASE HISTORY                                                       */
70
/*                                                                        */
71
/*    DATE              NAME                      DESCRIPTION             */
72
/*                                                                        */
73
/*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
74
/*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
75
/*                                            improved logic,             */
76
/*                                            resulting in version 6.1    */
77
/*                                                                        */
78
/**************************************************************************/
79
174469
VOID  _gx_radio_button_draw(GX_RADIO_BUTTON *button)
80
{
81
82
174469
GX_VALUE       xoffset = 0;
83
174469
GX_VALUE       yoffset = 0;
84
GX_RESOURCE_ID text_color;
85
GX_RESOURCE_ID fill_color;
86
GX_RESOURCE_ID pixelmap_id;
87
174469
GX_PIXELMAP   *pixelmap = GX_NULL;
88
GX_STRING      string;
89
90
174469
    if (button -> gx_widget_style & GX_STYLE_ENABLED)
91
    {
92
93
174431
        if (button -> gx_widget_style & GX_STYLE_BUTTON_PUSHED)
94
        {
95
54809
            fill_color = button -> gx_widget_selected_fill_color;
96
54809
            text_color = button -> gx_text_button_selected_text_color;
97
54809
            pixelmap_id = button -> gx_radio_button_on_pixelmap_id;
98
        }
99
        else
100
        {
101
119622
            fill_color = button -> gx_widget_normal_fill_color;
102
119622
            text_color = button -> gx_text_button_normal_text_color;
103
119622
            pixelmap_id = button -> gx_radio_button_off_pixelmap_id;
104
        }
105
    }
106
    else
107
    {
108
38
        fill_color = button -> gx_widget_disabled_fill_color;
109
38
        text_color = button -> gx_text_button_disabled_text_color;
110
111
38
        if (button -> gx_widget_style & GX_STYLE_BUTTON_PUSHED)
112
        {
113
7
            pixelmap_id = button -> gx_radio_button_on_disabled_pixelmap_id;
114
        }
115
        else
116
        {
117
31
            pixelmap_id = button -> gx_radio_button_off_disabled_pixelmap_id;
118
        }
119
    }
120
121
174469
    if (!(button -> gx_widget_status & GX_STATUS_TRANSPARENT))
122
    {
123
46
        _gx_widget_border_draw((GX_WIDGET *)button, GX_COLOR_ID_DEFAULT_BORDER, fill_color, fill_color, GX_TRUE);
124
    }
125
126
174469
    if (pixelmap_id)
127
    {
128
174468
        _gx_context_pixelmap_get(pixelmap_id, &pixelmap);
129
    }
130
174469
    if (pixelmap)
131
    {
132
174466
        _gx_widget_height_get((GX_WIDGET *)button, &yoffset);
133
174466
        yoffset = (GX_VALUE)((yoffset - pixelmap -> gx_pixelmap_height) / 2);
134
135
174466
        switch (button -> gx_widget_style & GX_STYLE_TEXT_ALIGNMENT_MASK)
136
        {
137
4
        case GX_STYLE_TEXT_RIGHT:
138
4
            _gx_widget_width_get((GX_WIDGET *)button, &xoffset);
139
4
            xoffset = (GX_VALUE)(xoffset - pixelmap -> gx_pixelmap_width + 1);
140
            /* draw the pixelmap on the right */
141
4
            _gx_canvas_pixelmap_draw((GX_VALUE)(button -> gx_widget_size.gx_rectangle_right -
142
4
                                                pixelmap -> gx_pixelmap_width + 1),
143
4
                                     (GX_VALUE)(button -> gx_widget_size.gx_rectangle_top + yoffset), pixelmap);
144
145
            /* draw the text to the left of the bitmap */
146
4
            xoffset = (GX_VALUE)(-(pixelmap -> gx_pixelmap_width * 3 / 2));
147
4
            break;
148
149
4
        case GX_STYLE_TEXT_CENTER:
150
            /* draw the pixelmap and text centered         */
151
4
            _gx_widget_width_get((GX_WIDGET *)button, &xoffset);
152
4
            xoffset = (GX_VALUE)((xoffset - pixelmap -> gx_pixelmap_width) / 2);
153
154
            /* draw the pixelmap centered */
155
4
            _gx_canvas_pixelmap_draw((GX_VALUE)(button -> gx_widget_size.gx_rectangle_left + xoffset),
156
4
                                     (GX_VALUE)(button -> gx_widget_size.gx_rectangle_top + yoffset), pixelmap);
157
            /* draw the text centered: */
158
4
            xoffset = 0;
159
4
            break;
160
161
174458
        case GX_STYLE_TEXT_LEFT:
162
        default:
163
            /* draw the pixelmap on the left */
164
174458
            _gx_canvas_pixelmap_draw(button -> gx_widget_size.gx_rectangle_left,
165
174458
                                     (GX_VALUE)(button -> gx_widget_size.gx_rectangle_top + yoffset), pixelmap);
166
167
            /* draw the text to the right of the pixelmap */
168
174458
            xoffset = (GX_VALUE)(pixelmap -> gx_pixelmap_width * 3 / 2);
169
174458
            break;
170
        }
171
    }
172
173
174
174469
    _gx_text_button_text_get_ext((GX_TEXT_BUTTON *)button, &string);
175
176
174469
    if (string.gx_string_ptr)
177
    {
178
174468
        _gx_widget_text_draw_ext((GX_WIDGET *)button, text_color,
179
174468
                                 button -> gx_text_button_font_id,
180
                                 &string, xoffset, 0);
181
    }
182
183
    /* Draw button's children.  */
184
174469
    _gx_widget_children_draw((GX_WIDGET *)button);
185
174469
}
186