GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_checkbox_draw.c Lines: 52 52 100.0 %
Date: 2026-03-06 19:21:09 Branches: 18 18 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
/*                                                                        */
37
/*  FUNCTION                                               RELEASE        */
38
/*                                                                        */
39
/*    _gx_checkbox_draw                                   PORTABLE C      */
40
/*                                                           6.1          */
41
/*  AUTHOR                                                                */
42
/*                                                                        */
43
/*    Kenneth Maxwell, Microsoft Corporation                              */
44
/*                                                                        */
45
/*  DESCRIPTION                                                           */
46
/*                                                                        */
47
/*    This function draws the specified button, which is a special type   */
48
/*    of widget.                                                          */
49
/*                                                                        */
50
/*  INPUT                                                                 */
51
/*                                                                        */
52
/*    button                                Checkbox control block        */
53
/*                                                                        */
54
/*  OUTPUT                                                                */
55
/*                                                                        */
56
/*    None                                                                */
57
/*                                                                        */
58
/*  CALLS                                                                 */
59
/*                                                                        */
60
/*    _gx_context_pixelmap_get              Retrieve pixelmap image       */
61
/*    _gx_widget_height_get                 Gets the height of the widget */
62
/*    _gx_canvas_pixelmap_draw              Draw the pixelmap image       */
63
/*    _gx_widget_text_id_draw               Draw the text based on ID     */
64
/*    _gx_widget_text_draw                  Draw the text string          */
65
/*    _gx_widget_children_draw              Draw children widgets         */
66
/*                                                                        */
67
/*  CALLED BY                                                             */
68
/*                                                                        */
69
/*    Application Code                                                    */
70
/*    GUIX Internal Code                                                  */
71
/*                                                                        */
72
/**************************************************************************/
73
99966
VOID  _gx_checkbox_draw(GX_CHECKBOX *checkbox)
74
{
75
99966
GX_WIDGET     *widget = (GX_WIDGET *)checkbox;
76
99966
GX_VALUE       xoffset = 0;
77
99966
GX_VALUE       yoffset = 0;
78
GX_RESOURCE_ID fill_color;
79
GX_RESOURCE_ID text_color;
80
GX_RESOURCE_ID pixelmap_id;
81
99966
GX_PIXELMAP   *pixelmap = GX_NULL;
82
GX_STRING      string;
83
84
99966
    if (widget -> gx_widget_style & GX_STYLE_ENABLED)
85
    {
86
99928
        if (widget -> gx_widget_style & GX_STYLE_BUTTON_PUSHED)
87
        {
88
28730
            fill_color = widget -> gx_widget_selected_fill_color;
89
28730
            text_color = checkbox -> gx_text_button_selected_text_color;
90
28730
            pixelmap_id = checkbox -> gx_checkbox_checked_pixelmap_id;
91
        }
92
        else
93
        {
94
71198
            fill_color = widget -> gx_widget_normal_fill_color;
95
71198
            text_color = checkbox -> gx_text_button_normal_text_color;
96
71198
            pixelmap_id = checkbox -> gx_checkbox_unchecked_pixelmap_id;
97
        }
98
    }
99
    else
100
    {
101
38
        fill_color = checkbox -> gx_widget_disabled_fill_color;
102
38
        text_color = checkbox -> gx_text_button_disabled_text_color;
103
38
        if (widget -> gx_widget_style & GX_STYLE_BUTTON_PUSHED)
104
        {
105
7
            pixelmap_id = checkbox -> gx_checkbox_checked_disabled_pixelmap_id;
106
        }
107
        else
108
        {
109
31
            pixelmap_id = checkbox -> gx_checkbox_unchecked_disabled_pixelmap_id;
110
        }
111
    }
112
113
    /* If I am not transparent, draw my border and background */
114
115
99966
    if (!(widget -> gx_widget_status & GX_STATUS_TRANSPARENT))
116
    {
117
46
        _gx_widget_border_draw(widget, GX_COLOR_ID_DEFAULT_BORDER, fill_color, fill_color, GX_TRUE);
118
    }
119
120
    /* draw the pixelmap */
121
122
99966
    if (pixelmap_id)
123
    {
124
99963
        _gx_context_pixelmap_get(pixelmap_id, &pixelmap);
125
    }
126
127
99966
    if (pixelmap)
128
    {
129
99901
        _gx_widget_height_get((GX_WIDGET *)checkbox, &yoffset);
130
99901
        yoffset = (GX_VALUE)((yoffset - pixelmap -> gx_pixelmap_height) / 2);
131
132

99901
        switch (checkbox -> gx_widget_style & GX_STYLE_TEXT_ALIGNMENT_MASK)
133
        {
134
4
        case GX_STYLE_TEXT_RIGHT:
135
4
            _gx_widget_width_get((GX_WIDGET *)checkbox, &xoffset);
136
4
            xoffset = (GX_VALUE)(xoffset - pixelmap -> gx_pixelmap_width + 1);
137
            /* draw the pixelmap on the right */
138
4
            _gx_canvas_pixelmap_draw((GX_VALUE)(checkbox -> gx_widget_size.gx_rectangle_right -
139
4
                                                pixelmap -> gx_pixelmap_width + 1),
140
4
                                     (GX_VALUE)(checkbox -> gx_widget_size.gx_rectangle_top + yoffset), pixelmap);
141
142
            /* draw the text to the left of the bitmap */
143
4
            xoffset = (GX_VALUE)(-(pixelmap -> gx_pixelmap_width * 3 / 2));
144
4
            break;
145
146
4
        case GX_STYLE_TEXT_CENTER:
147
            /* draw the pixelmap and text centered         */
148
4
            _gx_widget_width_get((GX_WIDGET *)checkbox, &xoffset);
149
4
            xoffset = (GX_VALUE)((xoffset - pixelmap -> gx_pixelmap_width) / 2);
150
151
            /* draw the pixelmap centered */
152
4
            _gx_canvas_pixelmap_draw((GX_VALUE)(checkbox -> gx_widget_size.gx_rectangle_left + xoffset),
153
4
                                     (GX_VALUE)(checkbox -> gx_widget_size.gx_rectangle_top + yoffset), pixelmap);
154
            /* draw the text centered: */
155
4
            xoffset = 0;
156
4
            break;
157
158
99887
        case GX_STYLE_TEXT_LEFT:
159
            /* draw the pixelmap on the left */
160
99887
            _gx_canvas_pixelmap_draw(checkbox -> gx_widget_size.gx_rectangle_left,
161
99887
                                     (GX_VALUE)(checkbox -> gx_widget_size.gx_rectangle_top + yoffset), pixelmap);
162
163
            /* draw the text to the right of the pixelmap */
164
99887
            xoffset = (GX_VALUE)(pixelmap -> gx_pixelmap_width * 3 / 2);
165
99887
            break;
166
        }
167
    }
168
169
99966
    _gx_text_button_text_get_ext((GX_TEXT_BUTTON *)checkbox, &string);
170
171
99966
    if (string.gx_string_ptr)
172
    {
173
99964
        _gx_widget_text_draw_ext(widget, text_color,
174
99964
                                 checkbox -> gx_text_button_font_id,
175
                                 &string, xoffset, 0);
176
    }
177
178
    /* Draw checkbox's children.  */
179
99966
    _gx_widget_children_draw(widget);
180
99966
}
181