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

FourPanesWindow.h

Go to the documentation of this file.
00001 #ifndef OglGui_FourPanesWindow_h
00002 #define OglGui_FourPanesWindow_h
00003 
00004 #ifndef Window_h
00005 #include "OglGui/Window.h"
00006 #endif
00007 
00008 #ifndef SizableWindow_h
00009 #include "OglGui/SizableWindow.h"
00010 #endif
00011 
00012 namespace OglGui
00013 {
00014 
00015 class FourPanesWindow : public Window
00016 {
00017 public:
00018 
00019     FourPanesWindow(int x, int y, int w, int h) :
00020         Window(x, y, w, h)
00021     {
00022         Init(w, h);
00023     }
00024 
00025     FourPanesWindow(Window *parent, int w, int h) :
00026         Window(parent, w, h)
00027     {
00028         Init(w, h);
00029     }
00030 
00031     FourPanesWindow(Window *parent, int x, int y, int w, int h) :
00032         Window(parent, x, y, w, h)
00033     {
00034         Init(w, h);
00035     }
00036 
00037     void LayoutPanes()
00038     {
00039         int x,y,w,h;
00040 
00041         if (mLayedOut)
00042             return;
00043 
00044         mLayedOut = true;
00045 
00046         GetDimensions(x,y,w,h);
00047 
00048         for (int i=0; i<4; i++)
00049             if (mPanes[i])
00050                 mPanes[i]->SetDimensions((i%2)*w/2, (i/2)*h/2, w/2, h/2);
00051 
00052         mSizeKnob = new SizableWindow(this, w/2-8, h/2-8, 16, 16);
00053         mSizeKnob->SetAllowSizeDirections(SizableWindow::AllDir, false);
00054         mSizeKnob->SetBorderBackground(0x80ff0000);
00055         mSizeKnob->SetMoveFeedback(true);
00056         mSizeKnob->SetDoStateFeedback(true);
00057 
00058         if (mPanes[0])
00059             DoConnect(mPanes[0], T2B | R2L, B2B | L2L);
00060         if (mPanes[1])
00061             DoConnect(mPanes[1], T2B | L2R, B2B | R2R);
00062         if (mPanes[2])
00063             DoConnect(mPanes[2], B2T | R2L, T2T | L2L);
00064         if (mPanes[3])
00065             DoConnect(mPanes[3], B2T | L2R, T2T | R2R);
00066 
00067         SetReposChildren(false, false);
00068     }
00069 
00070     void RegisterPane(Window *paneWnd, int i)
00071     {
00072         if (i > 4 || mPanes[i] != 0) return;
00073 
00074         mPanes[i] = paneWnd;
00075     }
00076 
00077     void SetScaleOnReshape(bool mode)
00078     {
00079         mScaleOnReshape = mode;
00080     }
00081 
00082     void SetMinimumPaneSizes(int w=80, int h=80)
00083     {
00084         mMinimumWidth = w;
00085         mMinimumHeight = h;
00086     }
00087 
00088     SizableWindow* SizeKnob()
00089     {
00090         return mSizeKnob;
00091     }
00092 
00093     virtual void DisplayFunc()
00094     {
00095         int     pX,pY,pW,pH;
00096         int     x,y,w,h;
00097         bool    adjust = false;
00098 
00099         if (!mLayedOut)
00100             LayoutPanes();
00101 
00102         GetDimensions(pX, pY, pW, pH);
00103         mSizeKnob->GetDimensions(x, y, w, h);
00104 
00105         x +=8; y +=8;
00106         if (pW != mOldWidth || pH != mOldHeight)
00107         {
00108             if (mScaleOnReshape)
00109             {
00110                 float   scaleX, scaleY;
00111                 scaleX = x / (float) mOldWidth;
00112                 scaleY = y / (float) mOldHeight;
00113                 x = (int) (scaleX * pW);
00114                 y = (int) (scaleY * pH);
00115                 adjust = true;
00116             }
00117             mOldWidth = pW;
00118             mOldHeight = pH;
00119         }
00120 
00121         if (x > pW - mMinimumWidth)
00122             x = pW - mMinimumWidth, adjust = true;
00123         if (x < mMinimumWidth)
00124             x = mMinimumWidth, adjust = true;
00125         if (y > pH - mMinimumHeight)
00126             y = pH - mMinimumHeight, adjust = true;
00127         if (y < mMinimumHeight)
00128             y = mMinimumHeight, adjust = true;
00129         x -=8; y -= 8;
00130 
00131         if (adjust)
00132         {
00133             mSizeKnob->SetDimensions(x, y, w, h);
00134             OnLayoutChange();
00135         }
00136         Window::DisplayFunc();
00137     }
00138 
00139 private:
00140 
00141     SizableWindow* mSizeKnob;
00142     Window*        mPanes[4];
00143     bool           mLayedOut;
00144     int            mMinimumWidth, mMinimumHeight;
00145     int            mOldWidth, mOldHeight;
00146     int            mScaleOnReshape;
00147 
00148     void
00149     Init(int w, int h)
00150     {
00151         int i;
00152 
00153         mLayedOut = false;
00154         mScaleOnReshape = true;
00155         mMinimumWidth = 80;
00156         mMinimumHeight = 80;
00157         mOldWidth = w;
00158         mOldHeight = h;
00159 
00160         for (i=0; i<4; i++)
00161             mPanes[i] = 0;
00162    }
00163 
00164     void
00165     DoConnect(Window* pane, int knobConnect, int frameConnect)
00166     {
00167         pane->ConnectTo(mSizeKnob, knobConnect );
00168         pane->ConnectTo(this, frameConnect);
00169     }
00170 };
00171 
00172 } // namespace OglGui
00173 
00174 #endif

Generated on Thu Jan 13 09:04:50 2011 for ImpalaSrc by  doxygen 1.5.1