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 |
|
|
/** Prompt Management (Slider) */ |
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_display.h" |
28 |
|
|
#include "gx_context.h" |
29 |
|
|
#include "gx_widget.h" |
30 |
|
|
#include "gx_utility.h" |
31 |
|
|
#include "gx_slider.h" |
32 |
|
|
|
33 |
|
|
/**************************************************************************/ |
34 |
|
|
/* */ |
35 |
|
|
/* FUNCTION RELEASE */ |
36 |
|
|
/* */ |
37 |
|
|
/* _gx_slider_value_calculate PORTABLE C */ |
38 |
|
|
/* 6.1 */ |
39 |
|
|
/* AUTHOR */ |
40 |
|
|
/* */ |
41 |
|
|
/* Kenneth Maxwell, Microsoft Corporation */ |
42 |
|
|
/* */ |
43 |
|
|
/* DESCRIPTION */ |
44 |
|
|
/* */ |
45 |
|
|
/* This service calculates the slider value. */ |
46 |
|
|
/* */ |
47 |
|
|
/* INPUT */ |
48 |
|
|
/* */ |
49 |
|
|
/* slider Slider widget control block */ |
50 |
|
|
/* info Pointer to slider info */ |
51 |
|
|
/* new_position New slider position */ |
52 |
|
|
/* */ |
53 |
|
|
/* OUTPUT */ |
54 |
|
|
/* */ |
55 |
|
|
/* status Completion status */ |
56 |
|
|
/* None */ |
57 |
|
|
/* */ |
58 |
|
|
/* CALLS */ |
59 |
|
|
/* */ |
60 |
|
|
/* _gx_slider_travel_get Get the slider travel */ |
61 |
|
|
/* _gx_slider_value_set Set the slider value */ |
62 |
|
|
/* */ |
63 |
|
|
/* CALLED BY */ |
64 |
|
|
/* */ |
65 |
|
|
/* Application Code */ |
66 |
|
|
/* GUIX Internal Code */ |
67 |
|
|
/* */ |
68 |
|
|
/* RELEASE HISTORY */ |
69 |
|
|
/* */ |
70 |
|
|
/* DATE NAME DESCRIPTION */ |
71 |
|
|
/* */ |
72 |
|
|
/* 05-19-2020 Kenneth Maxwell Initial Version 6.0 */ |
73 |
|
|
/* 09-30-2020 Kenneth Maxwell Modified comment(s), */ |
74 |
|
|
/* resulting in version 6.1 */ |
75 |
|
|
/* */ |
76 |
|
|
/**************************************************************************/ |
77 |
|
5359 |
UINT _gx_slider_value_calculate(GX_SLIDER *slider, GX_SLIDER_INFO *info, INT new_position) |
78 |
|
|
{ |
79 |
|
|
INT newval; |
80 |
|
|
INT mintravel; |
81 |
|
|
INT maxtravel; |
82 |
|
|
|
83 |
|
|
/* get travel limits */ |
84 |
|
5359 |
_gx_slider_travel_get(slider, info, &mintravel, &maxtravel); |
85 |
|
|
|
86 |
|
|
/* make sure we don't allow travel too far */ |
87 |
✓✓ |
5359 |
if (new_position < mintravel) |
88 |
|
|
{ |
89 |
|
1726 |
new_position = mintravel; |
90 |
|
|
} |
91 |
|
|
else |
92 |
|
|
{ |
93 |
✓✓ |
3633 |
if (new_position > maxtravel) |
94 |
|
|
{ |
95 |
|
1623 |
new_position = maxtravel; |
96 |
|
|
} |
97 |
|
|
} |
98 |
|
|
|
99 |
|
|
/* use position to calculate new value */ |
100 |
✓✓ |
5359 |
if (maxtravel > mintravel) |
101 |
|
|
{ |
102 |
|
|
/* do linear interpolation using input position to |
103 |
|
|
determine new slider value |
104 |
|
|
*/ |
105 |
|
|
|
106 |
|
|
/* get distance from starting point */ |
107 |
|
|
|
108 |
✓✓ |
5214 |
if (slider -> gx_widget_style & GX_STYLE_SLIDER_VERTICAL) |
109 |
|
|
{ |
110 |
|
2292 |
newval = maxtravel - new_position; |
111 |
|
|
} |
112 |
|
|
else |
113 |
|
|
{ |
114 |
|
2922 |
newval = new_position - mintravel; |
115 |
|
|
} |
116 |
|
|
|
117 |
|
5214 |
newval = GX_FIXED_VAL_MAKE(newval); |
118 |
|
|
|
119 |
|
|
/* multiply by value range */ |
120 |
|
5214 |
newval *= info -> gx_slider_info_max_val - info -> gx_slider_info_min_val; |
121 |
|
|
|
122 |
|
|
/* divide by travel range */ |
123 |
|
5214 |
newval /= (maxtravel - mintravel); |
124 |
|
5214 |
newval = GX_FIXED_VAL_RND(newval); |
125 |
|
|
|
126 |
|
|
/* offset by min value */ |
127 |
|
5214 |
newval += info -> gx_slider_info_min_val; |
128 |
|
|
|
129 |
|
|
/* has the value changed? */ |
130 |
✓✓ |
5214 |
if (newval != info -> gx_slider_info_current_val) |
131 |
|
|
{ |
132 |
|
|
/* yes, re-assign value which will move the needle */ |
133 |
|
2432 |
_gx_slider_value_set(slider, info, newval); |
134 |
|
|
} |
135 |
|
|
} |
136 |
|
5359 |
return(GX_SUCCESS); |
137 |
|
|
} |
138 |
|
|
|