20 #ifndef _STELFADER_HPP_ 21 #define _STELFADER_HPP_ 32 StelFader(
bool initialState,
float minimumValue=0.f,
float maximumValue=1.f) : state(initialState), minValue(minimumValue), maxValue(maximumValue) {;}
35 virtual void update(
int deltaTicks) = 0;
37 virtual float getInterstate()
const = 0;
38 virtual float getInterstatePercentage()
const = 0;
41 bool operator==(
bool s)
const {
return state==s;}
42 operator bool()
const {
return state;}
43 virtual void setDuration(
int) {;}
44 virtual float getDuration() = 0;
45 virtual void setMinValue(
float _min) {minValue = _min;}
46 virtual void setMaxValue(
float _max) {maxValue = _max;}
47 float getMinValue() {
return minValue;}
48 float getMaxValue() {
return maxValue;}
51 float minValue, maxValue;
60 BooleanFader(
bool initialState=
false,
float minimumValue=0.f,
float maximumValue=1.f) :
StelFader(initialState, minimumValue, maximumValue) {;}
63 void update(
int deltaTicks) {Q_UNUSED(deltaTicks);}
65 float getInterstate()
const {
return state ? maxValue : minValue;}
66 float getInterstatePercentage()
const {
return state ? 100.f : 0.f;}
68 StelFader& operator=(
bool s) {state=s;
return *
this;}
69 virtual float getDuration() {
return 0.f;}
81 LinearFader(
int _duration=1000,
float minimumValue=0.f,
float maximumValue=1.f,
bool initialState=
false)
82 :
StelFader(initialState, minimumValue, maximumValue)
89 interstate = state ? maxValue : minValue;
95 void update(
int deltaTicks)
97 if (!isTransiting)
return;
99 if (counter>=duration)
102 isTransiting =
false;
103 interstate = targetValue;
108 interstate = startValue + (targetValue - startValue) * counter/duration;
113 float getInterstate()
const {
return interstate;}
114 float getInterstatePercentage()
const {
return 100.f * (interstate-minValue)/(maxValue-minValue);}
122 if(s == state)
return *
this;
126 counter = duration - counter;
127 float temp = startValue;
128 startValue = targetValue;
133 if(state == s)
return *
this;
137 startValue = s ? minValue : maxValue;
138 targetValue = s ? maxValue : minValue;
145 void setDuration(
int _duration) {duration = _duration;}
146 virtual float getDuration() {
return duration;}
147 void setMaxValue(
float _max) {
148 if(interstate >= maxValue) interstate =_max;
155 float startValue, targetValue;
167 ParabolicFader(
int _duration=1000,
float minimumValue=0.f,
float maximumValue=1.f,
bool initialState=
false)
168 :
StelFader(initialState, minimumValue, maximumValue)
170 isTransiting =
false;
171 duration = _duration;
172 interstate = state ? maxValue : minValue;
178 void update(
int deltaTicks)
180 if (!isTransiting)
return;
182 if (counter>=duration)
185 isTransiting =
false;
186 interstate = targetValue;
191 interstate = startValue + (targetValue - startValue) * counter/duration;
192 interstate *= interstate;
199 float getInterstate(
void)
const {
return interstate;}
200 float getInterstatePercentage(
void)
const {
return 100.f * (interstate-minValue)/(maxValue-minValue);}
208 if(s == state)
return *
this;
212 counter = duration - counter;
213 float temp = startValue;
214 startValue = targetValue;
219 if(state == s)
return *
this;
223 startValue = s ? minValue : maxValue;
224 targetValue = s ? maxValue : minValue;
231 void setDuration(
int _duration) {duration = _duration;}
232 virtual float getDuration(
void) {
return duration;}
236 float startValue, targetValue;
241 #endif // _STELFADER_HPP_ Implementation of StelFader which implements a linear transition.
Implementation of StelFader which behaves like a normal boolean, i.e.
Manages a (usually smooth) transition between two states (typically ON/OFF) in function of a counter ...