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_window.h"
31 #include "gx_system.h"
32 #include "gx_circular_gauge.h"
33 
34 
35 /**************************************************************************/
36 /*                                                                        */
37 /*  FUNCTION                                               RELEASE        */
38 /*                                                                        */
39 /*    _gx_circular_gauge_create                           PORTABLE C      */
40 /*                                                           6.1.10       */
41 /*  AUTHOR                                                                */
42 /*                                                                        */
43 /*    Kenneth Maxwell, Microsoft Corporation                              */
44 /*                                                                        */
45 /*  DESCRIPTION                                                           */
46 /*                                                                        */
47 /*    This functon creates a circular gauge with the specified properties.*/
48 /*                                                                        */
49 /*  INPUT                                                                 */
50 /*                                                                        */
51 /*    gauge                                 Pointer to circular gauge     */
52 /*                                            control block               */
53 /*    name                                  Logical name of circular gauge*/
54 /*                                            widget                      */
55 /*    parent                                Pointer to the parent widget  */
56 /*    info                                  Pointer to                    */
57 /*                                            GX_CIRCULAR_GAUGE_INFO      */
58 /*                                            structure                   */
59 /*    style                                 Style of circular gauge.      */
60 /*    circular_gauge_id                     Application-defined ID of     */
61 /*                                            circular gauge              */
62 /*    xpos                                  Gauge x-coordinate position   */
63 /*    ypos                                  Gauge y-coordinate position   */
64 /*                                                                        */
65 /*  OUTPUT                                                                */
66 /*                                                                        */
67 /*    status                                Completion status             */
68 /*                                                                        */
69 /*  CALLS                                                                 */
70 /*                                                                        */
71 /*    _gx_widget_create                     Creates a widget.             */
72 /*    _gx_widget_link                       Links a child widget to its   */
73 /*                                            parent.                     */
74 /*    _gx_circular_gauge_angle_increment_calculate                        */
75 /*                                          Calculate increment angle for */
76 /*                                            each step.                  */
77 /*                                                                        */
78 /*  CALLED BY                                                             */
79 /*                                                                        */
80 /*    Application Code                                                    */
81 /*                                                                        */
82 /*  RELEASE HISTORY                                                       */
83 /*                                                                        */
84 /*    DATE              NAME                      DESCRIPTION             */
85 /*                                                                        */
86 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
87 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
88 /*                                            resulting in version 6.1    */
89 /*  01-31-2022     Ting Zhu                 Modified comment(s),          */
90 /*                                            added resize notify status, */
91 /*                                            resulting in version 6.1.10 */
92 /*                                                                        */
93 /**************************************************************************/
_gx_circular_gauge_create(GX_CIRCULAR_GAUGE * gauge,GX_CONST GX_CHAR * name,GX_WIDGET * parent,GX_CIRCULAR_GAUGE_INFO * info,GX_RESOURCE_ID background_id,ULONG style,USHORT circular_gauge_id,GX_VALUE xpos,GX_VALUE ypos)94 UINT  _gx_circular_gauge_create(GX_CIRCULAR_GAUGE *gauge,
95                                 GX_CONST GX_CHAR *name,
96                                 GX_WIDGET *parent,
97                                 GX_CIRCULAR_GAUGE_INFO *info,
98                                 GX_RESOURCE_ID background_id,
99                                 ULONG style,
100                                 USHORT circular_gauge_id,
101                                 GX_VALUE xpos, GX_VALUE ypos)
102 {
103     /* Call the widget create function.  */
104     _gx_icon_create((GX_ICON *)gauge, name, GX_NULL, background_id, style, circular_gauge_id, xpos, ypos);
105 
106     /* Populate the rest of gauge control block - overriding as necessary.  */
107     gauge -> gx_widget_type = GX_TYPE_CIRCULAR_GAUGE;
108 
109     gauge -> gx_circular_gauge_info = *info;
110 
111     if (gauge -> gx_circular_gauge_info.gx_circular_gauge_info_animation_delay <= 0)
112     {
113         gauge -> gx_circular_gauge_info.gx_circular_gauge_info_animation_delay = GX_DEFAULT_CIRCULAR_GAUGE_ANIMATION_DELAY;
114     }
115 
116     gauge -> gx_widget_draw_function = (VOID (*)(GX_WIDGET *))_gx_circular_gauge_draw;
117     gauge -> gx_widget_event_process_function = (UINT (*)(GX_WIDGET *, GX_EVENT *))_gx_circular_gauge_event_process;
118 
119     /* Initiate rotate needle pixelmap.  */
120     memset(&gauge -> gx_circular_gauge_needle_rotated, 0, sizeof(GX_PIXELMAP));
121     gauge -> gx_circular_gauge_needle_source = GX_NULL;
122     gauge -> gx_circular_gauge_start_angle = 0;
123     gauge -> gx_circular_gauge_current_angle = 0;
124     gauge -> gx_circular_gauge_target_angle = 0;
125     gauge -> gx_widget_status |= GX_STATUS_RESIZE_NOTIFY;
126 
127     /* Determine if a parent widget was provided.  */
128     if (parent)
129     {
130         _gx_widget_link(parent, (GX_WIDGET *)gauge);
131     }
132 
133     /* Return completion status. */
134     return(GX_SUCCESS);
135 }
136 
137