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)
86 interstate = state ? maxValue : minValue;
92 void update(
int deltaTicks)
94 if (!isTransiting)
return;
96 if (counter>=duration)
100 interstate = targetValue;
105 interstate = startValue + (targetValue - startValue) * counter/duration;
110 float getInterstate()
const {
return interstate;}
111 float getInterstatePercentage()
const {
return 100.f * (interstate-minValue)/(maxValue-minValue);}
119 if(s == state)
return *
this;
123 counter = duration - counter;
124 float temp = startValue;
125 startValue = targetValue;
130 if(state == s)
return *
this;
134 startValue = s ? minValue : maxValue;
135 targetValue = s ? maxValue : minValue;
142 void setDuration(
int _duration) {duration = _duration;}
143 virtual float getDuration() {
return duration;}
144 void setMaxValue(
float _max) {
145 if(interstate >= maxValue) interstate =_max;
152 float startValue, targetValue;
164 ParabolicFader(
int _duration=1000,
float minimumValue=0.f,
float maximumValue=1.f,
bool initialState=
false)
165 :
StelFader(initialState, minimumValue, maximumValue)
167 isTransiting =
false;
168 duration = _duration;
169 interstate = state ? maxValue : minValue;
175 void update(
int deltaTicks)
177 if (!isTransiting)
return;
179 if (counter>=duration)
182 isTransiting =
false;
183 interstate = targetValue;
188 interstate = startValue + (targetValue - startValue) * counter/duration;
189 interstate *= interstate;
196 float getInterstate(
void)
const {
return interstate;}
197 float getInterstatePercentage(
void)
const {
return 100.f * (interstate-minValue)/(maxValue-minValue);}
205 if(s == state)
return *
this;
209 counter = duration - counter;
210 float temp = startValue;
211 startValue = targetValue;
216 if(state == s)
return *
this;
220 startValue = s ? minValue : maxValue;
221 targetValue = s ? maxValue : minValue;
228 void setDuration(
int _duration) {duration = _duration;}
229 virtual float getDuration(
void) {
return duration;}
233 float startValue, targetValue;
238 #endif // _STELFADER_HPP_