Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

Transition.h

Go to the documentation of this file.
00001 //345678901234567890123456789012345678901234567890123456789012345678901234567890
00002 // Author: Richard van Balen
00003 #ifndef OglGui_Transition_h
00004 #define OglGui_Transition_h
00005 
00006 #ifndef OglGui_time_included
00007 #include <time.h>
00008 #define OglGui_time_included
00009 #endif
00010 
00011 #ifndef OglGui_Window_h
00012 #include "OglGui/Window.h"
00013 #endif
00014 
00015 namespace OglGui {
00016 
00017 class Transition : public Window
00018 {
00019 public:
00020     Transition(Window* parent) :
00021         Window(parent,0,0,40,40)
00022     {
00023         Init(parent,40,40);
00024     }
00025     Transition(Window* parent,int x,int y,int w,int h) :
00026         Window(parent,x,y,w,h)
00027     {
00028         Init(parent,w,h);
00029     }
00030 
00031     void
00032     TransitionStart(bool dissolve, int mode1, int mode2 = -1, int ms=500)
00033     {
00034         mDissolveMode = dissolve;
00035         mTransitMode1 = mode1;
00036         mTransitMode2 = (mode2 == -1) ? mode1 : mode2;
00037         mDurationMs = ms;
00038         SetVisible(true);
00039         oglSys.BringToFront(mOglWnd);
00040         SetBackground(dissolve ? 0xffffffff : 0);
00041         mInitializeStart = true;
00042     }
00043 
00044     void GridXY(int x, int y)
00045     {
00046         mNx = x;
00047         mNy = y;
00048     }
00049 
00050     void FillColors(ULONG c1, ULONG c2, ULONG c3, ULONG c4, ULONG cc)
00051     {
00052         mFillCol1 = c1;
00053         mFillCol2 = c2;
00054         mFillCol3 = c3;
00055         mFillCol4 = c4;
00056         mFillColC = cc;
00057     }
00058 
00059     void FillColors(ULONG c1, ULONG c2, ULONG c3, ULONG c4)
00060     {
00061         FillColors(c1,c2,c3,c4,oglWHITE);
00062     }
00063 
00064     void BlockSlide(int mode, int x, int y, int w, int h)
00065     {
00066         int blW = w, blH = h;
00067         int f = 1;
00068         if (mode & 5)
00069         {
00070             f = ((mode & 5) == 5) ? 2 : 1;
00071             blW = ((mPerc/f) * w) / 100;
00072             x += (mode & 1) ? blW : 0;
00073             blW = w - f*blW;
00074         }
00075         if (mode & 10)
00076         {
00077             f = ((mode & 10) == 10) ? 2 : 1;
00078             blH = ((mPerc/f) * h) / 100;
00079             y += (mode & 8) ? blH : 0;
00080             blH = h - f*blH;
00081         }
00082         SetFillColors(mFillCol1,mFillCol2,mFillCol3,mFillCol4,mFillColC);
00083         FillRectangle(x,y,blW,blH);
00084     }
00085 
00086     void OpenCircle(int mode, int x, int y, int w, int h)
00087     {
00088         double pyt = (w/2)*(w/2) + (h/2)*(h/2);
00089         int sz = (int) (sqrt(pyt) * ((mode > 1 && mode < 8) ? mode/2 : 1));
00090         int startR = 1 + (mPerc * sz) / 100;
00091         if (mode < 8 && mode & 1)
00092         {
00093             sz -= startR;
00094             startR = 1;
00095         }
00096         oglSys.StartScissor(mOglWnd,x,y,w,h);
00097         if (mode < 8)
00098         {
00099             SetLineWidth(6);
00100             SetLineColors(mFillCol1,mFillCol2,mFillCol3,mFillCol4);
00101             for (int r=startR; r<sz; r += 2)
00102                 DrawCircle(x+w/2,y+h/2,r);
00103         }
00104         else
00105         {
00106             bool twoSides = (mode>11 && mode<16) || (mode>19&&mode<24);
00107             if (mode < 16)
00108                 sz = w > h ? 3*w/2 : 3*h/2;
00109             int ang = (mode-8) * 90;
00110             double startAng = ang + (twoSides ? mPerc*1.8 : 0);
00111             double endAng = ang+360-mPerc*3.6 + (twoSides ? mPerc*1.8 : 0);
00112             DrawColArc3D(x+w/2,y+h/2,0,sz,sz,DEG2RAD(startAng),DEG2RAD(endAng),
00113                          mFillCol1,mFillCol2,true,mFillColC);
00114         }
00115 
00116         oglSys.EndScissor();
00117     }
00118 
00119     void DoBlock(int mode, int x, int y, int w, int h)
00120     {
00121         if (!mode)
00122             return;
00123         if (mode > 0 && mode < 16)
00124             BlockSlide(mode,x,y,w,h);
00125         else //if (mode < 18)
00126             OpenCircle(mode-16,x,y,w,h);
00127     }
00128 
00129     virtual void InitDisplayFunc()
00130     {
00131         if (mDissolveMode)
00132         {
00133             int col = GetBackground();
00134             int r,g,b,a;
00135             COLOR2RGBA(col,r,g,b,a);
00136             a = 255 - (mPerc*255)/100;
00137             col = RGBA2COLOR(r,g,b,a);
00138             SetBackground(col);
00139             SetDimensions(0,0,mParent->W(),mParent->H());
00140         }
00141         Window::InitDisplayFunc();
00142     }
00143 
00144     virtual void DisplayFunc()
00145     {
00146         if (mInitializeStart)
00147         {
00148             mInitializeStart = false;
00149             mStartTime = OglClock()*1000;
00150         }
00151         if ((mPerc = ((OglClock()*1000 - mStartTime) * 100) / mDurationMs) > 100)
00152             SetVisible(false);
00153         else if (mTransitMode1 || mTransitMode2)
00154         {
00155             OGC oldOGC;
00156             OGCSave(&oldOGC);
00157             SetDimensions(0,0,mParent->W(),mParent->H());
00158             int cnt = 0, blW = W()/mNx, blH = H()/mNy;
00159             for (int i=0; i<mNy; i++) for (int j=0; j<mNx; j++)
00160                 DoBlock((cnt++%2)?mTransitMode2:mTransitMode1,
00161                         j * blW, i * blH, blW, blH);
00162             OGCRestore(&oldOGC);
00163         }
00164         Window::DisplayFunc();
00165     }
00166 
00167 protected:
00168     Window* mParent;
00169     bool    mDissolveMode;
00170     int     mTransitMode1;
00171     int     mTransitMode2;
00172     int     mNx;
00173     int     mNy;
00174     int     mPerc;
00175     int     mDurationMs;
00176     bool    mInitializeStart;
00177     double  mStartTime;
00178     ULONG   mFillCol1;
00179     ULONG   mFillCol2;
00180     ULONG   mFillCol3;
00181     ULONG   mFillCol4;
00182     ULONG   mFillColC;
00183 
00184 private:
00185     void Init(Window* parent, int w, int h)
00186     {
00187         mParent = parent;
00188         mInitializeStart = false;
00189         mDissolveMode = false;
00190         mTransitMode1 = 0;
00191         mTransitMode2 = 0;
00192         mNx = 3;
00193         mNy = 3;
00194         SetAlwaysDraw(true);
00195         SetVisible(false);
00196         mFillCol1 = mFillCol2 = mFillCol3 = mFillCol4 = mFillColC = oglWHITE;
00197     }
00198 
00199 };
00200 
00201 } // Namespace OglGui
00202 #endif
00203 

Generated on Fri Mar 19 09:31:39 2010 for ImpalaSrc by  doxygen 1.5.1