1 /**************************************************************************/
2 /*                                                                        */
3 /*       Copyright (c) Microsoft Corporation. All rights reserved.        */
4 /*                                                                        */
5 /*       This software is licensed under the Microsoft Software License   */
6 /*       Terms for Microsoft Azure RTOS. Full text of the license can be  */
7 /*       found in the LICENSE file at https://aka.ms/AzureRTOS_EULA       */
8 /*       and in the root directory of this software.                      */
9 /*                                                                        */
10 /**************************************************************************/
11 
12 
13 /**************************************************************************/
14 /**************************************************************************/
15 /**                                                                       */
16 /** GUIX Component                                                        */
17 /**                                                                       */
18 /**   Circular Gauge Management (Circular Gauge)                          */
19 /**                                                                       */
20 /**************************************************************************/
21 
22 #define GX_SOURCE_CODE
23 
24 
25 /* Include necessary system files.  */
26 
27 #include "gx_api.h"
28 #include "gx_widget.h"
29 #include "gx_icon.h"
30 #include "gx_system.h"
31 #include "gx_utility.h"
32 #include "gx_circular_gauge.h"
33 
34 
35 /**************************************************************************/
36 /*                                                                        */
37 /*  FUNCTION                                               RELEASE        */
38 /*                                                                        */
39 /*    _gx_circular_gauge_event_process                    PORTABLE C      */
40 /*                                                           6.1.10       */
41 /*  AUTHOR                                                                */
42 /*                                                                        */
43 /*    Kenneth Maxwell, Microsoft Corporation                              */
44 /*                                                                        */
45 /*  DESCRIPTION                                                           */
46 /*                                                                        */
47 /*    This function processes events for the specified circular gauge     */
48 /*    widget.                                                             */
49 /*                                                                        */
50 /*  INPUT                                                                 */
51 /*                                                                        */
52 /*    circular_gauge                        Circular gauge control block  */
53 /*    event_ptr                             Pointer to event to process   */
54 /*                                                                        */
55 /*  OUTPUT                                                                */
56 /*                                                                        */
57 /*    status                                Completion status             */
58 /*                                                                        */
59 /*  CALLS                                                                 */
60 /*                                                                        */
61 /*    _gx_circular_gauge_info_get           Retrieve the circular gauge   */
62 /*                                            information structure.      */
63 /*    _gx_circular_gauge_info_set           Set the circular gauge info.  */
64 /*    _gx_widget_event_process              Process event for specified   */
65 /*                                            widget.                     */
66 /*    _gx_widget_pixelmap_get               Get needle pixelmap.          */
67 /*    _gx_circular_gauge_needle_rectangle_calculate                       */
68 /*                                          Calculate current needle      */
69 /*                                            rectangle.                  */
70 /*                                                                        */
71 /*  CALLED BY                                                             */
72 /*                                                                        */
73 /*    Application Code                                                    */
74 /*                                                                        */
75 /*  RELEASE HISTORY                                                       */
76 /*                                                                        */
77 /*    DATE              NAME                      DESCRIPTION             */
78 /*                                                                        */
79 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
80 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
81 /*                                            resulting in version 6.1    */
82 /*  01-31-2022     Ting Zhu                 Modified comment(s), improved */
83 /*                                            logic to recalculate needle */
84 /*                                            rectangle on resize event,  */
85 /*                                            resulting in version 6.1.10 */
86 /*                                                                        */
87 /**************************************************************************/
_gx_circular_gauge_event_process(GX_CIRCULAR_GAUGE * gauge,GX_EVENT * event_ptr)88 UINT  _gx_circular_gauge_event_process(GX_CIRCULAR_GAUGE *gauge, GX_EVENT *event_ptr)
89 {
90 UINT status = GX_SUCCESS;
91 
92     switch (event_ptr -> gx_event_type)
93     {
94     case GX_EVENT_SHOW:
95         status = _gx_icon_event_process((GX_ICON *)gauge, event_ptr);
96 
97         /* Needle source being GX_NULL indicates it's the first time to show. So initialize the needle rectangle. */
98         if (gauge -> gx_circular_gauge_needle_source == GX_NULL)
99         {
100             _gx_widget_pixelmap_get((GX_WIDGET *)gauge, gauge -> gx_circular_gauge_info.gx_circular_gauge_info_needle_pixelmap, &(gauge -> gx_circular_gauge_needle_source));
101             _gx_circular_gauge_needle_rectangle_calculate(gauge, gauge -> gx_circular_gauge_current_angle, &(gauge -> gx_circular_gauge_current_needle_rectangle));
102         }
103 
104         /* Calculate needle increment angle, if any.  */
105         _gx_circular_gauge_angle_increment_calculate(gauge);
106         break;
107 
108     case GX_EVENT_HIDE:
109         if (gauge -> gx_circular_gauge_info.gx_circular_gauge_info_animation_steps > 0)
110         {
111             /* Stop needle animation timer. */
112             _gx_system_timer_stop((GX_WIDGET *)gauge, GX_CIRCULAR_GAUGE_TIMER);
113         }
114         status = _gx_icon_event_process((GX_ICON *)gauge, event_ptr);
115         break;
116 
117     case GX_EVENT_TIMER:
118         if (event_ptr -> gx_event_payload.gx_event_timer_id == GX_CIRCULAR_GAUGE_TIMER)
119         {
120 
121             /* Calculate current angle.  */
122             gauge -> gx_circular_gauge_animation_step++;
123 
124             if (gauge -> gx_circular_gauge_animation_step < gauge -> gx_circular_gauge_info.gx_circular_gauge_info_animation_steps)
125             {
126                 gauge -> gx_circular_gauge_current_angle = gauge -> gx_circular_gauge_start_angle;
127                 gauge -> gx_circular_gauge_current_angle += GX_FIXED_VAL_TO_INT(gauge -> gx_circular_gauge_angle_increment *
128                                                              gauge -> gx_circular_gauge_animation_step);
129             }
130             else
131             {
132                 gauge -> gx_circular_gauge_current_angle = gauge -> gx_circular_gauge_target_angle;
133 
134                 /* Stop timer. */
135                 _gx_system_timer_stop((GX_WIDGET *)gauge, GX_CIRCULAR_GAUGE_TIMER);
136                 gauge -> gx_circular_gauge_animation_step = 0;
137 
138                 /* Inform the parent that the gauge animation is completed.  */
139                 _gx_widget_event_generate((GX_WIDGET *)gauge, GX_EVENT_ANIMATION_COMPLETE, 0);
140             }
141             _gx_circular_gauge_needle_dirty_mark(gauge);
142         }
143         else
144         {
145             status = _gx_widget_event_process((GX_WIDGET *)gauge, event_ptr);
146         }
147         break;
148 
149     case GX_EVENT_RESIZED:
150 
151         /* Recalculate needle rectangle. */
152         _gx_circular_gauge_needle_rectangle_calculate(gauge, gauge -> gx_circular_gauge_current_angle, &(gauge -> gx_circular_gauge_current_needle_rectangle));
153         break;
154 
155     default:
156 
157         status = _gx_icon_event_process((GX_ICON *)gauge, event_ptr);
158     }
159 
160     return status;
161 }
162 
163