GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_pixelmap_button_draw.c Lines: 48 48 100.0 %
Date: 2026-03-06 19:21:09 Branches: 22 22 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_pixelmap_button_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                                Button control block          */
53
/*                                                                        */
54
/*  OUTPUT                                                                */
55
/*                                                                        */
56
/*    None                                                                */
57
/*                                                                        */
58
/*  CALLS                                                                 */
59
/*                                                                        */
60
/*    _gx_context_pixelmap_get              Retrieve pixelmap image       */
61
/*    _gx_canvas_pixelmap_draw              Draw the pixelmap             */
62
/*    _gx_button_draw                       Draw the button               */
63
/*    _gx_widget_children_draw              Draw children widgets         */
64
/*                                                                        */
65
/*  CALLED BY                                                             */
66
/*                                                                        */
67
/*    Application Code                                                    */
68
/*    GUIX Internal Code                                                  */
69
/*                                                                        */
70
/**************************************************************************/
71
8544
VOID  _gx_pixelmap_button_draw(GX_PIXELMAP_BUTTON *button)
72
{
73
GX_RESOURCE_ID pixelmap;
74
GX_PIXELMAP   *map;
75
8544
GX_WIDGET     *widget = (GX_WIDGET *)button;
76
INT            xpos;
77
INT            ypos;
78
79
80
    /* default to using the normal pixlemap */
81
8544
    pixelmap = button -> gx_pixelmap_button_normal_id;
82
83
    /* If the button is not enabled and the user provided
84
       a disabled pixelmap, use that */
85
8544
    if (button -> gx_pixelmap_button_disabled_id &&
86
1187
        !(button -> gx_widget_style & GX_STYLE_ENABLED))
87
    {
88
65
        pixelmap = button -> gx_pixelmap_button_disabled_id;
89
    }
90
    else
91
    {
92
        /* otherwise, if the button is pushed used the selected pixelmap */
93
8479
        if (button -> gx_widget_style & GX_STYLE_BUTTON_PUSHED)
94
        {
95
132
            if (button -> gx_pixelmap_button_selected_id)
96
            {
97
115
                pixelmap = button -> gx_pixelmap_button_selected_id;
98
            }
99
        }
100
    }
101
102
8544
    if (!(button -> gx_widget_style & GX_STYLE_ENABLED))
103
    {
104
68
        if (button -> gx_pixelmap_button_disabled_id)
105
        {
106
65
            pixelmap = button -> gx_pixelmap_button_disabled_id;
107
        }
108
    }
109
110
8544
    _gx_context_pixelmap_get(pixelmap, &map);
111
112
8544
    if (map)
113
    {
114
8516
        switch (button -> gx_widget_style & GX_PIXELMAP_HALIGN_MASK)
115
        {
116
1818
        case GX_STYLE_HALIGN_CENTER:
117
1818
            xpos = button -> gx_widget_size.gx_rectangle_right -
118
1818
                button -> gx_widget_size.gx_rectangle_left -
119
1818
                map -> gx_pixelmap_width + 1;
120
121
1818
            xpos /= 2;
122
1818
            xpos += button -> gx_widget_size.gx_rectangle_left;
123
1818
            break;
124
125
2
        case GX_STYLE_HALIGN_RIGHT:
126
2
            xpos = button -> gx_widget_size.gx_rectangle_right - map -> gx_pixelmap_width + 1;
127
2
            break;
128
129
6696
        default:
130
6696
            xpos = button -> gx_widget_size.gx_rectangle_left;
131
6696
            break;
132
        }
133
134
8516
        switch (button -> gx_widget_style & GX_PIXELMAP_VALIGN_MASK)
135
        {
136
1827
        case GX_STYLE_VALIGN_CENTER:
137
1827
            ypos = button -> gx_widget_size.gx_rectangle_bottom -
138
1827
                button -> gx_widget_size.gx_rectangle_top -
139
1827
                map -> gx_pixelmap_height + 1;
140
141
1827
            ypos /= 2;
142
1827
            ypos += button -> gx_widget_size.gx_rectangle_top;
143
1827
            break;
144
145
2
        case GX_STYLE_VALIGN_BOTTOM:
146
2
            ypos = button -> gx_widget_size.gx_rectangle_bottom - map -> gx_pixelmap_height + 1;
147
2
            break;
148
149
6687
        default:
150
6687
            ypos = button -> gx_widget_size.gx_rectangle_top;
151
6687
            break;
152
        }
153
8516
        _gx_widget_context_fill_set(widget);
154
8516
        _gx_canvas_pixelmap_draw((GX_VALUE)xpos, (GX_VALUE)ypos, map);
155
    }
156
    else
157
    {
158
        /* If I don't have a pixelmap and not transparent,
159
           draw something
160
         */
161
28
        if (!(widget -> gx_widget_style & GX_STYLE_TRANSPARENT))
162
        {
163
23
            _gx_button_draw((GX_BUTTON *)button);
164
        }
165
    }
166
167
    /* Draw button's children.  */
168
8544
    _gx_widget_children_draw(widget);
169
8544
}
170