00001
00002
00003 #ifndef OglGui_OpenClose_h
00004 #define OglGui_OpenClose_h
00005
00006 namespace OglGui {
00007
00008 class OpenClose
00009 {
00010 public:
00011 OpenClose(Window* parent)
00012 {
00013 Init(parent);
00014 }
00015
00016 void Opening(bool mode) { mOpening = mode; }
00017 bool Opening() { return mOpening; }
00018 void Closing(bool mode) { mClosing = mode; }
00019 bool Closing() { return mClosing; }
00020 Window* Target() { return mTarget; }
00021 void Target(Window* target) { mTarget = target; }
00022
00023 void Open(Window *target, int x, int y, int w, int h, int ms=500)
00024 {
00025 mTarget = target;
00026 mDurationMs = ms;
00027 mStartX = x;
00028 mStartY = y;
00029 mStartW = w;
00030 mStartH = h;
00031 mTarget->SetDimensions(x,y,w,h);
00032 mTarget->SetVisible(true);
00033 mStartTime = OglClock()*1000;
00034 mOpening = true;
00035 }
00036
00037 void Close(int ms=500)
00038 {
00039 mTarget->GetDimensions(mEndX,mEndY,mEndW,mEndH);
00040 mDurationMs = ms;
00041 mTarget->SetVisible(true);
00042 mStartTime = OglClock()*1000;
00043 mClosing = true;
00044 }
00045
00046 virtual void DisplayFunc()
00047 {
00048 if (!mTarget)
00049 return;
00050
00051 if ((mPerc = ((OglClock()*1000 - mStartTime) * 100) / mDurationMs) > 100)
00052 {
00053 mTarget->SetDimensions(0,0,mParent->W(), mParent->H());
00054 if (mClosing)
00055 mTarget->SetVisible(false);
00056 mClosing = mOpening = false;
00057 }
00058 else
00059 {
00060 int x,y,w,h;
00061 mTarget->GetDimensions(x,y,w,h);
00062 double p = mFancy ? sin(DEG2RAD(mPerc*0.9))*mPerc : mPerc;
00063 if (mOpening)
00064 {
00065 x = mStartX - (p * mStartX)/100;
00066 y = mStartY - (p * mStartY)/100;
00067 w = mStartW + (mPerc * (mParent->W() - mStartW))/100;
00068 h = mStartH + (mPerc * (mParent->H() - mStartH))/100;
00069 }
00070 else
00071 {
00072 x = mEndX - (p * (mEndX-mStartX))/100;
00073 y = mEndY - (p * (mEndY-mStartY))/100;
00074 w = mEndW - (mPerc * (mEndW-mStartW))/100;
00075 h = mEndH - (mPerc * (mEndH-mStartH))/100;
00076 }
00077 mTarget->SetDimensions(x,y,w,h);
00078 }
00079 }
00080
00081 protected:
00082 Window* mParent;
00083 Window* mTarget;
00084 int mPerc;
00085 int mDurationMs;
00086 double mStartTime;
00087
00088 bool mOpening;
00089 bool mClosing;
00090 int mStartX;
00091 int mStartY;
00092 int mStartW;
00093 int mStartH;
00094
00095 int mEndX;
00096 int mEndY;
00097 int mEndW;
00098 int mEndH;
00099
00100 bool mFancy;
00101
00102 private:
00103 void Init(Window* parent)
00104 {
00105 mParent = parent;
00106 mTarget = 0;
00107 mOpening = false;
00108 mClosing = false;
00109 mFancy = true;
00110 }
00111 };
00112
00113 }
00114 #endif
00115