GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_radial_slider_needle_rectangle_calculate.c Lines: 19 19 100.0 %
Date: 2024-12-05 08:52:37 Branches: 2 2 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
/**   Radial Slider Management (Slider)                                   */
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_utility.h"
29
#include "gx_radial_slider.h"
30
31
/**************************************************************************/
32
/*                                                                        */
33
/*  FUNCTION                                               RELEASE        */
34
/*                                                                        */
35
/*    _gx_radial_slider_needle_rectangle_calculate        PORTABLE C      */
36
/*                                                           6.1.10       */
37
/*  AUTHOR                                                                */
38
/*                                                                        */
39
/*    Kenneth Maxwell, Microsoft Corporation                              */
40
/*                                                                        */
41
/*  DESCRIPTION                                                           */
42
/*                                                                        */
43
/*    This service calculates the bounding rectangle of the radial slider */
44
/*    needle.                                                             */
45
/*                                                                        */
46
/*  INPUT                                                                 */
47
/*                                                                        */
48
/*    slider                                Radial slider control block   */
49
/*    rectangle                             Rectangle to be retrieved     */
50
/*                                                                        */
51
/*  OUTPUT                                                                */
52
/*                                                                        */
53
/*    status                                Completion status             */
54
/*                                                                        */
55
/*  CALLS                                                                 */
56
/*                                                                        */
57
/*    _gx_widget_pixelmap_get               Retrieve pixelmap with        */
58
/*                                           specified resource id        */
59
/*    _gx_utility_rectangle_define          Define a rectangle            */
60
/*                                                                        */
61
/*  CALLED BY                                                             */
62
/*                                                                        */
63
/*    GUIX Internal 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     Ting Zhu                 Modified comment(s),          */
73
/*                                            supported needle offset,    */
74
/*                                            resulting in version 6.1.10 */
75
/*                                                                        */
76
/**************************************************************************/
77
189
UINT _gx_radial_slider_needle_rectangle_calculate(GX_RADIAL_SLIDER *slider, GX_RECTANGLE *rectangle)
78
{
79
GX_PIXELMAP           *map;
80
189
GX_RADIAL_SLIDER_INFO *info = &slider -> gx_radial_slider_info;
81
INT                    xpos;
82
INT                    ypos;
83
84
189
    _gx_widget_pixelmap_get((GX_WIDGET *)slider, info -> gx_radial_slider_info_needle_pixelmap, &map);
85
86
189
    if (map)
87
    {
88
188
        xpos = _gx_utility_math_cos(GX_FIXED_VAL_MAKE(info -> gx_radial_slider_info_current_angle));
89
188
        ypos = _gx_utility_math_sin(GX_FIXED_VAL_MAKE(info -> gx_radial_slider_info_current_angle));
90
91
        /* calculate sin and cos value of current angle value. */
92
188
        xpos = GX_FIXED_VAL_RND((info -> gx_radial_slider_info_radius + info -> gx_radial_slider_info_needle_offset) * xpos);
93
188
        ypos = GX_FIXED_VAL_RND((info -> gx_radial_slider_info_radius + info -> gx_radial_slider_info_needle_offset) * ypos);
94
95
        /* calculate needle position. */
96
188
        xpos += info -> gx_radial_slider_info_xcenter;
97
188
        ypos = info -> gx_radial_slider_info_ycenter - ypos;
98
99
188
        xpos -= map -> gx_pixelmap_width >> 1;
100
188
        ypos -= map -> gx_pixelmap_height >> 1;
101
102
188
        xpos += slider -> gx_widget_size.gx_rectangle_left;
103
188
        ypos += slider -> gx_widget_size.gx_rectangle_top;
104
105
        /* define needle rectangle. */
106
188
        _gx_utility_rectangle_define(rectangle, (GX_VALUE)xpos, (GX_VALUE)ypos,
107
188
                                    (GX_VALUE)(xpos + map -> gx_pixelmap_width),
108
188
                                    (GX_VALUE)(ypos + map -> gx_pixelmap_height));
109
    }
110
    else
111
    {
112
1
        _gx_utility_rectangle_define(rectangle, 0, 0, 0, 0);
113
    }
114
115
189
    return GX_SUCCESS;
116
}
117