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

WindowView2DWithRect.h

Go to the documentation of this file.
00001 #ifndef Application_IDash_WindowView2DWithRect_h
00002 #define Application_IDash_WindowView2DWithRect_h
00003 
00004 #ifndef OglGui_RepeatTimer_h
00005 #include "OglGui/RepeatTimer.h"
00006 #endif
00007 
00008 #ifndef OglGui_Window_h
00009 #include "OglGui/Window.h"
00010 #endif
00011 
00012 #ifndef OglGui_WindowView2DListener_h
00013 #include "OglGui/WindowView2DListener.h"
00014 #endif
00015 
00016 #ifndef OglGui_SetImageInterface_h
00017 #include "OglGui/SetImageInterface.h"
00018 #endif
00019 
00020 #include "Core/Geometry/Rectangle.h"
00021 
00022 namespace OglGui
00023 {
00024 
00025 class WindowView2DWithRectListener
00026 {
00027 public:
00028     virtual void
00029     OnRectangleSelect(float x, float y, float w, float h)
00030     {
00031 
00032     }
00033 };
00034 
00035 class WindowView2DWithRect : public StaticText,
00036                      public RepeatTimer,
00037                      public SetImageInterface
00038 {
00039 public:
00040 
00041     WindowView2DWithRect(int x, int y, int w, int h, OGLIMAGE *oglIm=0):
00042         StaticText(x, y, w, h, "")
00043     {
00044         Init(oglIm, "");
00045     }
00046 
00047     WindowView2DWithRect(Window* parent, int x, int y, int w, int h, OGLIMAGE *oglIm=0):
00048         StaticText(parent, x, y, w, h, "")
00049     {
00050         Init(oglIm, "");
00051     }
00052 
00053     WindowView2DWithRect(Window* parent, int w, int h, OGLIMAGE *oglIm=0) :
00054         StaticText(parent, w, h, "")
00055     {
00056         Init(oglIm, "");
00057     }
00058 
00059     void
00060     SetWndView2DListener(WindowView2DListener* listener, void* listenerData = 0)
00061     {
00062         mWndView2DListener = listener;
00063         mListenerData = listenerData;
00064     }
00065 
00066 /*
00067     void CenterStr(int dX, int dY)
00068     {
00069         int     tW, tH;
00070         oglSys.GetTextExtent(mOglWnd, (char *) mLabel.c_str(), &tW, &tH);
00071 
00072         ULONG   shadCol = GetState() ? oglLIGHTGREY : oglGREY;
00073         ULONG   foreCol = GetState() ? oglBLACK : oglLIGHTGREY;
00074         int w = WndWidth(), h = WndHeight();
00075         oglSys.ShadowPrintf(mOglWnd, w/2 - tW/2 + dX, h/2 - tH/2 + dY,
00076                             shadCol, foreCol, "%s", mLabel.c_str());
00077     }
00078 */
00079     virtual void DisplayFunc()
00080     {
00081         int w = mOglWnd->width;
00082         int h = mOglWnd->height;
00083 
00084         viewSys.SetDimensions(mView, 0, 0, w, h);
00085 
00086         if (mScaleToWnd && mView->im)
00087             viewSys.SetZoom(mView, w / (float) mView->im->w,
00088                             h / (float) mView->im->h);
00089 
00090         if (mActAsButton && mIsPressed)
00091         {
00092             mOldBorderType = GetBorderType();
00093             mView->x++; mView->y--;
00094         }
00095         StaticText::DisplayFunc();
00096 
00097         if (mActAsButton && mIsPressed){
00098             SetBorderType(mOldBorderType);
00099             mView->x--; mView->y++;
00100         }
00101 
00102         if (mIsDragging) {
00103             OGC prevOGC;
00104             OGCSave( &prevOGC );
00105             SetLineWidth(2);
00106             SetSolidLineColor(0xffdddd22);
00107             DrawRectangle(mDragLX, mDragLY, mDragHX - mDragLX, mDragHY - mDragLY);
00108             OGCRestore( &prevOGC );
00109         }
00110 
00111         //CenterStr(mIsPressed ? 1 : 0, mIsPressed ? 2 : 3);
00112     }
00113 
00114     virtual void MouseFunc(INT msg, INT but, INT state, INT x, INT y)
00115     {
00116         Window::MouseFunc(msg, but, state, x, y);
00117 
00118         int w = mOglWnd->width;
00119         int h = mOglWnd->height;
00120 
00121 
00122         if (msg == oglMouseDown && but == oglLeftButton) {
00123             if (mIsDragging) {
00124                 // execute if click within box, cancel if outside:
00125                 if (mDragLX <= x && x <= mDragHX && mDragLY <= y && y <= mDragHY) {
00126                     float sx, sy, sw, sh;
00127                     sx = mDragLX;
00128                     sy = mDragLY;
00129                     sw = mDragHX - mDragLX;
00130                     sh = mDragHY - mDragLY;
00131                     if (sw > 1 && sh > 1) {
00132                         // coordinates based on upper-left = 0,0 instead of lower-left = 0,0
00133 //                        ILOG_DEBUG(" SELECT: " << sx / w << ", " << 1.0 - (sy/h + sh/h) << ", " << sw/w << ", " <<sh/h);
00134                         if (mListener)
00135                         mListener->OnRectangleSelect(sx/w, 1.0 - (sy/h + sh/h), sw/w, sh/h);
00136                     }
00137                 }
00138                 mIsDragging = false;
00139                 return;
00140             } else {
00141                 mDragLX = mDragHX = x;
00142                 mDragLY = mDragHY = y;
00143                 mIsDragging = true;
00144             }
00145         }
00146 
00147         if (msg == oglMouseMove && mIsDragging) {
00148             if (x < mDragLX) mDragLX = x;
00149             if (x > mDragHX) mDragHX = x;
00150             if (y < mDragLY) mDragLY = y;
00151             if (y > mDragHY) mDragHY = y;
00152 
00153             if (mDragLX < 0) mDragLX = 0;
00154             if (mDragLY < 0) mDragLY = 0;
00155             if (mDragHX > w) mDragHX = w;
00156             if (mDragHY > h) mDragHY = h;
00157         }
00158     }
00159 
00160     virtual void
00161     KeyboardFunc(INT c, INT state)
00162     {
00163         if (!mActAsButton && c >= oglUP && c <= oglESC)
00164             Window::KeyboardFunc(c, state | oglControl);
00165     }
00166 
00167     void SetActAsButton(bool b)
00168     {
00169         mActAsButton = b;
00170     }
00171 
00172     void SetRepeatMode(bool b=true)
00173     {
00174         mRepeatMode = b;
00175     }
00176 
00177     bool IsPressed()
00178     {
00179         return mIsPressed;
00180     }
00181 
00182     void SetPressed(bool pressed)
00183     {
00184         mIsPressed = pressed;
00185     }
00186 
00187     void SetScaleToWindow(bool scale=true)
00188     {
00189         mScaleToWnd = scale;
00190     }
00191 
00192     bool GetScaleToWindow() const
00193     {
00194         return mScaleToWnd;
00195     }
00196 
00197     virtual void SetImage(OGLIMAGE* oglIm)
00198     {
00199         viewSys.SetImage(mView, oglIm);
00200     }
00201 
00202     OGLVIEW* GetOglView() const
00203     {
00204         return mView;
00205     }
00206 
00207     void
00208     SetListener(WindowView2DWithRectListener* listener)
00209     {
00210         mListener = listener;
00211     }
00212 
00213 private:
00214 
00215     void Init(OGLIMAGE *oglIm, strconst label)
00216     {
00217         mWndView2DListener = 0;
00218         mRepeatMode = false;
00219         SetRepeatDelays(400, 20);
00220         mIsPressed = false;
00221         mActAsButton = false;
00222         mScaleToWnd = true;
00223 
00224         SetBorderType(BEV_ETCHED);
00225         mOglWnd->clipRounded = 1;
00226         mImageH = oglIm->h;
00227         mImageW = oglIm->w;
00228         mView = viewSys.View2D(mOglWnd, oglIm, 0, 0, WndWidth(), WndHeight());
00229         mView->texturing = 1;
00230         viewSys.SetTags(mView, selectedTag | visibleTag | showTitleTag |
00231                         showTextTag | zoomableTag | panableTag);
00232 
00233         mIsDragging = false;
00234         mListener = NULL;
00235     }
00236 
00237 protected:
00238     WindowView2DListener*   mWndView2DListener;
00239     void*                   mListenerData;
00240     OGLVIEW*                mView;
00241     int                     mImageW;
00242     int                     mImageH;
00243     bool                    mActAsButton;
00244     bool                    mRepeatMode;
00245     bool                    mIsPressed;
00246     bool                    mScaleToWnd;
00247     int                     mOldBorderType;
00248     WindowView2DWithRectListener *mListener;
00249 
00250     int mDragLX, mDragHX;
00251     int mDragLY, mDragHY;
00252     bool mIsDragging;
00253     int mKeyframeID;
00254 
00255     ILOG_VAR_DEC;
00256 };
00257 
00258 ILOG_VAR_INIT(WindowView2DWithRect, Application.IDash);
00259 
00260 
00261 } // namespace OglGui
00262 #endif

Generated on Fri Mar 19 09:30:27 2010 for ImpalaSrc by  doxygen 1.5.1