GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_icon_button_draw.c Lines: 41 41 100.0 %
Date: 2026-03-06 19:21:09 Branches: 10 10 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_icon_button_draw                                PORTABLE C      */
40
/*                                                           6.1.9        */
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                                Icon button control block     */
53
/*                                                                        */
54
/*  OUTPUT                                                                */
55
/*                                                                        */
56
/*    None                                                                */
57
/*                                                                        */
58
/*  CALLS                                                                 */
59
/*                                                                        */
60
/*    _gx_button_background_draw            Draw the button background    */
61
/*    _gx_context_pixelmap_get              Retrieve pixelmap image       */
62
/*    _gx_widget_border_width_get           Get the border width          */
63
/*    _gx_canvas_pixelmap_draw              Draw the pixelmap             */
64
/*    _gx_widget_children_draw              Draw children widgets         */
65
/*                                                                        */
66
/*  CALLED BY                                                             */
67
/*                                                                        */
68
/*    Application Code                                                    */
69
/*    GUIX Internal Code                                                  */
70
/*                                                                        */
71
/**************************************************************************/
72
23181
VOID  _gx_icon_button_draw(GX_ICON_BUTTON *button)
73
{
74
GX_WIDGET   *widget;
75
GX_PIXELMAP *map;
76
GX_VALUE     xpos;
77
GX_VALUE     ypos;
78
GX_VALUE     border;
79
23181
INT          shift = 0;
80
81
    /* Setup the widget.  */
82
23181
    widget =  (GX_WIDGET *)button;
83
84
    /* draw the background button */
85
23181
    _gx_button_background_draw((GX_BUTTON *)button);
86
87
    /* draw the button icon */
88
23181
    _gx_context_pixelmap_get(button -> gx_icon_button_icon_id, &map);
89
90
23181
    if (map)
91
    {
92
22160
        _gx_widget_border_width_get(widget, &border);
93
94
22160
        if (widget -> gx_widget_style & GX_STYLE_BUTTON_PUSHED)
95
        {
96
41
            shift = 1;
97
        }
98
99
22160
        switch (widget -> gx_widget_style & GX_PIXELMAP_HALIGN_MASK)
100
        {
101
22144
        case GX_STYLE_HALIGN_CENTER:
102
22144
            xpos = (GX_VALUE)(widget -> gx_widget_size.gx_rectangle_right -
103
22144
                              widget -> gx_widget_size.gx_rectangle_left -
104
22144
                              map -> gx_pixelmap_width + 1);
105
106
22144
            xpos /= 2;
107
22144
            xpos = (GX_VALUE)(xpos + widget -> gx_widget_size.gx_rectangle_left + shift);
108
22144
            break;
109
110
2
        case GX_STYLE_HALIGN_RIGHT:
111
2
            xpos = (GX_VALUE)(widget -> gx_widget_size.gx_rectangle_right - map -> gx_pixelmap_width - border + shift + 1);
112
2
            break;
113
114
14
        default:
115
14
            xpos = (GX_VALUE)(widget -> gx_widget_size.gx_rectangle_left + border + shift);
116
14
            break;
117
        }
118
119
22160
        switch (widget -> gx_widget_style & GX_PIXELMAP_VALIGN_MASK)
120
        {
121
22153
        case GX_STYLE_VALIGN_CENTER:
122
22153
            ypos = (GX_VALUE)(widget -> gx_widget_size.gx_rectangle_bottom -
123
22153
                              widget -> gx_widget_size.gx_rectangle_top -
124
22153
                              map -> gx_pixelmap_height + 1);
125
126
22153
            ypos /= 2;
127
22153
            ypos = (GX_VALUE)(ypos + widget -> gx_widget_size.gx_rectangle_top + shift);
128
22153
            break;
129
130
2
        case GX_STYLE_VALIGN_BOTTOM:
131
2
            ypos = (GX_VALUE)(widget -> gx_widget_size.gx_rectangle_bottom - map -> gx_pixelmap_height - border + shift + 1);
132
2
            break;
133
134
5
        default:
135
5
            ypos = (GX_VALUE)(widget -> gx_widget_size.gx_rectangle_top + border + shift);
136
5
            break;
137
        }
138
22160
        _gx_widget_context_fill_set(widget);
139
22160
        _gx_canvas_pixelmap_draw(xpos, ypos, map);
140
    }
141
142
143
    /* Draw button's children.  */
144
23181
    _gx_widget_children_draw(widget);
145
23181
}
146