StelFader.hpp   StelFader.hpp 
skipping to change at line 23 skipping to change at line 23
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA.
*/ */
#ifndef _STELFADER_HPP_ #ifndef _STELFADER_HPP_
#define _STELFADER_HPP_ #define _STELFADER_HPP_
#include <QtGlobal>
//! @class StelFader //! @class StelFader
//! Manages a (usually smooth) transition between two states (typically ON/ OFF) in function of a counter //! Manages a (usually smooth) transition between two states (typically ON/ OFF) in function of a counter
//! It used for various purpose like smooth transitions between //! It used for various purpose like smooth transitions between
class StelFader class StelFader
{ {
public: public:
// Create and initialise // Create and initialise
StelFader(bool initialState, float minimumValue=0.f, float maximumVa lue=1.f) : state(initialState), minValue(minimumValue), maxValue(maximumVal ue) {;} StelFader(bool initialState, float minimumValue=0.f, float maximumVa lue=1.f) : state(initialState), minValue(minimumValue), maxValue(maximumVal ue) {;}
virtual ~StelFader() {;} virtual ~StelFader() {;}
// Increments the internal counter of deltaTime ticks // Increments the internal counter of deltaTime ticks
virtual void update(int deltaTicks) = 0; virtual void update(int deltaTicks) = 0;
// Gets current switch state // Gets current switch state
virtual float getInterstate(void) const = 0; virtual float getInterstate() const = 0;
virtual float getInterstatePercentage(void) const = 0; virtual float getInterstatePercentage() const = 0;
// Switchors can be used just as bools // Switchors can be used just as bools
virtual StelFader& operator=(bool s) = 0; virtual StelFader& operator=(bool s) = 0;
bool operator==(bool s) const {return state==s;} bool operator==(bool s) const {return state==s;}
operator bool() const {return state;} operator bool() const {return state;}
virtual void setDuration(int _duration) {;} virtual void setDuration(int) {;}
virtual float getDuration(void) = 0; virtual float getDuration() = 0;
virtual void setMinValue(float _min) {minValue = _min;} virtual void setMinValue(float _min) {minValue = _min;}
virtual void setMaxValue(float _max) {maxValue = _max;} virtual void setMaxValue(float _max) {maxValue = _max;}
float getMinValue(void) {return minValue;} float getMinValue() {return minValue;}
float getMaxValue(void) {return maxValue;} float getMaxValue() {return maxValue;}
protected: protected:
bool state; bool state;
float minValue, maxValue; float minValue, maxValue;
}; };
//! @class BooleanFader //! @class BooleanFader
//! Implementation of StelFader which behaves like a normal boolean, i.e. n o transition between on and off. //! Implementation of StelFader which behaves like a normal boolean, i.e. n o transition between on and off.
class BooleanFader : public StelFader class BooleanFader : public StelFader
{ {
public: public:
// Create and initialise // Create and initialise
BooleanFader(bool initialState=false, float minimumValue=0.f, float maximumValue=1.f) : StelFader(initialState, minimumValue, maximumValue) {;} BooleanFader(bool initialState=false, float minimumValue=0.f, float maximumValue=1.f) : StelFader(initialState, minimumValue, maximumValue) {;}
~BooleanFader() {;} ~BooleanFader() {;}
// Increments the internal counter of deltaTime ticks // Increments the internal counter of deltaTime ticks
void update(int deltaTicks) {;} void update(int deltaTicks) {Q_UNUSED(deltaTicks);}
// Gets current switch state // Gets current switch state
float getInterstate(void) const {return state ? maxValue : minValue; float getInterstate() const {return state ? maxValue : minValue;}
} float getInterstatePercentage() const {return state ? 100.f : 0.f;}
float getInterstatePercentage(void) const {return state ? 100.f : 0.
f;}
// Switchors can be used just as bools // Switchors can be used just as bools
StelFader& operator=(bool s) {state=s; return *this;} StelFader& operator=(bool s) {state=s; return *this;}
virtual float getDuration(void) {return 0.f;} virtual float getDuration() {return 0.f;}
protected: protected:
}; };
//! @class LinearFader //! @class LinearFader
//! Implementation of StelFader which implements a linear transition. //! Implementation of StelFader which implements a linear transition.
//! Please note that state is updated instantaneously, so if you need to dr aw something fading in //! Please note that state is updated instantaneously, so if you need to dr aw something fading in
//! and out, you need to check the interstate value (!=0) to know to draw w hen on AND during transitions. //! and out, you need to check the interstate value (!=0) to know to draw w hen on AND during transitions.
class LinearFader : public StelFader class LinearFader : public StelFader
{ {
public: public:
skipping to change at line 108 skipping to change at line 110
interstate = targetValue; interstate = targetValue;
// state = (targetValue==maxValue) ? true : false; // state = (targetValue==maxValue) ? true : false;
} }
else else
{ {
interstate = startValue + (targetValue - startValue) * counter/duration; interstate = startValue + (targetValue - startValue) * counter/duration;
} }
} }
// Get current switch state // Get current switch state
float getInterstate(void) const { return interstate;} float getInterstate() const { return interstate;}
float getInterstatePercentage(void) const {return 100.f * (interstat float getInterstatePercentage() const {return 100.f * (interstate-mi
e-minValue)/(maxValue-minValue);} nValue)/(maxValue-minValue);}
// StelFaders can be used just as bools // StelFaders can be used just as bools
StelFader& operator=(bool s) StelFader& operator=(bool s)
{ {
if(isTransiting) { if(isTransiting) {
// if same end state, no changes // if same end state, no changes
if(s == state) return *this; if(s == state) return *this;
// otherwise need to reverse course // otherwise need to reverse course
skipping to change at line 141 skipping to change at line 143
state = s; state = s;
startValue = s ? minValue : maxValue; startValue = s ? minValue : maxValue;
targetValue = s ? maxValue : minValue; targetValue = s ? maxValue : minValue;
counter=0; counter=0;
isTransiting = true; isTransiting = true;
} }
return *this; return *this;
} }
void setDuration(int _duration) {duration = _duration;} void setDuration(int _duration) {duration = _duration;}
virtual float getDuration(void) {return duration;} virtual float getDuration() {return duration;}
void setMaxValue(float _max) { void setMaxValue(float _max) {
if(interstate >= maxValue) interstate =_max; if(interstate >= maxValue) interstate =_max;
maxValue = _max; maxValue = _max;
} }
protected: protected:
bool isTransiting; bool isTransiting;
int duration; int duration;
float startValue, targetValue; float startValue, targetValue;
int counter; int counter;
 End of changes. 9 change blocks. 
16 lines changed or deleted 16 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/