GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_icon_button_draw.c Lines: 41 41 100.0 %
Date: 2024-12-05 08:52:37 Branches: 10 10 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
/*                                                                        */
36
/*  FUNCTION                                               RELEASE        */
37
/*                                                                        */
38
/*    _gx_icon_button_draw                                PORTABLE C      */
39
/*                                                           6.1.9        */
40
/*  AUTHOR                                                                */
41
/*                                                                        */
42
/*    Kenneth Maxwell, Microsoft Corporation                              */
43
/*                                                                        */
44
/*  DESCRIPTION                                                           */
45
/*                                                                        */
46
/*    This function draws the specified button, which is a special type   */
47
/*    of widget.                                                          */
48
/*                                                                        */
49
/*  INPUT                                                                 */
50
/*                                                                        */
51
/*    button                                Icon button control block     */
52
/*                                                                        */
53
/*  OUTPUT                                                                */
54
/*                                                                        */
55
/*    None                                                                */
56
/*                                                                        */
57
/*  CALLS                                                                 */
58
/*                                                                        */
59
/*    _gx_button_background_draw            Draw the button background    */
60
/*    _gx_context_pixelmap_get              Retrieve pixelmap image       */
61
/*    _gx_widget_border_width_get           Get the border width          */
62
/*    _gx_canvas_pixelmap_draw              Draw the pixelmap             */
63
/*    _gx_widget_children_draw              Draw children widgets         */
64
/*                                                                        */
65
/*  CALLED BY                                                             */
66
/*                                                                        */
67
/*    Application Code                                                    */
68
/*    GUIX Internal Code                                                  */
69
/*                                                                        */
70
/*  RELEASE HISTORY                                                       */
71
/*                                                                        */
72
/*    DATE              NAME                      DESCRIPTION             */
73
/*                                                                        */
74
/*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
75
/*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
76
/*                                            resulting in version 6.1    */
77
/*  10-15-2021     Ting Zhu                 Modified comment(s),          */
78
/*                                            fixed pixelmap draw offset, */
79
/*                                            resulting in version 6.1.9  */
80
/*                                                                        */
81
/**************************************************************************/
82
23181
VOID  _gx_icon_button_draw(GX_ICON_BUTTON *button)
83
{
84
GX_WIDGET   *widget;
85
GX_PIXELMAP *map;
86
GX_VALUE     xpos;
87
GX_VALUE     ypos;
88
GX_VALUE     border;
89
23181
INT          shift = 0;
90
91
    /* Setup the widget.  */
92
23181
    widget =  (GX_WIDGET *)button;
93
94
    /* draw the background button */
95
23181
    _gx_button_background_draw((GX_BUTTON *)button);
96
97
    /* draw the button icon */
98
23181
    _gx_context_pixelmap_get(button -> gx_icon_button_icon_id, &map);
99
100
23181
    if (map)
101
    {
102
22160
        _gx_widget_border_width_get(widget, &border);
103
104
22160
        if (widget -> gx_widget_style & GX_STYLE_BUTTON_PUSHED)
105
        {
106
41
            shift = 1;
107
        }
108
109
22160
        switch (widget -> gx_widget_style & GX_PIXELMAP_HALIGN_MASK)
110
        {
111
22144
        case GX_STYLE_HALIGN_CENTER:
112
22144
            xpos = (GX_VALUE)(widget -> gx_widget_size.gx_rectangle_right -
113
22144
                              widget -> gx_widget_size.gx_rectangle_left -
114
22144
                              map -> gx_pixelmap_width + 1);
115
116
22144
            xpos /= 2;
117
22144
            xpos = (GX_VALUE)(xpos + widget -> gx_widget_size.gx_rectangle_left + shift);
118
22144
            break;
119
120
2
        case GX_STYLE_HALIGN_RIGHT:
121
2
            xpos = (GX_VALUE)(widget -> gx_widget_size.gx_rectangle_right - map -> gx_pixelmap_width - border + shift + 1);
122
2
            break;
123
124
14
        default:
125
14
            xpos = (GX_VALUE)(widget -> gx_widget_size.gx_rectangle_left + border + shift);
126
14
            break;
127
        }
128
129
22160
        switch (widget -> gx_widget_style & GX_PIXELMAP_VALIGN_MASK)
130
        {
131
22153
        case GX_STYLE_VALIGN_CENTER:
132
22153
            ypos = (GX_VALUE)(widget -> gx_widget_size.gx_rectangle_bottom -
133
22153
                              widget -> gx_widget_size.gx_rectangle_top -
134
22153
                              map -> gx_pixelmap_height + 1);
135
136
22153
            ypos /= 2;
137
22153
            ypos = (GX_VALUE)(ypos + widget -> gx_widget_size.gx_rectangle_top + shift);
138
22153
            break;
139
140
2
        case GX_STYLE_VALIGN_BOTTOM:
141
2
            ypos = (GX_VALUE)(widget -> gx_widget_size.gx_rectangle_bottom - map -> gx_pixelmap_height - border + shift + 1);
142
2
            break;
143
144
5
        default:
145
5
            ypos = (GX_VALUE)(widget -> gx_widget_size.gx_rectangle_top + border + shift);
146
5
            break;
147
        }
148
22160
        _gx_widget_context_fill_set(widget);
149
22160
        _gx_canvas_pixelmap_draw(xpos, ypos, map);
150
    }
151
152
153
    /* Draw button's children.  */
154
23181
    _gx_widget_children_draw(widget);
155
23181
}
156