00001 #ifndef OglGui_WindowView2D_h
00002 #define OglGui_WindowView2D_h
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef OglGui_RepeatTimer_h
00012 #include "OglGui/RepeatTimer.h"
00013 #endif
00014
00015 #ifndef OglGui_StaticText_h
00016 #include "OglGui/StaticText.h"
00017 #endif
00018
00019 #ifndef OglGui_WindowView2DListener_h
00020 #include "OglGui/WindowView2DListener.h"
00021 #endif
00022
00023 #ifndef OglGui_SetImageInterface_h
00024 #include "OglGui/SetImageInterface.h"
00025 #endif
00026
00027 namespace OglGui
00028 {
00029
00030 class WindowView2D : public StaticText,
00031 public RepeatTimer,
00032 public SetImageInterface
00033 {
00034 public:
00035
00036 WindowView2D(int x, int y, int w, int h, OGLIMAGE *oglIm=0):
00037 StaticText(x, y, w, h, "")
00038 {
00039 Init(oglIm, "");
00040 }
00041
00042 WindowView2D(Window* parent, int x, int y, int w, int h, OGLIMAGE *oglIm=0):
00043 StaticText(parent, x, y, w, h, "")
00044 {
00045 Init(oglIm, "");
00046 }
00047
00048 WindowView2D(Window* parent, int w, int h, OGLIMAGE *oglIm=0) :
00049 StaticText(parent, w, h, "")
00050 {
00051 Init(oglIm, "");
00052 }
00053
00054 void
00055 SetWndView2DListener(WindowView2DListener* listener, void* listenerData = 0)
00056 {
00057 mWndView2DListener = listener;
00058 mListenerData = listenerData;
00059 }
00060
00061 void Texturing(bool mode) { mView->texturing = mode ? 1 : 0; }
00062 bool Texturing() { return mView->texturing ? true : false; }
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 virtual void DisplayFunc()
00078 {
00079 int w = mOglWnd->width;
00080 int h = mOglWnd->height;
00081
00082 viewSys.SetDimensions(mView, 0, 0, w, h);
00083
00084 if (mScaleToWnd && mView->im)
00085 viewSys.SetZoom(mView, w / (float) mView->im->w,
00086 h / (float) mView->im->h);
00087
00088 if (mRepeatMode && mIsPressed && RepeatTime() &&
00089 mWndView2DListener && GetState())
00090 {
00091 mWndView2DListener->SelectionEvent(this, mListenerData);
00092 }
00093
00094 if (mActAsButton && mIsPressed)
00095 {
00096 mOldBorderType = GetBorderType();
00097 mView->x++; mView->y--;
00098 }
00099 StaticText::DisplayFunc();
00100
00101 if (mActAsButton && mIsPressed){
00102 SetBorderType(mOldBorderType);
00103 mView->x--; mView->y++;
00104 }
00105
00106
00107 }
00108
00109 virtual void MouseFunc(INT msg, INT but, INT state, INT x, INT y)
00110 {
00111 Window::MouseFunc(msg, but, state, x, y);
00112
00113 if ((msg == oglMouseDown) && (but == oglLeftButton) && GetState()){
00114 mIsPressed = true;
00115 if (mActAsButton && mRepeatMode)
00116 {
00117 StartRepeatTime();
00118 oglSys.SetAlwaysDraw(mOglWnd, true);
00119 if (mWndView2DListener)
00120 mWndView2DListener->SelectionEvent(this, mListenerData);
00121 }
00122 }
00123 if (msg == oglMouseMove && (state & oglLeftButton))
00124 mIsPressed = x<0 || x>mOglWnd->width || y<0 || y>mOglWnd->height;
00125
00126
00127
00128
00129
00130
00131 if (msg == oglMouseUp){
00132 if (mActAsButton && !mRepeatMode && mIsPressed && mWndView2DListener){
00133 mIsPressed = false;
00134 mWndView2DListener->SelectionEvent(this, mListenerData);
00135 }
00136 mIsPressed = false;
00137 oglSys.SetAlwaysDraw(mOglWnd, false);
00138 oglSys.UpdateSceneFlag(mOglWnd, 1);
00139 }
00140 }
00141
00142 virtual void
00143 KeyboardFunc(INT c, INT state)
00144 {
00145 if (!mActAsButton && c >= oglUP && c <= oglESC)
00146 Window::KeyboardFunc(c, state | oglControl);
00147
00148
00149
00150
00151
00152 }
00153
00154 void SetActAsButton(bool b)
00155 {
00156 mActAsButton = b;
00157 }
00158
00159 void SetRepeatMode(bool b=true)
00160 {
00161 mRepeatMode = b;
00162 }
00163
00164 bool IsPressed()
00165 {
00166 return mIsPressed;
00167 }
00168
00169 void SetPressed(bool pressed)
00170 {
00171 mIsPressed = pressed;
00172 }
00173
00174 void SetScaleToWindow(bool scale=true)
00175 {
00176 mScaleToWnd = scale;
00177 }
00178
00179 bool GetScaleToWindow() const
00180 {
00181 return mScaleToWnd;
00182 }
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195 virtual void SetImage(OGLIMAGE* oglIm)
00196 {
00197 viewSys.SetImage(mView, oglIm);
00198 }
00199 virtual OGLIMAGE* GetImage()
00200 {
00201 return viewSys.GetImage(mView);
00202 }
00203
00204 OGLVIEW* GetOglView() const
00205 {
00206 return mView;
00207 }
00208
00209 private:
00210
00211 void Init(OGLIMAGE *oglIm, strconst label)
00212 {
00213 mWndView2DListener = 0;
00214 mRepeatMode = false;
00215 SetRepeatDelays(400, 20);
00216 mIsPressed = false;
00217 mActAsButton = false;
00218 mScaleToWnd = true;
00219
00220 SetBorderType(BEV_ETCHED);
00221 mOglWnd->clipRounded = 1;
00222 mView = viewSys.View2D(mOglWnd, oglIm, 0, 0, WndWidth(), WndHeight());
00223 mView->texturing = 1;
00224 viewSys.SetTags(mView, selectedTag | visibleTag | showTitleTag |
00225 showTextTag | zoomableTag | panableTag);
00226 }
00227
00228 protected:
00229 WindowView2DListener* mWndView2DListener;
00230 void* mListenerData;
00231 OGLVIEW* mView;
00232 bool mActAsButton;
00233 bool mRepeatMode;
00234 bool mIsPressed;
00235 bool mScaleToWnd;
00236 int mOldBorderType;
00237 };
00238
00239 }
00240 #endif