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