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 /**************************************************************************/
_gx_circular_gauge_event_process(GX_CIRCULAR_GAUGE * gauge,GX_EVENT * event_ptr)87 UINT _gx_circular_gauge_event_process(GX_CIRCULAR_GAUGE *gauge, GX_EVENT *event_ptr)
88 {
89 UINT status = GX_SUCCESS;
90
91 switch (event_ptr -> gx_event_type)
92 {
93 case GX_EVENT_SHOW:
94 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 if (gauge -> gx_circular_gauge_needle_source == GX_NULL)
98 {
99 _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 _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 _gx_circular_gauge_angle_increment_calculate(gauge);
105 break;
106
107 case GX_EVENT_HIDE:
108 if (gauge -> gx_circular_gauge_info.gx_circular_gauge_info_animation_steps > 0)
109 {
110 /* Stop needle animation timer. */
111 _gx_system_timer_stop((GX_WIDGET *)gauge, GX_CIRCULAR_GAUGE_TIMER);
112 }
113 status = _gx_icon_event_process((GX_ICON *)gauge, event_ptr);
114 break;
115
116 case GX_EVENT_TIMER:
117 if (event_ptr -> gx_event_payload.gx_event_timer_id == GX_CIRCULAR_GAUGE_TIMER)
118 {
119
120 /* Calculate current angle. */
121 gauge -> gx_circular_gauge_animation_step++;
122
123 if (gauge -> gx_circular_gauge_animation_step < gauge -> gx_circular_gauge_info.gx_circular_gauge_info_animation_steps)
124 {
125 gauge -> gx_circular_gauge_current_angle = gauge -> gx_circular_gauge_start_angle;
126 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 gauge -> gx_circular_gauge_current_angle = gauge -> gx_circular_gauge_target_angle;
132
133 /* Stop timer. */
134 _gx_system_timer_stop((GX_WIDGET *)gauge, GX_CIRCULAR_GAUGE_TIMER);
135 gauge -> gx_circular_gauge_animation_step = 0;
136
137 /* Inform the parent that the gauge animation is completed. */
138 _gx_widget_event_generate((GX_WIDGET *)gauge, GX_EVENT_ANIMATION_COMPLETE, 0);
139 }
140 _gx_circular_gauge_needle_dirty_mark(gauge);
141 }
142 else
143 {
144 status = _gx_widget_event_process((GX_WIDGET *)gauge, event_ptr);
145 }
146 break;
147
148 case GX_EVENT_RESIZED:
149
150 /* Recalculate needle rectangle. */
151 _gx_circular_gauge_needle_rectangle_calculate(gauge, gauge -> gx_circular_gauge_current_angle, &(gauge -> gx_circular_gauge_current_needle_rectangle));
152 break;
153
154 default:
155
156 status = _gx_icon_event_process((GX_ICON *)gauge, event_ptr);
157 }
158
159 return status;
160 }
161
162