00001 #ifndef Impala_Visualization_VideoNav_h
00002 #define Impala_Visualization_VideoNav_h
00003
00004 #include "Visualization/Window.h"
00005 #include "Core/Stream/RgbDataSrc.h"
00006 #include "Visualization/VideoNavListener.h"
00007
00008 namespace Impala {
00009 namespace Visualization {
00010
00011 class VideoNav : public Window
00012 {
00013 public:
00014 typedef Core::Stream::RgbDataSrc RgbDataSrc;
00015
00016 VideoNav(int x, int y, RgbDataSrc* src, double viewScale = 1.0,
00017 bool allowJump = true) :
00018 Window(x, y, viewScale * src->FrameWidth(),
00019 viewScale * src->FrameHeight() + 25, true)
00020 {
00021 Init(src, allowJump, viewScale);
00022 }
00023
00024 VideoNav(OglGui::Window* parent, RgbDataSrc* src, double viewScale = 1.0,
00025 bool allowJump = true) :
00026 Window(parent, viewScale * src->FrameWidth() + 2,
00027 viewScale * src->FrameHeight() + 2 + 25, true)
00028 {
00029 Init(src, allowJump, viewScale);
00030 }
00031
00032 VideoNav(OglGui::Window* parent, int frameWidth, int frameHeight,
00033 double viewScale = 1.0, bool allowJump = true) :
00034 Window(parent, viewScale * frameWidth + 2,
00035 viewScale * frameHeight + 2 + 25, true)
00036 {
00037 Init(0, allowJump, viewScale);
00038 }
00039
00040 void SetVideoNavListener(VideoNavListener* listener, void* listenerData = 0)
00041 {
00042 mVideoNavListener = listener;
00043 mListenerData = listenerData;
00044 }
00045
00046 void SetRect(Core::Geometry::Rectangle rect)
00047 {
00048 ViewWithRect* view = GetViewWithRect(0);
00049 if (view)
00050 view->SetRect(rect);
00051 }
00052
00053 Core::Geometry::Rectangle
00054 GetRect()
00055 {
00056 return GetViewWithRect(0)->GetRect();
00057 }
00058
00059 void ToggleHashValueDisplay()
00060 {
00061 mDisplayFrameHash = !mDisplayFrameHash;
00062 }
00063
00064 void ChangeSrc(RgbDataSrc* src)
00065 {
00066 mSrc = src;
00067 if (!mSrc)
00068 {
00069 DeleteViewers();
00070 return;
00071 }
00072 if ((mLastFrameWidth != mSrc->FrameWidth()) ||
00073 (mLastFrameHeight != mSrc->FrameHeight()))
00074 {
00075 int border = (GetParent()) ? 2 : 0;
00076 int newWidth = mViewScale * mSrc->FrameWidth() + border;
00077 int newHeight = mViewScale * mSrc->FrameHeight() + border + 25;
00078 int dy = newHeight - WndHeight();
00079 SetDimensions(RETAIN, WndY() - dy, newWidth, newHeight);
00080 DeleteViewers();
00081 mLastFrameWidth = mSrc->FrameWidth();
00082 mLastFrameHeight = mSrc->FrameHeight();
00083 }
00084 }
00085
00086
00087
00088 virtual void KeyboardFunc(int c, int state)
00089 {
00090 if (c=='#')
00091 ToggleHashValueDisplay();
00092 Window::KeyboardFunc(c,state);
00093 }
00094
00095 virtual void DisplayFunc()
00096 {
00097 Window::DisplayFunc();
00098
00099 if (!mSrc)
00100 return;
00101
00102 OGC oldOGC;
00103 OGCSave(&oldOGC);
00104
00105 SetSolidLineColor(oglBLACK);
00106 SetLineWidth(1);
00107
00108
00109 int width = mOglWnd->width;
00110 DrawRectangle(0, 0, width-1, 25 - 2);
00111 if (mDisplayFrameHash)
00112 {
00113 if (mSrc->FrameNr() != mLastFrame)
00114 mLastHash = mSrc->GetHash();
00115 String msg = "hash: [" + mLastHash + "]";
00116 oglSys.PosColPrintf(mOglWnd, 4, 27, oglGREEN, "%s",msg.c_str());
00117 }
00118 oglSys.PosColPrintf(mOglWnd, 20, 7, oglGREEN, "at frame %d of %d",
00119 mSrc->FrameNr(), mSrc->LastFrame());
00120 SetSolidLineColor(oglRED);
00121 mMappedFramePos = ((double)mSrc->FrameNr()/mSrc->LastFrame())*(width-3);
00122 DrawRectangle(1 + mMappedFramePos, 1, 1, 25 - 4);
00123
00124 OGCRestore(&oldOGC);
00125 }
00126
00127 virtual void MouseFunc(int msg, int but, int state, int x, int y)
00128 {
00129 Window::MouseFunc(msg, but, state, x, y);
00130
00131 if (msg == oglMouseUp)
00132 mScrollDrag = false;
00133
00134 if (((msg==oglMouseDown && but==oglLeftButton) ||
00135 (msg==oglMouseMove && state&oglLeftButton)) && y < 25)
00136 {
00137 if ((msg==oglMouseDown) && (but==oglLeftButton))
00138 mScrollDrag = true;
00139 if (x < 0)
00140 x = 0;
00141 int width = mOglWnd->width-1;
00142 if (x >= width)
00143 x = width;
00144 int reqFr = ((double) x / width) * mSrc->LastFrame();
00145 if (reqFr >= mSrc->LastFrame() - 1)
00146 reqFr = mSrc->LastFrame() - 1;
00147 if ((reqFr != mSrc->FrameNr()) && mVideoNavListener &&
00148 mScrollDrag && mAllowJump)
00149 {
00150 mVideoNavListener->NavFrameEvent(this, reqFr, mListenerData);
00151 }
00152 }
00153 }
00154
00155 private:
00156
00157 void Init(RgbDataSrc* src, bool allowJump, double viewScale)
00158 {
00159 mSrc = src;
00160 mLastFrameWidth = (src) ? src->FrameWidth() : -1;
00161 mLastFrameHeight = (src) ? src->FrameHeight() : -1;
00162 mAllowJump = allowJump;
00163 mViewScale = viewScale;
00164 if (mSrc && (mSrc->LastFrame() > 1000000))
00165 mAllowJump = false;
00166 mRequestedFrame = 0;
00167 mMappedFramePos = 0;
00168 mScrollDrag = false;
00169 mVideoNavListener = 0;
00170 SetMakeViewWithRect(true);
00171
00172 mLastFrame = -1;
00173 mLastHash = "";
00174 mDisplayFrameHash = true;
00175 }
00176
00177 RgbDataSrc* mSrc;
00178 int mLastFrameWidth;
00179 int mLastFrameHeight;
00180 bool mAllowJump;
00181 double mViewScale;
00182 int mRequestedFrame;
00183 int mMappedFramePos;
00184 bool mScrollDrag;
00185
00186 int mLastFrame;
00187 String mLastHash;
00188 bool mDisplayFrameHash;
00189
00190 VideoNavListener* mVideoNavListener;
00191 void* mListenerData;
00192
00193 };
00194
00195 }
00196 }
00197
00198 #endif