GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_circular_gauge_background_draw.c Lines: 31 31 100.0 %
Date: 2024-12-05 08:52:37 Branches: 16 16 100.0 %

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

1727
    if ((map != GX_NULL) && (map -> gx_pixelmap_data != GX_NULL))
143
    {
144
        /* Draw needle .  */
145
1711
        _gx_canvas_pixelmap_draw((GX_VALUE)gauge -> gx_circular_gauge_current_needle_x,
146
1711
                                 (GX_VALUE)gauge -> gx_circular_gauge_current_needle_y,
147
                                 map);
148
149
        /* Free rotate needle pixelmap memory.  */
150

1711
        if (_gx_system_memory_free && free_mem)
151
        {
152
1644
            if (map -> gx_pixelmap_aux_data)
153
            {
154
16
                _gx_system_memory_free((VOID *)map -> gx_pixelmap_aux_data);
155
16
                map -> gx_pixelmap_aux_data = GX_NULL;
156
            }
157
1644
            _gx_system_memory_free((VOID *)map -> gx_pixelmap_data);
158
1644
            map -> gx_pixelmap_data = GX_NULL;
159
        }
160
    }
161
1727
}
162