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

ZoomControl.h

Go to the documentation of this file.
00001 #ifndef OglGui_ZoomControl_h
00002 #define OglGui_ZoomControl_h
00003 
00004 #ifndef OglGui_Button_h
00005 #include "OglGui/Button.h"
00006 #endif
00007 
00008 #ifndef OglGui_Slider_h
00009 #include "OglGui/Slider.h"
00010 #endif
00011 
00012 
00013 #ifndef OglGui_GroupBox_h
00014 #include "OglGui/GroupBox.h"
00015 #endif
00016 
00017 namespace OglGui
00018 {
00019 
00020 class ZoomControl : public GroupBox, SliderListener, ButtonListener
00021 {
00022 public:
00023 
00024     ZoomControl(int x, int y, int w, int h, int maxZoom) :
00025         GroupBox(x, y, w, h, "Zoom")
00026     {
00027         Init(w, h, maxZoom);
00028     }
00029 
00030     ZoomControl(Window* parent, int x, int y, int w, int h, int maxZoom) :
00031         GroupBox(parent, x, y, w, h, "Zoom")
00032     {
00033         Init(w, h, maxZoom);
00034     }
00035 
00036     ZoomControl(Window* parent, int w, int h, int maxZoom) :
00037         GroupBox(parent, w, h, "Zoom")
00038     {
00039         Init(w, h, maxZoom);
00040     }
00041 
00042     virtual void
00043     SliderChangedEvent(Slider *src, void* userData)
00044     {
00045         if (mTargetWindow == 0 || mAdjusting) return;
00046 
00047         float   val = mZoomSlider->Value() / 100.0f;
00048         if (mTargetIs2D)
00049             viewSys.ZoomTagged(mTargetWindow, selectedTag, 1, val, val, 0);
00050         else
00051             view3DSys.ZoomTagged(mTargetWindow, selectedTag, 1, val, val, 0);
00052     }
00053 
00054     virtual void
00055     ButtonSelectionEvent(Button *src, void* userData)
00056     {
00057         OGLWND *target = mTargetWindow;
00058         if (userData == (void*)0)
00059             if (mTargetIs2D)
00060                 viewSys.PanTagged(target, selectedTag, 1, 0.5f, 0.5f, 0);
00061             else
00062                 view3DSys.PanTagged(target, selectedTag, 1, 0.5f, 0.5f, 0);
00063         if (userData==(void*)1)
00064             if (mTargetIs2D)
00065                 viewSys.FitTagged(target, selectedTag, 1, 0);
00066             else
00067                 view3DSys.FitTagged(target, selectedTag, 1, 0);
00068         if (userData == (void*)2){
00069             if (mTargetIs2D){
00070                 viewSys.ZoomTagged(target, selectedTag, 1, 1.0f, 1.0f, 0);
00071                 viewSys.PanTagged(target, selectedTag, 1, 0.5f, 0.5f, 0);
00072             }
00073             else {
00074                 view3DSys.ZoomTagged(target, selectedTag, 1, 1.0f, 1.0f, 0);
00075                 view3DSys.PanTagged(target, selectedTag, 1, 0.5f, 0.5f, 0);
00076             }
00077             mZoomSlider->SetValue(100);
00078         }
00079     }
00080 
00081     virtual void
00082     DisplayFunc()
00083     {
00084         LIST    *obj;
00085         bool    enable = false;
00086 
00087         GroupBox::DisplayFunc();
00088         if (mTargetWindow){
00089             ForAllElements(obj, mTargetWindow->objectList){
00090                 if (mTargetIs2D){
00091                     OGLVIEW *v2d = (OGLVIEW *) obj->info;
00092                     if (enable=(viewSys.HasTags(v2d, selectedTag) ? true:false))
00093                     {
00094                         mAdjusting = true;
00095                         mZoomSlider->SetValue(v2d->zoomX*100);
00096                         mAdjusting = false;
00097                         break;
00098                     }
00099                 }
00100                 else {
00101                     OGLVIEW3D *v3d = (OGLVIEW3D *) obj->info;
00102                     if (enable=view3DSys.HasTags(v3d,selectedTag) ? true:false)
00103                         break;
00104                 }
00105             }
00106         }
00107 
00108         if (enable != (mZoomSlider->GetState() > 0))
00109         {
00110             mZoomSlider->SetState(enable ? 1 : 0);
00111             mCenterButton->SetState(enable ? 1 : 0);
00112             mFitButton->SetState(enable ? 1 : 0);
00113             mResetButton->SetState(enable ? 1 : 0);
00114         }
00115     }
00116 
00117     void
00118     SetZoomTarget(OGLWND *oW, bool is2d)
00119     {
00120         mTargetWindow = oW;
00121         mTargetIs2D = is2d;
00122     }
00123 
00124     void
00125     SetZoomTarget(Window *tW)
00126     {
00127         SetZoomTarget(tW->GetOGLWND(), tW->Is2d());
00128     }
00129 
00130     Slider* ZoomSlider()
00131     {
00132         return mZoomSlider;
00133     }
00134 
00135     Button* CenterButton()
00136     {
00137         return mCenterButton;
00138     }
00139     Button* FitButton()
00140     {
00141         return mFitButton;
00142     }
00143     Button* ResetButton()
00144     {
00145         return mResetButton;
00146     }
00147 
00148 private:
00149 
00150     Slider*       mZoomSlider;
00151     Button*       mCenterButton;
00152     Button*       mFitButton;
00153     Button*       mResetButton;
00154     OGLWND*       mTargetWindow;
00155     bool          mTargetIs2D;
00156     bool          mAdjusting;
00157 
00158     void
00159     Init(int w, int h, int maxZoom)
00160     {
00161         OGLWND  *oW = GetOGLWND();
00162 
00163         mTargetWindow = 0;
00164         mAdjusting = false;
00165         h -= 22;
00166 
00167         mZoomSlider = new Slider(this, 4, h - (2*h)/3+4, w-8, (2*h)/3-4, 0,
00168                                  maxZoom*100, 100, BEV_RAISED, 16);
00169         mZoomSlider->SetIncrement(10);
00170         mZoomSlider->SetShowValPerc(true);
00171         mZoomSlider->SetSliderListener(this);
00172         
00173         mCenterButton = new Button(this, 4, 4, (w-18)/3, h/3 - 4, "Center");
00174         mCenterButton->SetButtonListener(this);
00175         mFitButton = new Button(this, (w-18)/3 + 10, 4, (w-18)/3, h/3 - 4,
00176                                 "Fit");
00177         mFitButton->SetButtonListener(this, (void*)1);
00178         mResetButton = new Button(this, (2*(w-18))/3 + 16, 4, (w-18)/3,
00179                                   h/3 - 4, "Reset");
00180         mResetButton->SetButtonListener(this, (void*)2);
00181 
00182         ScaleChildren();
00183         SetAllowChildScaling(false);
00184 
00185         SetDisableOGLViewKeys(true);
00186         SetDisableOGLViewMouse(true);
00187     }
00188 };
00189 
00190 } // namespace OglGui
00191 
00192 #endif

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