GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_circular_gauge_needle_rectangle_calculate.c Lines: 33 33 100.0 %
Date: 2024-12-05 08:52:37 Branches: 4 4 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_utility.h"
28
#include "gx_circular_gauge.h"
29
30
31
/**************************************************************************/
32
/*                                                                        */
33
/*  FUNCTION                                               RELEASE        */
34
/*                                                                        */
35
/*    _gx_circular_gauge_needle_rectangle_calculate       PORTABLE C      */
36
/*                                                           6.1.10       */
37
/*  AUTHOR                                                                */
38
/*                                                                        */
39
/*    Kenneth Maxwell, Microsoft Corporation                              */
40
/*                                                                        */
41
/*  DESCRIPTION                                                           */
42
/*                                                                        */
43
/*    This function calculates needle rectangle.                          */
44
/*                                                                        */
45
/*  INPUT                                                                 */
46
/*                                                                        */
47
/*    circular_gauge                        Circular gauge control block  */
48
/*    angle                                 The rotation angle            */
49
/*    rect                                  return rectangle pointer      */
50
/*                                                                        */
51
/*  OUTPUT                                                                */
52
/*                                                                        */
53
/*    status                                Completion status             */
54
/*                                                                        */
55
/*  CALLS                                                                 */
56
/*                                                                        */
57
/*    _gx_utility_math_sin                  Compute sin value             */
58
/*    _gx_utility_math_cos                  Compute cos value             */
59
/*                                                                        */
60
/*                                                                        */
61
/*  CALLED BY                                                             */
62
/*                                                                        */
63
/*    Application Code                                                    */
64
/*                                                                        */
65
/*  RELEASE HISTORY                                                       */
66
/*                                                                        */
67
/*    DATE              NAME                      DESCRIPTION             */
68
/*                                                                        */
69
/*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
70
/*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
71
/*                                            resulting in version 6.1    */
72
/*  01-31-2022     Kenneth Maxwell          Modified comment(s),          */
73
/*                                            corrected logic,            */
74
/*                                            resulting in version 6.1.10 */
75
/*                                                                        */
76
/**************************************************************************/
77
1769
UINT  _gx_circular_gauge_needle_rectangle_calculate(GX_CIRCULAR_GAUGE *gauge, INT angle, GX_RECTANGLE *rect)
78
{
79
GX_CIRCULAR_GAUGE_INFO *info;
80
1769
INT                    mx[4] = { -1, 1, 1, -1 };
81
1769
INT                    my[4] = { 1, 1, -1, -1 };
82
INT                    idxminx;
83
INT                    idxmaxx;
84
INT                    idxmaxy;
85
GX_PIXELMAP            *needle_map;
86
INT                    srcxres;
87
INT                    srcyres;
88
INT                    cosv;
89
INT                    sinv;
90
INT                    xres;
91
INT                    yres;
92
INT                    width;
93
INT                    height;
94
INT                    rot_cx;
95
INT                    rot_cy;
96
INT                    x;
97
INT                    y;
98
99
    /* Pick up needle pixelmap.  */
100
1769
    needle_map = gauge -> gx_circular_gauge_needle_source;
101
102
1769
    if (needle_map == GX_NULL)
103
    {
104
38
        return GX_FAILURE;
105
    }
106
107
1731
    info = &gauge -> gx_circular_gauge_info;
108
109
2408
    while (angle < 0)
110
    {
111
677
        angle += 360;
112
    }
113
114
1731
    idxminx = (angle / 90) & 0x3;
115
1731
    idxmaxx = (idxminx + 2) & 0x3;
116
1731
    idxmaxy = (idxminx + 1) & 0x3;
117
118
    /* Calculate the source x and y center. */
119
1731
    srcxres = needle_map -> gx_pixelmap_width >> 1;
120
1731
    srcyres = needle_map -> gx_pixelmap_height >> 1;
121
122
1731
    cosv = _gx_utility_math_cos(GX_FIXED_VAL_MAKE(angle));
123
1731
    sinv = _gx_utility_math_sin(GX_FIXED_VAL_MAKE(angle));
124
125
1731
    xres = GX_FIXED_VAL_TO_INT(mx[idxmaxx] * (srcxres + 2) * cosv - my[idxmaxx] * (srcyres + 2) * sinv);
126
1731
    yres = GX_FIXED_VAL_TO_INT(my[idxmaxy] * (srcyres + 2) * cosv + mx[idxmaxy] * (srcxres + 2) * sinv);
127
128
    /* Calculate destination width and height. */
129
1731
    width = (xres << 1);
130
1731
    height = (yres << 1);
131
132
1731
    rot_cx = info -> gx_circular_gauge_info_needle_xcor;
133
1731
    rot_cy = info -> gx_circular_gauge_info_needle_ycor;
134
135
    /* Calculate the new rotation axis. */
136
1731
    x = (rot_cx - srcxres) * cosv - (rot_cy - srcyres) * sinv;
137
1731
    y = (rot_cy - srcyres) * cosv + (rot_cx - srcxres) * sinv;
138
139
1731
    x = GX_FIXED_VAL_TO_INT(x) + xres;
140
1731
    y = GX_FIXED_VAL_TO_INT(y) + yres;
141
142
    /* Calculate new needle rectangle */
143
1731
    rect -> gx_rectangle_left = (GX_VALUE)(gauge -> gx_widget_size.gx_rectangle_left +
144
1731
                                           info -> gx_circular_gauge_info_needle_xpos - x);
145
146
1731
    rect -> gx_rectangle_top = (GX_VALUE)(gauge -> gx_widget_size.gx_rectangle_top +
147
1731
                                          info -> gx_circular_gauge_info_needle_ypos - y);
148
149
1731
    rect -> gx_rectangle_right = (GX_VALUE)(rect -> gx_rectangle_left + width);
150
1731
    rect -> gx_rectangle_bottom = (GX_VALUE)(rect -> gx_rectangle_top + height);
151
152
    /* Mark the combine area as dirty.  */
153
1731
    return(GX_SUCCESS);
154
}
155