00001 #ifndef Impala_Visualization_SearchTopicGui_h
00002 #define Impala_Visualization_SearchTopicGui_h
00003
00004 #ifdef DX_USED
00005 #include "Link/DXMedia/HxDXMedia.h"
00006 #endif
00007 #include "Core/Trec/SearchTopic.h"
00008 #include "OglGui/StringSelector.h"
00009 #include "OglGui/TextArea.h"
00010 #include "OglGui/Strut.h"
00011 #include "OglGui/Button.h"
00012 #include "Visualization/ImageStrip.h"
00013 #include "Visualization/LogoWindow.h"
00014 #include "Visualization/SearchTopicGuiListener.h"
00015
00016 namespace Impala {
00017 namespace Visualization {
00018
00019 class SearchTopicGui : public Window,
00020 public OglGui::StringListener,
00021 public ImagesListener,
00022 public OglGui::ButtonListener
00023 {
00024 const static int NUM = 1;
00025 const static int VIDEO = 2;
00026 const static int PLAY = 3;
00027 const static int EXAMPLE = 4;
00028
00029 public:
00030
00031 SearchTopicGui(OglGui::Window* parent, int wndWidth, int wndHeight,
00032 int nrImOnRow, int imWidth, int imHeight, double viewScale,
00033 Core::Trec::SearchTopic* searchTopic,
00034 Core::Array::Array2dVec3UInt8* logoIm, bool logoAnim) :
00035 Window(parent, wndWidth, wndHeight, true)
00036 {
00037 mSearchTopic = searchTopic;
00038
00039 if (logoAnim || logoIm)
00040 new LogoWindow(this, true, 0, 0, wndWidth, 400, logoIm, logoAnim);
00041
00042 int line = 20;
00043 mTopicNumList = new OglGui::StringSelector(this, wndWidth - 20, 12*line);
00044 SetAsBox(mTopicNumList);
00045 mTopicNumList->SetStringListener(this, NUM);
00046 for (int i=0 ; mSearchTopic && i<mSearchTopic->NrTopic() ; i++)
00047 mTopicNumList->AddString(mSearchTopic->GetTopicNum(i) + " : " +
00048 mSearchTopic->GetTopicText(i));
00049 mTopicTextArea = new OglGui::TextArea(this, wndWidth - 20, 3*line, "");
00050 SetAsBox(mTopicTextArea);
00051
00052 mTopicVideoList = 0;
00053 if (mSearchTopic->HasVideos())
00054 {
00055 OglGui::TextArea* vArea = new OglGui::TextArea(this, 100, 1*line,
00056 "Video examples");
00057 vArea->SetBorderType(0);
00058 mTopicVideoList = new OglGui::StringSelector(this, 600, 6*line);
00059 SetAsBox(mTopicVideoList);
00060 mTopicVideoList->SetStringListener(this, VIDEO);
00061 OglGui::Button* but = new OglGui::Button(this, 50, 22, "Play");
00062 but->SetButtonListener(this, PLAY);
00063 OglGui::Strut* strut = new OglGui::Strut(this, 4000, 1);
00064 }
00065
00066 mExampleImagesStrip = new ImageStrip(this, imWidth, imHeight,
00067 viewScale, nrImOnRow);
00068 mExampleImagesStrip->SetImagesListener(this, EXAMPLE);
00069 mExampleImagesStrip->ActivateInfoBox(false);
00070 SetAsBox(mExampleImagesStrip);
00071 }
00072
00073 void
00074 SetTopicListener(SearchTopicGuiListener* listener, void* listenerData = 0)
00075 {
00076 mTopicListener = listener;
00077 mTopicListenerData = listenerData;
00078 }
00079
00080 virtual void StringSelectionEvent(OglGui::StringSelector* src, int strIndex,
00081 void* vData)
00082 {
00083 int listenerData = (int)(long long)vData;
00084 switch (listenerData)
00085 {
00086 case NUM:
00087 ShowTopic(strIndex);
00088 break;
00089 case VIDEO:
00090 mTopicVideoList->SetCurrentString(strIndex);
00091 break;
00092 }
00093 }
00094
00095 virtual void ImageSelectionEvent(Window* src, int imIndex, void* vData)
00096 {
00097 if (vData == (void*) EXAMPLE && mTopicVideoList)
00098 mTopicVideoList->SetCurrentString(imIndex);
00099 }
00100
00101 virtual void ButtonSelectionEvent(OglGui::Button* src, void* vData)
00102 {
00103 if (vData == (void*) PLAY)
00104 #ifndef DX_USED
00105 std::cout << "Play not available." << std::endl;
00106 #else
00107 {
00108 int vidEx = mTopicVideoList->GetCurrentStringIdx();
00109 String fileName = mSearchTopic->GetCurTopicVideoExampleName(vidEx);
00110 void* handle = HxDXOpenFullPlayer(fileName.c_str());
00111 if (handle)
00112 {
00113 HxDXShowSegmentPlayer(handle, 0, -1);
00114 HxDXClosePlayer(handle);
00115 }
00116 else
00117 std::cout << "Unable to play " << fileName << std::endl;
00118 }
00119 #endif
00120 }
00121
00122 void ShowTopic(int id)
00123 {
00124 if (mSearchTopic)
00125 {
00126 mTopicNumList->SetCurrentString(id);
00127 mSearchTopic->TopicSelect(id);
00128 mTopicTextArea->SetText(mSearchTopic->GetCurTopicText());
00129
00130 if (mTopicVideoList)
00131 {
00132 mTopicVideoList->RemoveStrings();
00133 for (int v=0 ; v<mSearchTopic->GetCurTopicNrExamples() ; v++)
00134 mTopicVideoList->
00135 AddString(mSearchTopic->GetCurTopicExampleName(v));
00136 }
00137
00138 mExampleImagesStrip->RemoveImages();
00139 for (int i=0 ; i<mSearchTopic->GetCurTopicNrExamples() ; i++)
00140 {
00141 String name = String("Example ") + MakeString(i);
00142 Core::Array::Array2dVec3UInt8* im;
00143 if (im = mSearchTopic->GetCurTopicImageExample(i, true))
00144 mExampleImagesStrip->AddImage(im, "Direct", name, true);
00145 }
00146 if (mTopicListener)
00147 mTopicListener->TopicSelectionEvent(this,id,mTopicListenerData);
00148 }
00149 }
00150
00151 private:
00152
00153 void SetAsBox(OglGui::Window *w)
00154 {
00155 w->SetBorderType(4);
00156 w->SetBorderFillShaded(2);
00157 }
00158
00159 Core::Trec::SearchTopic* mSearchTopic;
00160 OglGui::StringSelector* mTopicNumList;
00161 OglGui::TextArea* mTopicTextArea;
00162 OglGui::StringSelector* mTopicVideoList;
00163 ImageStrip* mExampleImagesStrip;
00164
00165 SearchTopicGuiListener* mTopicListener;
00166 void* mTopicListenerData;
00167
00168 };
00169
00170 }
00171 }
00172
00173 #endif