00001 00014 #ifndef PROGRESSBAR_H 00015 #define PROGRESSBAR_H 00016 00017 00018 #include "IS3DCommon.H" 00019 #include "DrawObj.H" 00020 00021 namespace IS3D { 00022 00023 00024 // Functors allow for callback functions that are class methods 00025 // in C++. Google "C++ functors" for more information. 00026 class ProgressCallbackFunctor 00027 { 00028 public: 00029 virtual ~ProgressCallbackFunctor() {} 00030 virtual float exec() = 0; 00031 }; 00032 00033 template <class T> 00034 class ProgressCallbackSpecificFunctor : public ProgressCallbackFunctor 00035 { 00036 public: 00037 typedef float (T::*MethodType)(); 00038 ProgressCallbackSpecificFunctor(T *obj, MethodType meth) { 00039 _obj = obj; 00040 _method = meth; 00041 } 00042 virtual ~ProgressCallbackSpecificFunctor() {} 00043 float exec() { 00044 return (_obj->*_method)(); 00045 } 00046 protected: 00047 T *_obj; 00048 MethodType _method; 00049 }; 00050 // End functor bullshit 00051 00052 00053 00054 00055 00056 00057 typedef ReferenceCountedPointer<class ProgressBar> ProgressBarRef; 00079 class ProgressBar : public DrawObj 00080 { 00081 public: 00082 ProgressBar(const std::string &title); 00083 virtual ~ProgressBar(); 00084 00086 void setValue(float v) { _value = v; } 00087 float getValue() { return _value; } 00088 00089 template <class T> 00090 void setProgressUpdateCallback(T *thisPtr, float (T::*method)()) { 00091 if (_callback != NULL) 00092 delete _callback; 00093 _callback = new ProgressCallbackSpecificFunctor<T>(thisPtr, method); 00094 } 00095 00096 void draw(); 00097 00098 private: 00099 ProgressCallbackFunctor *_callback; 00100 std::string _title; 00101 float _value; 00102 GFontRef _font; 00103 Color4 _outlineCol, _bgCol, _barCol, _titleCol, _percCol; 00104 Vector2 _pos; 00105 Vector2 _size; 00106 }; 00107 00108 } // end namespace 00109 00110 #endif 00111