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