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 |
|
|
/** Progress Bar Management (Radial Progress Bar) */ |
18 |
|
|
/** */ |
19 |
|
|
/**************************************************************************/ |
20 |
|
|
|
21 |
|
|
#define GX_SOURCE_CODE |
22 |
|
|
|
23 |
|
|
/* Include necessary system files. */ |
24 |
|
|
|
25 |
|
|
#include "gx_api.h" |
26 |
|
|
#include "gx_system.h" |
27 |
|
|
#include "gx_utility.h" |
28 |
|
|
#include "gx_radial_progress_bar.h" |
29 |
|
|
|
30 |
|
|
/**************************************************************************/ |
31 |
|
|
/* */ |
32 |
|
|
/* FUNCTION RELEASE */ |
33 |
|
|
/* */ |
34 |
|
|
/* _gx_radial_progress_bar_value_calculate PORTABLE C */ |
35 |
|
|
/* 6.1 */ |
36 |
|
|
/* AUTHOR */ |
37 |
|
|
/* */ |
38 |
|
|
/* Kenneth Maxwell, Microsoft Corporation */ |
39 |
|
|
/* */ |
40 |
|
|
/* DESCRIPTION */ |
41 |
|
|
/* */ |
42 |
|
|
/* This service calcualtes the radial progress bar value. */ |
43 |
|
|
/* */ |
44 |
|
|
/* */ |
45 |
|
|
/* INPUT */ |
46 |
|
|
/* */ |
47 |
|
|
/* progress_bar Radial Progress Bar control */ |
48 |
|
|
/* block */ |
49 |
|
|
/* new_position New progress bar position */ |
50 |
|
|
/* */ |
51 |
|
|
/* OUTPUT */ |
52 |
|
|
/* */ |
53 |
|
|
/* status Completion status */ |
54 |
|
|
/* */ |
55 |
|
|
/* CALLS */ |
56 |
|
|
/* */ |
57 |
|
|
/* _gx_radial_progress_bar_value_set Set the value for the */ |
58 |
|
|
/* progress bar */ |
59 |
|
|
/* */ |
60 |
|
|
/* CALLED BY */ |
61 |
|
|
/* */ |
62 |
|
|
/* Application Code */ |
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 |
|
|
/* */ |
73 |
|
|
/**************************************************************************/ |
74 |
|
25 |
UINT _gx_radial_progress_bar_value_calculate(GX_RADIAL_PROGRESS_BAR *progress_bar, GX_POINT new_position) |
75 |
|
|
{ |
76 |
|
|
GX_RADIAL_PROGRESS_BAR_INFO *info; |
77 |
|
|
INT new_value; |
78 |
|
|
INT dist; |
79 |
|
|
INT x_dist; |
80 |
|
|
INT y_dist; |
81 |
|
|
|
82 |
|
|
|
83 |
|
25 |
info = &progress_bar -> gx_radial_progress_bar_info; |
84 |
|
|
|
85 |
|
25 |
x_dist = (INT)(new_position.gx_point_x - info -> gx_radial_progress_bar_info_xcenter); |
86 |
|
25 |
y_dist = (INT)(new_position.gx_point_y - info -> gx_radial_progress_bar_info_ycenter); |
87 |
|
|
|
88 |
|
25 |
dist = (x_dist * x_dist) + (y_dist * y_dist); |
89 |
|
25 |
dist = (INT)_gx_utility_math_sqrt((UINT)dist); |
90 |
|
|
|
91 |
✓✓ |
25 |
if (!dist) |
92 |
|
|
{ |
93 |
|
1 |
return GX_FAILURE; |
94 |
|
|
} |
95 |
|
|
|
96 |
✓✓ |
24 |
if (new_position.gx_point_y <= info -> gx_radial_progress_bar_info_ycenter) |
97 |
|
|
{ |
98 |
|
16 |
x_dist = GX_FIXED_VAL_MAKE(x_dist) / dist; |
99 |
|
|
|
100 |
|
|
/* New position hit upper track. */ |
101 |
|
16 |
new_value = _gx_utility_math_acos(x_dist); |
102 |
|
|
} |
103 |
|
|
else |
104 |
|
|
{ |
105 |
|
8 |
y_dist = GX_FIXED_VAL_MAKE(y_dist) / dist; |
106 |
|
|
|
107 |
|
|
/* New position hit lower track. */ |
108 |
|
8 |
new_value = _gx_utility_math_asin(y_dist); |
109 |
|
|
|
110 |
✓✓ |
8 |
if (new_position.gx_point_x < info -> gx_radial_progress_bar_info_xcenter) |
111 |
|
|
{ |
112 |
|
4 |
new_value = 180 + new_value; |
113 |
|
|
} |
114 |
|
|
else |
115 |
|
|
{ |
116 |
|
4 |
new_value = 360 - new_value; |
117 |
|
|
} |
118 |
|
|
} |
119 |
|
|
|
120 |
✓✓ |
24 |
if (info -> gx_radial_progress_bar_info_current_val <= 0) |
121 |
|
|
{ |
122 |
|
|
/* Move radial progress bar clockwise. */ |
123 |
|
12 |
new_value = new_value - info -> gx_radial_progress_bar_info_anchor_val; |
124 |
|
|
|
125 |
✓✓ |
12 |
if (new_value > 0) |
126 |
|
|
{ |
127 |
|
6 |
new_value -= 360; |
128 |
|
|
} |
129 |
|
|
} |
130 |
|
|
else |
131 |
|
|
{ |
132 |
|
|
/* Move radial progress bar anti-clockwise. */ |
133 |
|
12 |
new_value = new_value - info -> gx_radial_progress_bar_info_anchor_val; |
134 |
|
|
|
135 |
✓✓ |
12 |
if (new_value < 0) |
136 |
|
|
{ |
137 |
|
6 |
new_value += 360; |
138 |
|
|
} |
139 |
|
|
} |
140 |
|
|
|
141 |
|
24 |
_gx_radial_progress_bar_value_set(progress_bar, (GX_VALUE)new_value); |
142 |
|
|
|
143 |
|
24 |
return(GX_SUCCESS); |
144 |
|
|
} |
145 |
|
|
|