GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_circular_gauge_event_process.c Lines: 34 34 100.0 %
Date: 2024-12-05 08:52:37 Branches: 13 13 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
/**   Circular Gauge Management (Circular Gauge)                          */
18
/**                                                                       */
19
/**************************************************************************/
20
21
#define GX_SOURCE_CODE
22
23
24
/* Include necessary system files.  */
25
26
#include "gx_api.h"
27
#include "gx_widget.h"
28
#include "gx_icon.h"
29
#include "gx_system.h"
30
#include "gx_utility.h"
31
#include "gx_circular_gauge.h"
32
33
34
/**************************************************************************/
35
/*                                                                        */
36
/*  FUNCTION                                               RELEASE        */
37
/*                                                                        */
38
/*    _gx_circular_gauge_event_process                    PORTABLE C      */
39
/*                                                           6.1.10       */
40
/*  AUTHOR                                                                */
41
/*                                                                        */
42
/*    Kenneth Maxwell, Microsoft Corporation                              */
43
/*                                                                        */
44
/*  DESCRIPTION                                                           */
45
/*                                                                        */
46
/*    This function processes events for the specified circular gauge     */
47
/*    widget.                                                             */
48
/*                                                                        */
49
/*  INPUT                                                                 */
50
/*                                                                        */
51
/*    circular_gauge                        Circular gauge control block  */
52
/*    event_ptr                             Pointer to event to process   */
53
/*                                                                        */
54
/*  OUTPUT                                                                */
55
/*                                                                        */
56
/*    status                                Completion status             */
57
/*                                                                        */
58
/*  CALLS                                                                 */
59
/*                                                                        */
60
/*    _gx_circular_gauge_info_get           Retrieve the circular gauge   */
61
/*                                            information structure.      */
62
/*    _gx_circular_gauge_info_set           Set the circular gauge info.  */
63
/*    _gx_widget_event_process              Process event for specified   */
64
/*                                            widget.                     */
65
/*    _gx_widget_pixelmap_get               Get needle pixelmap.          */
66
/*    _gx_circular_gauge_needle_rectangle_calculate                       */
67
/*                                          Calculate current needle      */
68
/*                                            rectangle.                  */
69
/*                                                                        */
70
/*  CALLED BY                                                             */
71
/*                                                                        */
72
/*    Application Code                                                    */
73
/*                                                                        */
74
/*  RELEASE HISTORY                                                       */
75
/*                                                                        */
76
/*    DATE              NAME                      DESCRIPTION             */
77
/*                                                                        */
78
/*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
79
/*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
80
/*                                            resulting in version 6.1    */
81
/*  01-31-2022     Ting Zhu                 Modified comment(s), improved */
82
/*                                            logic to recalculate needle */
83
/*                                            rectangle on resize event,  */
84
/*                                            resulting in version 6.1.10 */
85
/*                                                                        */
86
/**************************************************************************/
87
249
UINT  _gx_circular_gauge_event_process(GX_CIRCULAR_GAUGE *gauge, GX_EVENT *event_ptr)
88
{
89
249
UINT status = GX_SUCCESS;
90
91

249
    switch (event_ptr -> gx_event_type)
92
    {
93
40
    case GX_EVENT_SHOW:
94
40
        status = _gx_icon_event_process((GX_ICON *)gauge, event_ptr);
95
96
        /* Needle source being GX_NULL indicates it's the first time to show. So initialize the needle rectangle. */
97
40
        if (gauge -> gx_circular_gauge_needle_source == GX_NULL)
98
        {
99
38
            _gx_widget_pixelmap_get((GX_WIDGET *)gauge, gauge -> gx_circular_gauge_info.gx_circular_gauge_info_needle_pixelmap, &(gauge -> gx_circular_gauge_needle_source));
100
38
            _gx_circular_gauge_needle_rectangle_calculate(gauge, gauge -> gx_circular_gauge_current_angle, &(gauge -> gx_circular_gauge_current_needle_rectangle));
101
        }
102
103
        /* Calculate needle increment angle, if any.  */
104
40
        _gx_circular_gauge_angle_increment_calculate(gauge);
105
40
        break;
106
107
29
    case GX_EVENT_HIDE:
108
29
        if (gauge -> gx_circular_gauge_info.gx_circular_gauge_info_animation_steps > 0)
109
        {
110
            /* Stop needle animation timer. */
111
26
            _gx_system_timer_stop((GX_WIDGET *)gauge, GX_CIRCULAR_GAUGE_TIMER);
112
        }
113
29
        status = _gx_icon_event_process((GX_ICON *)gauge, event_ptr);
114
29
        break;
115
116
74
    case GX_EVENT_TIMER:
117
74
        if (event_ptr -> gx_event_payload.gx_event_timer_id == GX_CIRCULAR_GAUGE_TIMER)
118
        {
119
120
            /* Calculate current angle.  */
121
73
            gauge -> gx_circular_gauge_animation_step++;
122
123
73
            if (gauge -> gx_circular_gauge_animation_step < gauge -> gx_circular_gauge_info.gx_circular_gauge_info_animation_steps)
124
            {
125
71
                gauge -> gx_circular_gauge_current_angle = gauge -> gx_circular_gauge_start_angle;
126
71
                gauge -> gx_circular_gauge_current_angle += GX_FIXED_VAL_TO_INT(gauge -> gx_circular_gauge_angle_increment *
127
                                                             gauge -> gx_circular_gauge_animation_step);
128
            }
129
            else
130
            {
131
2
                gauge -> gx_circular_gauge_current_angle = gauge -> gx_circular_gauge_target_angle;
132
133
                /* Stop timer. */
134
2
                _gx_system_timer_stop((GX_WIDGET *)gauge, GX_CIRCULAR_GAUGE_TIMER);
135
2
                gauge -> gx_circular_gauge_animation_step = 0;
136
137
                /* Inform the parent that the gauge animation is completed.  */
138
2
                _gx_widget_event_generate((GX_WIDGET *)gauge, GX_EVENT_ANIMATION_COMPLETE, 0);
139
            }
140
73
            _gx_circular_gauge_needle_dirty_mark(gauge);
141
        }
142
        else
143
        {
144
1
            status = _gx_widget_event_process((GX_WIDGET *)gauge, event_ptr);
145
        }
146
74
        break;
147
148
37
    case GX_EVENT_RESIZED:
149
150
        /* Recalculate needle rectangle. */
151
37
        _gx_circular_gauge_needle_rectangle_calculate(gauge, gauge -> gx_circular_gauge_current_angle, &(gauge -> gx_circular_gauge_current_needle_rectangle));
152
37
        break;
153
154
69
    default:
155
156
69
        status = _gx_icon_event_process((GX_ICON *)gauge, event_ptr);
157
    }
158
159
249
    return status;
160
}
161