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_icon.h"
29 #include "gx_system.h"
30 #include "gx_context.h"
31 #include "gx_canvas.h"
32 #include "gx_circular_gauge.h"
33 
34 
35 /**************************************************************************/
36 /*                                                                        */
37 /*  FUNCTION                                               RELEASE        */
38 /*                                                                        */
39 /*    _gx_circular_gauge_background_draw                  PORTABLE C      */
40 /*                                                           6.1.9        */
41 /*  AUTHOR                                                                */
42 /*                                                                        */
43 /*    Kenneth Maxwell, Microsoft Corporation                              */
44 /*                                                                        */
45 /*  DESCRIPTION                                                           */
46 /*                                                                        */
47 /*    This function draws background of the specified circular gauge.     */
48 /*                                                                        */
49 /*  INPUT                                                                 */
50 /*                                                                        */
51 /*    gauge                                 Pointer to circular gauge     */
52 /*                                            control block               */
53 /*                                                                        */
54 /*  OUTPUT                                                                */
55 /*                                                                        */
56 /*    None                                                                */
57 /*                                                                        */
58 /*  CALLS                                                                 */
59 /*                                                                        */
60 /*    _gx_icon_background_draw              Draw icon background          */
61 /*    _gx_context_pixelmap_get              Gets the pixelmap associated  */
62 /*                                            the supplied resource ID.   */
63 /*    _gx_circular_gauge_needle_rotate      Needle rotate function        */
64 /*    _gx_canvas_pixelmap_draw              Draw the specified pixelmap.  */
65 /*    _gx_system_memory_free                Free memory.                  */
66 /*    [gx_display_driver_callback_assign]   Assigns widget callback       */
67 /*                                            function                    */
68 /*    _gx_circular_gauge_needle_rotate_callback                           */
69 /*                                          Needle rotate callback        */
70 /*                                            function                    */
71 /*                                                                        */
72 /*  CALLED BY                                                             */
73 /*                                                                        */
74 /*    GUIX Internal Code                                                  */
75 /*                                                                        */
76 /*  RELEASE HISTORY                                                       */
77 /*                                                                        */
78 /*    DATE              NAME                      DESCRIPTION             */
79 /*                                                                        */
80 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
81 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
82 /*                                            resulting in version 6.1    */
83 /*  10-15-2021     Kenneth Maxwell          Modified comment(s),          */
84 /*                                            fixed the order of setting  */
85 /*                                            the display driver callback */
86 /*                                            and drawing the background, */
87 /*                                            resulting in version 6.1.9  */
88 /*                                                                        */
89 /**************************************************************************/
_gx_circular_gauge_background_draw(GX_CIRCULAR_GAUGE * gauge)90 VOID  _gx_circular_gauge_background_draw(GX_CIRCULAR_GAUGE *gauge)
91 {
92 GX_PIXELMAP            *map;
93 GX_CIRCULAR_GAUGE_INFO *info;
94 GX_DISPLAY             *display;
95 GX_BOOL                 free_mem;
96 
97 /* pickup pointer to current context */
98 GX_DRAW_CONTEXT *context = _gx_system_current_draw_context;
99 
100     display = context -> gx_draw_context_display;
101 
102 
103     /* Pick up gauge information.  */
104     info = &gauge -> gx_circular_gauge_info;
105     free_mem = GX_FALSE;
106 
107     if (gauge -> gx_circular_gauge_info.gx_circular_gauge_info_needle_pixelmap)
108     {
109         /* get pointer to needle source image */
110         _gx_context_pixelmap_get(gauge -> gx_circular_gauge_info.gx_circular_gauge_info_needle_pixelmap,
111                                  &gauge -> gx_circular_gauge_needle_source);
112     }
113 
114     if (gauge -> gx_circular_gauge_current_angle != 0)
115     {
116         if (display -> gx_display_driver_callback_assign)
117         {
118             /* rotate the needle while gauge background is being drawn */
119             display -> gx_display_driver_callback_assign(_gx_circular_gauge_needle_rotate_callback, gauge);
120         }
121         else
122         {
123             /* rotate the needle inline: */
124             _gx_circular_gauge_needle_rotate(gauge);
125         }
126         map = &gauge -> gx_circular_gauge_needle_rotated;
127         free_mem = GX_TRUE;
128     }
129     else
130     {
131         map = gauge -> gx_circular_gauge_needle_source;
132         gauge -> gx_circular_gauge_current_needle_x = gauge -> gx_widget_size.gx_rectangle_left +
133             info -> gx_circular_gauge_info_needle_xpos -
134             info -> gx_circular_gauge_info_needle_xcor;
135         gauge -> gx_circular_gauge_current_needle_y = gauge -> gx_widget_size.gx_rectangle_top +
136             info -> gx_circular_gauge_info_needle_ypos -
137             info -> gx_circular_gauge_info_needle_ycor;
138     }
139 
140     /* Call icon draw function to draw the background.  */
141     _gx_icon_background_draw((GX_ICON *)gauge);
142 
143     if ((map != GX_NULL) && (map -> gx_pixelmap_data != GX_NULL))
144     {
145         /* Draw needle .  */
146         _gx_canvas_pixelmap_draw((GX_VALUE)gauge -> gx_circular_gauge_current_needle_x,
147                                  (GX_VALUE)gauge -> gx_circular_gauge_current_needle_y,
148                                  map);
149 
150         /* Free rotate needle pixelmap memory.  */
151         if (_gx_system_memory_free && free_mem)
152         {
153             if (map -> gx_pixelmap_aux_data)
154             {
155                 _gx_system_memory_free((VOID *)map -> gx_pixelmap_aux_data);
156                 map -> gx_pixelmap_aux_data = GX_NULL;
157             }
158             _gx_system_memory_free((VOID *)map -> gx_pixelmap_data);
159             map -> gx_pixelmap_data = GX_NULL;
160         }
161     }
162 }
163 
164