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 GetDimensions(pX, pY, pW, pH);
00100 mSizeKnob->GetDimensions(x, y, w, h);
00101
00102 x +=8; y +=8;
00103 if (pW != mOldWidth || pH != mOldHeight)
00104 {
00105 if (mScaleOnReshape)
00106 {
00107 float scaleX, scaleY;
00108 scaleX = x / (float) mOldWidth;
00109 scaleY = y / (float) mOldHeight;
00110 x = (int) (scaleX * pW);
00111 y = (int) (scaleY * pH);
00112 adjust = true;
00113 }
00114 mOldWidth = pW;
00115 mOldHeight = pH;
00116 }
00117
00118 if (x > pW - mMinimumWidth)
00119 x = pW - mMinimumWidth, adjust = true;
00120 if (x < mMinimumWidth)
00121 x = mMinimumWidth, adjust = true;
00122 if (y > pH - mMinimumHeight)
00123 y = pH - mMinimumHeight, adjust = true;
00124 if (y < mMinimumHeight)
00125 y = mMinimumHeight, adjust = true;
00126 x -=8; y -= 8;
00127
00128 if (adjust)
00129 {
00130 mSizeKnob->SetDimensions(x, y, w, h);
00131 OnLayoutChange();
00132 }
00133 Window::DisplayFunc();
00134 }
00135
00136 private:
00137
00138 SizableWindow* mSizeKnob;
00139 Window* mPanes[4];
00140 bool mLayedOut;
00141 int mMinimumWidth, mMinimumHeight;
00142 int mOldWidth, mOldHeight;
00143 int mScaleOnReshape;
00144
00145 void
00146 Init(int w, int h)
00147 {
00148 int i;
00149
00150 mLayedOut = false;
00151 mScaleOnReshape = true;
00152 mMinimumWidth = 80;
00153 mMinimumHeight = 80;
00154 mOldWidth = w;
00155 mOldHeight = h;
00156
00157 for (i=0; i<4; i++)
00158 mPanes[i] = 0;
00159 }
00160
00161 void
00162 DoConnect(Window* pane, int knobConnect, int frameConnect)
00163 {
00164 pane->ConnectTo(mSizeKnob, knobConnect );
00165 pane->ConnectTo(this, frameConnect);
00166 }
00167 };
00168
00169 }
00170
00171 #endif