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

PlotNeedle.h

Go to the documentation of this file.
00001 //345678901234567890123456789012345678901234567890123456789012345678901234567890
00002 // Author: Richard van Balen
00003 // Interactive needle for a Plot.
00004 
00005 #ifndef Impala_Visualisation_Plot_PlotNeedle_h
00006 #define Impala_Visualisation_Plot_PlotNeedle_h
00007 
00008 #include "Link/OGL/OGLWnd.h"
00009 #include "Visualization/Plot/Line.h"
00010 #include "Visualization/Plot/PlotNeedleListener.h"
00011 
00012 namespace Impala {
00013 namespace Visualization {
00014 namespace Plot {
00015 
00016 class PlotNeedle : public Line
00017 {
00018 public:
00019     PlotNeedle(double minX, double maxX, double x, double top, double bottom) :
00020         Line(0.0, false)
00021     {
00022         Init(minX, maxX, x, top, bottom);
00023     }
00024 
00025     void SetPlotNeedleListener(PlotNeedleListener* li, void* userData)
00026     {
00027         mListener = li;
00028         mListenerData = userData;
00029     }
00030 
00031     double Value()
00032     {
00033         return mX;
00034     }
00035 
00036     void SetTopBottom(double top, double bottom)
00037     {
00038         mNeedleData[0] = top;
00039         mNeedleData[1] = bottom;
00040         SetData((double *) &mNeedleData,2);
00041     }
00042 
00043     void SetMinMaxX(double minX, double maxX)
00044     {
00045         mNeedleMinX = minX;
00046         mNeedleMaxX = maxX;
00047     }
00048 
00049     void SetRoundOffset(double rOff)
00050     {
00051         mRoundOffset = rOff;
00052     }
00053 
00054     void MoveTo(double x)
00055     {
00056         if (mX == x)
00057             return;
00058         mX = x;
00059         if (mX < mNeedleMinX)
00060             mX = mNeedleMinX;
00061         if (mX > mNeedleMaxX)
00062             mX = mNeedleMaxX;
00063         SetDomain(mX, mX);
00064         if (mListener)
00065         {
00066             printf("PlotNeedle to listener: %f\n", mX);
00067             mListener->PlotNeedleChanged(this, mX, mListenerData);
00068         }
00069     }
00070 
00071     virtual void
00072     OnMouse(double x, double y, int msg, int but, int state)
00073     {
00074         if (state & (oglShift | oglControl))
00075             return;
00076 
00077         if (msg == oglMouseDown && but == oglLeftButton)
00078         {
00079             mDragging = true;
00080             MoveTo(x+mRoundOffset);
00081         }
00082         if (mDragging && msg == oglMouseMove && (state & oglLeftButton))
00083             MoveTo(x+mRoundOffset);
00084 
00085         if (!(state & oglLeftButton) && mDragging)
00086             mDragging = false;
00087     }
00088 
00089 private:
00090     void Init(double minX, double maxX, double x, double top, double bottom)
00091     {
00092         mListener = 0;
00093         mX = x;
00094         SetMinMaxX(minX,maxX);
00095         SetTopBottom(top, bottom);
00096         mRoundOffset = 0.0;
00097         mDragging = false;
00098     }
00099 
00100     PlotNeedleListener* mListener;
00101     void*               mListenerData;
00102 
00103     double  mNeedleData[2];
00104     double  mX, mNeedleMinX, mNeedleMaxX;
00105     double  mRoundOffset;
00106     bool    mDragging;
00107 };
00108 
00109 }//namespace Plot
00110 }//namespace Visualization
00111 }//namespace Impala
00112 
00113 #endif Impala_Visualisation_Plot_Line_h

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