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

TwoPanesWindow.h

Go to the documentation of this file.
00001 #ifndef OglGui_TwoPanesWindow_h
00002 #define OglGui_TwoPanesWindow_h
00003 
00004 /*
00005  *
00006  * changelog:
00007  * 14-5-06 Ork de Rooij: added mStartPos code in LayoutWindow
00008  */
00009 
00010 #ifndef SizableWindow_h
00011 #include "OglGui/SizableWindow.h"
00012 #endif
00013 
00014 namespace OglGui
00015 {
00016 
00017 class TwoPanesWindow : public Window
00018 {
00019 public:
00020 
00021     TwoPanesWindow(int x, int y, int w, int h, bool isHor=false) :
00022         Window(x, y, w, h)
00023     {
00024         Init(w, h, isHor);
00025     }
00026 
00027     TwoPanesWindow(Window *parent, int w, int h, bool isHor=false) :
00028         Window(parent, w, h)
00029     {
00030         Init(w, h, isHor);
00031     }
00032 
00033     TwoPanesWindow(Window *parent, int x, int y, int w, int h,bool isHor=false):
00034         Window( parent, x, y, w, h )
00035     {
00036         Init(w, h, isHor);
00037     }
00038 
00039     void LayoutPanes(bool mOwnStartPos = false, int mStartPos = 0)
00040     {
00041         int x,y,w,h;
00042 
00043         if( mLayedOut )
00044             return;
00045 
00046         mLayedOut = true;
00047 
00048         GetDimensions(x,y,w,h);
00049 
00050                 if (! mOwnStartPos) {
00051                     for (int i=0; i<2; i++)
00052                     {
00053                      if (mPanes[i] && mIsHor)
00054                             mPanes[i]->SetDimensions(0, i*h/2+(i?4:0), w, h/2-4);
00055                         else if (mPanes[i] && !mIsHor)
00056                         mPanes[i]->SetDimensions(i*w/2+(i?4:0), 0, w/2-4, h);
00057                         }
00058                 } else {
00059                         for (int i=0; i<2; i++)
00060                     {
00061                                 int l = mStartPos;
00062                                 int r = w - mStartPos;
00063                                 if (mPanes[i] && mIsHor)
00064                                         mPanes[i]->SetDimensions(0, i?l+4:0, w, i?r-4:l-4);
00065                         else if (mPanes[i] && !mIsHor)
00066                                         mPanes[i]->SetDimensions(i?l+4:0, 0, i?r-4:l-4, h);
00067                         }
00068 
00069                 }
00070 
00071 
00072         if (mIsHor)
00073         {
00074                         if (mOwnStartPos)
00075                     mSizeBar = new SizableWindow( this, 0, mStartPos-4, w, 8 );
00076                         else
00077                                 mSizeBar = new SizableWindow( this, 0, h/2-4, w, 8 );
00078     
00079             mSizeBar->SetAllowMoveDirections(SizableWindow::EastWest, false);
00080             mSizeBar->ConnectTo(this, L2L | R2R | TPARENT);
00081         }
00082         else
00083         {
00084                         if (mOwnStartPos)
00085                     mSizeBar = new SizableWindow( this, mStartPos - 4, 0, 8, h );
00086                         else
00087                                 mSizeBar = new SizableWindow( this, w/2-4, 0, 8, h );
00088             mSizeBar->SetAllowMoveDirections(SizableWindow::NorthSouth, false);
00089             mSizeBar->ConnectTo(this, T2T | B2B | TPARENT);
00090         }
00091 
00092         mSizeBar->SetAllowSizeDirections(SizableWindow::AllDir, false);
00093         mSizeBar->SetMoveCursor(mIsHor ? oglCursorN : oglCursorE);
00094 //        mSizeBar->SetMoveCursor(mIsHor ? oglCursorNS : oglCursorWE);
00095         mSizeBar->SetBorderBackground( 0x80ff8080 );
00096         mSizeBar->SetMoveFeedback( true );
00097         mSizeBar->SetDoStateFeedback( true );
00098 
00099         if (mPanes[0])
00100             DoConnect(mPanes[0], mIsHor ? T2B : R2L,
00101                       TPARENT | (mIsHor ? B2B | L2L | R2R : B2B | T2T| L2L));
00102 
00103         if (mPanes[1])
00104             DoConnect(mPanes[1], mIsHor ? B2T : L2R,
00105                       TPARENT | (mIsHor ? T2T | L2L | R2R : B2B | T2T | R2R));
00106 
00107         SetReposChildren( false, false );
00108     }
00109 
00110         virtual void ReshapeFunc(int width, int height)
00111         {
00112                 Window::ReshapeFunc(width, height);
00113                 if (mLockToOther) {
00114                         // window is reshaping and the slider wants to be locked to the
00115             // other side: move it with the difference.
00116                         int oldpos,na,nb,nc;
00117                         if (mIsHor)
00118             {
00119                                 mSizeBar->GetDimensions(na ,oldpos, nb, nc);
00120                                 mSizeBar->SetDimensions(0,oldpos+height-mOldHeight, width, 8 );
00121                         } 
00122             else
00123             {
00124                                 mSizeBar->GetDimensions(oldpos,na , nb, nc);
00125                                 mSizeBar->SetDimensions(oldpos+width-mOldWidth, 0, 8, height );
00126                         }
00127 
00128                 }
00129                 mOldHeight = height;
00130                 mOldWidth = width;
00131         }
00132 
00133         void SetMovable(bool isMovable) {
00134                 if (isMovable) {
00135                         mSizeBar->SetAllowMoveDirections(SizableWindow::AllDir, true);
00136                         mSizeBar->
00137                 SetAllowMoveDirections(mIsHor ? SizableWindow::EastWest :
00138                                        SizableWindow::NorthSouth, false);
00139                         mSizeBar->SetMoveCursor(mIsHor ? oglCursorN : oglCursorE);
00140                 } else {
00141                         mSizeBar->SetAllowMoveDirections(SizableWindow::AllDir, false);
00142                         mSizeBar->SetMoveCursor(0);
00143                 }
00144         }
00145 
00146         void SetLockToOtherSide(bool lockToOther) {
00147                 mLockToOther = lockToOther;
00148         }
00149 
00150 
00151     void RegisterPane(Window *paneWnd, int i)
00152     {
00153         if (i > 2 || mPanes[i] != 0)
00154             return;
00155 
00156         mPanes[i] = paneWnd;
00157     }
00158 
00159     void SetMinPaneSize( int sz )
00160     {
00161         mMinSize = sz;
00162     }
00163 
00164     SizableWindow* SizeBar()
00165     {
00166         return mSizeBar;
00167     }
00168 
00169     virtual void DisplayFunc()
00170     {
00171         int     pX,pY,pW,pH;
00172         int     x,y,w,h;
00173         bool    adjust = false;
00174 
00175         GetDimensions(pX, pY, pW, pH);
00176         mSizeBar->GetDimensions(x, y, w, h);
00177 
00178         x +=4; y +=4;
00179 
00180         if (mIsHor)
00181         {
00182             if( y > pH - mMinSize )
00183                 y = pH - mMinSize, adjust = true;
00184             if( y < mMinSize )
00185                 y = mMinSize, adjust = true;
00186         }
00187         else
00188         {
00189             if( x > pW - mMinSize )
00190                 x = pW - mMinSize, adjust = true;
00191             if( x < mMinSize )
00192                 x = mMinSize, adjust = true;
00193         }
00194         x -=4; y -= 4;
00195 
00196         if( adjust )
00197         {
00198             mSizeBar->SetDimensions( x, y, w, h );
00199             OnLayoutChange();
00200         }
00201         Window::DisplayFunc();
00202     }
00203 
00204 private:
00205 
00206     SizableWindow*  mSizeBar;
00207     Window*         mPanes[2];
00208     bool            mIsHor;
00209     bool            mLayedOut;
00210     int             mMinSize;
00211 
00212         int                             mOldWidth, mOldHeight;
00213         bool                    mLockToOther;
00214 
00215     void
00216     Init( int w, int h, bool isHor)
00217     {
00218         mIsHor = isHor;
00219         mLayedOut = false;
00220         mMinSize = 0;
00221         mPanes[0] = 0;
00222         mPanes[1] = 0;
00223         mOldWidth = w;
00224         mOldHeight = h;
00225         mLockToOther = false;
00226     }
00227 
00228     void
00229     DoConnect( Window* pane, int knobConnect, int frameConnect )
00230     {
00231         pane->ConnectTo( mSizeBar, knobConnect  );
00232         pane->ConnectTo( this, frameConnect );
00233     }
00234 };
00235 
00236 } //namespace OglGui
00237 #endif

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