GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_circular_gauge_needle_rectangle_calculate.c Lines: 33 33 100.0 %
Date: 2026-03-06 19:21:09 Branches: 4 4 100.0 %

Line Branch Exec Source
1
/***************************************************************************
2
 * Copyright (c) 2024 Microsoft Corporation
3
 * Copyright (c) 2026-present Eclipse ThreadX contributors
4
 *
5
 * This program and the accompanying materials are made available under the
6
 * terms of the MIT License which is available at
7
 * https://opensource.org/licenses/MIT.
8
 *
9
 * SPDX-License-Identifier: MIT
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_utility.h"
29
#include "gx_circular_gauge.h"
30
31
32
/**************************************************************************/
33
/*                                                                        */
34
/*  FUNCTION                                               RELEASE        */
35
/*                                                                        */
36
/*    _gx_circular_gauge_needle_rectangle_calculate       PORTABLE C      */
37
/*                                                           6.1.10       */
38
/*  AUTHOR                                                                */
39
/*                                                                        */
40
/*    Kenneth Maxwell, Microsoft Corporation                              */
41
/*                                                                        */
42
/*  DESCRIPTION                                                           */
43
/*                                                                        */
44
/*    This function calculates needle rectangle.                          */
45
/*                                                                        */
46
/*  INPUT                                                                 */
47
/*                                                                        */
48
/*    circular_gauge                        Circular gauge control block  */
49
/*    angle                                 The rotation angle            */
50
/*    rect                                  return rectangle pointer      */
51
/*                                                                        */
52
/*  OUTPUT                                                                */
53
/*                                                                        */
54
/*    status                                Completion status             */
55
/*                                                                        */
56
/*  CALLS                                                                 */
57
/*                                                                        */
58
/*    _gx_utility_math_sin                  Compute sin value             */
59
/*    _gx_utility_math_cos                  Compute cos value             */
60
/*                                                                        */
61
/*                                                                        */
62
/*  CALLED BY                                                             */
63
/*                                                                        */
64
/*    Application Code                                                    */
65
/*                                                                        */
66
/**************************************************************************/
67
1769
UINT  _gx_circular_gauge_needle_rectangle_calculate(GX_CIRCULAR_GAUGE *gauge, INT angle, GX_RECTANGLE *rect)
68
{
69
GX_CIRCULAR_GAUGE_INFO *info;
70
1769
INT                    mx[4] = { -1, 1, 1, -1 };
71
1769
INT                    my[4] = { 1, 1, -1, -1 };
72
INT                    idxminx;
73
INT                    idxmaxx;
74
INT                    idxmaxy;
75
GX_PIXELMAP            *needle_map;
76
INT                    srcxres;
77
INT                    srcyres;
78
INT                    cosv;
79
INT                    sinv;
80
INT                    xres;
81
INT                    yres;
82
INT                    width;
83
INT                    height;
84
INT                    rot_cx;
85
INT                    rot_cy;
86
INT                    x;
87
INT                    y;
88
89
    /* Pick up needle pixelmap.  */
90
1769
    needle_map = gauge -> gx_circular_gauge_needle_source;
91
92
1769
    if (needle_map == GX_NULL)
93
    {
94
38
        return GX_FAILURE;
95
    }
96
97
1731
    info = &gauge -> gx_circular_gauge_info;
98
99
2408
    while (angle < 0)
100
    {
101
677
        angle += 360;
102
    }
103
104
1731
    idxminx = (angle / 90) & 0x3;
105
1731
    idxmaxx = (idxminx + 2) & 0x3;
106
1731
    idxmaxy = (idxminx + 1) & 0x3;
107
108
    /* Calculate the source x and y center. */
109
1731
    srcxres = needle_map -> gx_pixelmap_width >> 1;
110
1731
    srcyres = needle_map -> gx_pixelmap_height >> 1;
111
112
1731
    cosv = _gx_utility_math_cos(GX_FIXED_VAL_MAKE(angle));
113
1731
    sinv = _gx_utility_math_sin(GX_FIXED_VAL_MAKE(angle));
114
115
1731
    xres = GX_FIXED_VAL_TO_INT(mx[idxmaxx] * (srcxres + 2) * cosv - my[idxmaxx] * (srcyres + 2) * sinv);
116
1731
    yres = GX_FIXED_VAL_TO_INT(my[idxmaxy] * (srcyres + 2) * cosv + mx[idxmaxy] * (srcxres + 2) * sinv);
117
118
    /* Calculate destination width and height. */
119
1731
    width = (xres << 1);
120
1731
    height = (yres << 1);
121
122
1731
    rot_cx = info -> gx_circular_gauge_info_needle_xcor;
123
1731
    rot_cy = info -> gx_circular_gauge_info_needle_ycor;
124
125
    /* Calculate the new rotation axis. */
126
1731
    x = (rot_cx - srcxres) * cosv - (rot_cy - srcyres) * sinv;
127
1731
    y = (rot_cy - srcyres) * cosv + (rot_cx - srcxres) * sinv;
128
129
1731
    x = GX_FIXED_VAL_TO_INT(x) + xres;
130
1731
    y = GX_FIXED_VAL_TO_INT(y) + yres;
131
132
    /* Calculate new needle rectangle */
133
1731
    rect -> gx_rectangle_left = (GX_VALUE)(gauge -> gx_widget_size.gx_rectangle_left +
134
1731
                                           info -> gx_circular_gauge_info_needle_xpos - x);
135
136
1731
    rect -> gx_rectangle_top = (GX_VALUE)(gauge -> gx_widget_size.gx_rectangle_top +
137
1731
                                          info -> gx_circular_gauge_info_needle_ypos - y);
138
139
1731
    rect -> gx_rectangle_right = (GX_VALUE)(rect -> gx_rectangle_left + width);
140
1731
    rect -> gx_rectangle_bottom = (GX_VALUE)(rect -> gx_rectangle_top + height);
141
142
    /* Mark the combine area as dirty.  */
143
1731
    return(GX_SUCCESS);
144
}
145