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

OglWindow.h

Go to the documentation of this file.
00001 #ifndef OglGui_OglWindow_h
00002 #define OglGui_OglWindow_h
00003 
00004 #ifndef OglGui_string_included
00005 #include <string>
00006 #define OglGui_string_included
00007 #endif
00008 
00009 #ifndef OglGui_Sys_h
00010 #include "OglGui/Sys.h"
00011 #endif
00012 
00013 #ifndef OglGui_LayoutListener_h
00014 #include "OglGui/LayoutListener.h"
00015 #endif
00016 #ifndef OglGui_LayoutConnect_h
00017 #include "OglGui/LayoutConnect.h"
00018 #endif
00019 #ifndef OglGui_LayoutScale_h
00020 #include "OglGui/LayoutScale.h"
00021 #endif
00022 
00023 namespace OglGui
00024 {
00025 
00026 
00033 class OglWindow : public LayoutComponent
00034 {
00035 public:
00036 
00037     OglWindow(int x, int y, int width, int height)
00038     {
00039         mOglWnd = oglSys.CreateOGLWND(x, y, width, height);
00040         Init();
00041     }
00042 
00043     OglWindow(OglWindow* parent, int x, int y, int width, int height)
00044     {
00045         mOglWnd = oglSys.CreateOGLViewPort(parent->mOglWnd, x, y, width,height);
00046         Init();
00047     }
00048 
00049     OglWindow(OGLWND *oglWnd)
00050     {
00051         mOglWnd = oglWnd;
00052         Init();
00053     }
00054 
00055     OglWindow(OGLWND *parent, int x, int y, int width, int height)
00056     {
00057         mOglWnd = oglSys.CreateOGLViewPort(parent, x, y, width, height);
00058         Init();
00059     }
00060 
00061     virtual ~OglWindow()
00062     {
00063 #ifdef DESTRUCT_VERBOSE
00064 printf("virtual OglGui::OglWindow destructor %d\n", mOglWnd);
00065 #endif
00066         mIsDestructing = true;
00067         if (!mIsExiting && mOglWnd)
00068             oglSys.ExitWindow(mOglWnd, 1);
00069     }
00070 
00072     // Layout handling
00073     virtual void OnLayoutChange()
00074     {
00075         for(unsigned int i=0 ; i<mLayoutFollowers.size() ; i++)
00076             if (mLayoutFollowers[i] != 0)
00077                 mLayoutFollowers[i]->OnLayoutChange();
00078     }
00079 
00080     LayoutListener* ConnectTo(LayoutComponent* target, int mode=ALLSIDES)
00081     {
00082         if (target == GetParent())
00083             mode |= TPARENT;
00084         return new LayoutConnect(target, this, mode);
00085     }
00086 
00087     LayoutListener* ScaleTo(LayoutComponent* target, int mode=0)
00088     {
00089         return new LayoutScale(target, this, mode);
00090     }
00091 
00092     //----------------------------------------------------------------
00093 
00094     bool Valid() const
00095     {
00096         return (mOglWnd != 0);
00097     }
00098 
00099     OGLWND* GetOGLWND() const
00100     {
00101         return mOglWnd;
00102     }
00103 
00104     void UpdateScene(bool mode=true) const
00105     {
00106         oglSys.SetUpdateScene(mOglWnd, mode);
00107     }
00108 
00109     virtual void SetFocus()
00110     {
00111         oglFocusWnd = mOglWnd;
00112     }
00113 
00114     void SetAlwaysDraw(bool mode=true)
00115     {
00116         oglSys.SetAlwaysDraw(mOglWnd, mode);
00117     }
00118 
00119     void SetVisible(bool flag=true)
00120     {
00121         if (flag)
00122             SetTags((TAGABLE *) mOglWnd, visibleTag);
00123         else
00124             ClearTags((TAGABLE *) mOglWnd, visibleTag);
00125     }
00126 
00127     bool GetVisible()
00128     {
00129         return HasTags((TAGABLE *) mOglWnd, visibleTag) ? true : false;
00130     }
00131 
00132     void SetBackground(ULONG col)
00133     {
00134         oglSys.SetBackground(mOglWnd, col);
00135     }
00136 
00137     ULONG GetBackground()
00138     {
00139         return oglSys.GetBackground(mOglWnd);
00140     }
00141 
00142     int WndX()      { return mOglWnd->x; }      // Deprecated
00143     int WndY()      { return mOglWnd->y; }      // Deprecated
00144     int WndWidth()  { return mOglWnd->width; }  // Deprecated
00145     int WndHeight() { return mOglWnd->height; } // Deprecated
00146 
00147     int X()         { return mOglWnd->x; }
00148     int Y()         { return mOglWnd->y; }
00149     int W()         { return mOglWnd->width; }
00150     int H()         { return mOglWnd->height; }
00151     int Width()     { return mOglWnd->width; }
00152     int Height()    { return mOglWnd->height; }
00153 
00154     static void ToTopWindow(OglWindow* wnd, int& x, int& y)
00155     {
00156         oglSys.VPToTopWndI(wnd->GetOGLWND(),&x,&y);
00157     }
00158     static void TopWindowTo(OglWindow* wnd, int& x, int& y)
00159     {
00160         oglSys.TopWndToVPI(wnd->GetOGLWND(),&x,&y);
00161     }
00162 
00163     void SetDimensions(int x, int y, int w, int h)
00164     {
00165         bool workaround = (x!=mOglWnd->x || y!= mOglWnd->y) &&
00166                           (w==mOglWnd->width) && (h==mOglWnd->height);
00167 
00168         oglSys.SetDimensions(mOglWnd, x, y, w, h);
00169         if (workaround)
00170             OnLayoutChange();
00171     }
00172 
00173     void SetDimensions(int w, int h)
00174     {
00175         SetDimensions(mOglWnd->x, mOglWnd->y, w, h);
00176         //oglSys.SetDimensions(mOglWnd, mOglWnd->x, mOglWnd->y, w, h);
00177     }
00178 
00179     void GetDimensions(int& x, int& y, int& w, int& h)
00180     {
00181         x = mOglWnd->x;
00182         y = mOglWnd->y;
00183         w = mOglWnd->width;
00184         h = mOglWnd->height;
00185     }
00186 
00187     void GetDimensions(int& w, int& h)
00188     {
00189         w = mOglWnd->width;
00190         h = mOglWnd->height;
00191     }
00192 
00193     bool IsRounded()
00194     {
00195         OGLWND *w = GetOGLWND();
00196         return w->r0 != 0.0f || w->r1 != 0.0f || w->r2 != 0.0f || w->r3 != 0.0f;
00197     }
00198 
00199     void SetRoundness(float r0, float r1, float r2, float r3)
00200     {
00201         oglSys.SetRoundness(mOglWnd, r0, r1, r2, r3);
00202     }
00203 
00204     bool GetRoundness(float& r0, float& r1, float& r2, float& r3)
00205     {
00206         r0 = mOglWnd->r0;
00207         r1 = mOglWnd->r1;
00208         r2 = mOglWnd->r2;
00209         r3 = mOglWnd->r3;
00210         return r0 != 0.0f || r1 != 0.0f || r2 != 0.0f || r3 != 0.0f;
00211     }
00212 
00213     void SetClipRounded(bool mode)
00214     {
00215         mOglWnd->clipRounded = mode;
00216     }
00217 
00218     virtual void SetBorderType(int type)
00219     {
00220         mOglWnd->borderType = type;
00221     }
00222 
00223     int GetBorderType()
00224     {
00225         return mOglWnd->borderType;
00226     }
00227 
00228     void SetBorderBackground(ULONG col)
00229     {
00230         mOglWnd->borderBgCol = col;
00231     }
00232 
00233     ULONG GetBorderBackground()
00234     {
00235         return mOglWnd->borderBgCol;
00236     }
00237 
00238     virtual void SetBorderFillShaded(int sh=2)
00239     {
00240         mOglWnd->borderFillShaded = sh;
00241     }
00242 
00243     int GetBorderFillShaded()
00244     {
00245         return mOglWnd->borderFillShaded;
00246     }
00247 
00248     void SetBorderFillOpacity(float op=0.5f)
00249     {
00250         mOglWnd->borderFillOpacity = op;
00251     }
00252 
00253     float GetBorderFillOpacity()
00254     {
00255         return mOglWnd->borderFillOpacity;
00256     }
00257 
00258     void SetNoMouseInput(bool mode=true)
00259     {
00260         oglSys.SetNoMouseInput(mOglWnd,mode);
00261     }
00262 
00263     int GetId() const
00264     {
00265         return mID;
00266     }
00267 
00268     int GetRunTimeType()
00269     {
00270         return mRunTimeType;
00271     }
00272 
00273     static OglWindow* GetPeer(OGLWND* oglWnd)
00274     {
00275         if (!oglWnd)
00276             return 0;
00277         return (OglWindow*) oglSys.GetSysData(oglWnd, 1);
00278     }
00279 
00280     OglWindow* GetParent()
00281     {
00282         if (mOglWnd->parent)
00283             return (OglWindow*) oglSys.GetSysData(mOglWnd->parent, 1);
00284         return 0;
00285     }
00286 
00287     static OglWindow* GetOglWindow(OGLWND* oglWnd)
00288     {
00289         return static_cast<OglWindow*>(oglSys.GetSysData(oglWnd, 1));
00290         // RvB: Wat is het verschil tussen static_cast en gewone.
00291         // return (OglWindow*)(oglSys.GetSysData(oglWnd, 1));
00292     }
00293 
00295 // C++ OVERLOADABLE OGL USER FUNCS.
00296 //
00297 // In support of overloading C OGL apps, default mapped to execute
00298 // old C user functions, if any.
00299 
00300     virtual void InitFunc()
00301     {
00302         if (mOldUserCFunctions.initFunc)
00303             mOldUserCFunctions.initFunc(mOglWnd);
00304     }
00305 
00306     virtual void ExitFunc()
00307     {
00308         mIsExiting = true;
00309         if (mOldUserCFunctions.exitFunc)
00310         {
00311             OGLUSERFUNCS funcs = mOldUserCFunctions;
00312             mOldUserCFunctions.exitFunc = 0;
00313             funcs.exitFunc(mOglWnd);
00314         }
00315 
00316         if (!mIsDestructing)
00317             delete this;
00318     }
00319 
00320 /*    
00321     virtual void ExitFunc()
00322     {
00323         if (mOldUserCFunctions.exitFunc)
00324         {
00325             mOldUserCFunctions.exitFunc(mOglWnd);
00326             mOldUserCFunctions.exitFunc = 0;
00327         }
00328 
00329         mIsExiting = true;
00330 
00331         if (!mIsDestructing)
00332             delete this;
00333     }
00334 */    
00335 
00336     virtual void InitDisplayFunc()
00337     {
00338         if (mOldUserCFunctions.initDisplayFunc)
00339             mOldUserCFunctions.initDisplayFunc(mOglWnd);
00340     }
00341 
00342     virtual void DisplayFunc()
00343     {
00344         if (mOldUserCFunctions.displayFunc)
00345             mOldUserCFunctions.displayFunc(mOglWnd);
00346     }
00347 
00348     virtual void MouseFunc(int msg, int but, int state, int x, int y)
00349     {
00350         if (mOldUserCFunctions.mouseFunc)
00351             mOldUserCFunctions.mouseFunc(mOglWnd, msg, but, state, x, y);
00352     }
00353 
00354     virtual void KeyboardFunc(int c, int state)
00355     {
00356         if (mOldUserCFunctions.keyboardFunc)
00357             mOldUserCFunctions.keyboardFunc(mOglWnd, c, state);
00358     }
00359 
00360     virtual void ViewportFunc(int width, int height)
00361     {
00362         if (mOldUserCFunctions.viewportFunc)
00363             mOldUserCFunctions.viewportFunc(mOglWnd, width, height);
00364     }
00365 
00366     virtual void ReshapeFunc(int width, int height)
00367     {
00368         if (mOldUserCFunctions.reshapeFunc)
00369             mOldUserCFunctions.reshapeFunc(mOglWnd, width, height);
00370         OnLayoutChange();
00371     }
00372 
00373 // END OF C++ OGL USER FUNCS.
00375  
00383     virtual void Start()
00384     {
00385         Sys::Instance().Start(mOglWnd);
00386     }
00387 
00389 protected:
00390 
00391     OGLWND*         mOglWnd;
00392     int             mRunTimeType;
00393     OGLUSERFUNCS    mOldUserCFunctions;
00394     bool            mDone;
00395     bool            mIsDestructing;
00396     bool            mIsExiting;
00397 
00398     void GlueFuncs()
00399     {
00400         memcpy((void*) &mOldUserCFunctions, &(mOglWnd->userFuncs),
00401                sizeof(OGLUSERFUNCS));
00402 
00403         mOglWnd->userFuncs.initFunc = GlueInitFunc;
00404         mOglWnd->userFuncs.exitFunc = GlueExitFunc;
00405         mOglWnd->userFuncs.initDisplayFunc = GlueInitDisplayFunc;
00406         mOglWnd->userFuncs.displayFunc = GlueDisplayFunc;
00407         mOglWnd->userFuncs.mouseFunc = GlueMouseFunc;
00408         mOglWnd->userFuncs.keyboardFunc = GlueKeyboardFunc;
00409         mOglWnd->userFuncs.viewportFunc = GlueViewportFunc;
00410         mOglWnd->userFuncs.reshapeFunc = GlueReshapeFunc;
00411     }
00412 
00414 private:
00415 
00416     static int      mNr;
00417     int             mID;
00418 
00419     void
00420     Init()
00421     {
00422         if (!mOglWnd)
00423         {
00424             fprintf(stderr, "CreateOGLWND/ViewPort failed\n");
00425             return;
00426         }
00427 
00428         mRunTimeType = 1;
00429 
00430         oglSys.SetSysData(mOglWnd, 1, this);
00431         mID = mNr++;
00432         mIsDestructing = false;
00433         mIsExiting = false;
00434 
00435         GlueFuncs();
00436     }
00437 
00438 /*
00439     void GlueFuncs()
00440     {
00441         memcpy((void*) &mOldUserCFunctions, &(mOglWnd->userFuncs),
00442                sizeof(OGLUSERFUNCS));
00443 
00444         mOglWnd->userFuncs.initFunc = GlueInitFunc;
00445         mOglWnd->userFuncs.exitFunc = GlueExitFunc;
00446         mOglWnd->userFuncs.initDisplayFunc = GlueInitDisplayFunc;
00447         mOglWnd->userFuncs.displayFunc = GlueDisplayFunc;
00448         mOglWnd->userFuncs.mouseFunc = GlueMouseFunc;
00449         mOglWnd->userFuncs.keyboardFunc = GlueKeyboardFunc;
00450         mOglWnd->userFuncs.viewportFunc = GlueViewportFunc;
00451         mOglWnd->userFuncs.reshapeFunc = GlueReshapeFunc;
00452     }
00453 */
00454 
00455     static void
00456     GlueInitFunc(OGLWND* oglWnd)
00457     {
00458         GetOglWindow(oglWnd)->InitFunc();
00459     }
00460 
00461     static void 
00462     GlueExitFunc(OGLWND* oglWnd)
00463     {
00464         OglWindow *wnd = GetOglWindow(oglWnd);
00465         wnd->ExitFunc();
00466     }
00467     
00468     static void 
00469     GlueInitDisplayFunc(OGLWND* oglWnd)
00470     {
00471         GetOglWindow(oglWnd)->InitDisplayFunc();
00472     }
00473     
00474     static void 
00475     GlueDisplayFunc(OGLWND* oglWnd)
00476     {
00477         GetOglWindow(oglWnd)->DisplayFunc();
00478     }
00479     
00480     static void 
00481     GlueMouseFunc(OGLWND* oglWnd, INT msg, INT but, INT state, INT x, INT y)
00482     {
00483         oglSys.UpdateSceneFlag(oglWnd, 1);
00484         GetOglWindow(oglWnd)->MouseFunc(msg, but, state, x, y);
00485     }
00486     
00487     static void 
00488     GlueKeyboardFunc(OGLWND* oglWnd, INT c, INT state)
00489     {
00490         GetOglWindow(oglWnd)->KeyboardFunc(c, state);
00491         oglSys.UpdateSceneFlag(oglWnd, 1);
00492     }
00493     
00494     static void 
00495     GlueViewportFunc(OGLWND* oglWnd, INT width, INT height)
00496     {
00497         GetOglWindow(oglWnd)->ViewportFunc(width, height);
00498     }
00499     
00500     static void 
00501     GlueReshapeFunc(OGLWND* oglWnd, INT width, INT height)
00502     {
00503         GetOglWindow(oglWnd)->ReshapeFunc(width, height);
00504     }
00505 
00506 };
00507 
00508 } // namespace OglGui
00509 #endif

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