00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef Impala_Application_MediaTable_RandomImageWindow_h
00011 #define Impala_Application_MediaTable_RandomImageWindow_h
00012
00013 #ifndef OglGui_WindowView2D_h
00014 #include "OglGui/WindowView2D.h"
00015 #endif
00016
00017 #include "../TableDataView.h"
00018 #include "../TableViewCache.h"
00019
00020 #include "../TableDataViewController.h"
00021
00022 #include "../OglImageCacheStore.h"
00023 #include "OglGui/GetOglImageByIdInterface.h"
00024
00025 namespace Impala { namespace Application { namespace MediaTable {
00026
00027 class RandomImageWindow : public OglGui::Window,
00028 public OglGui::WindowListener,
00029 public TableDataViewController
00030 {
00031 public:
00032 typedef OglGui::Window Window;
00033 typedef OglGui::WindowView2D WindowView2D;
00034 typedef OglGui::StaticText StaticText;
00035 typedef OglGui::GetOglImageByIdInterface GetOglImageByIdInterface;
00036 typedef OglGui::OglImageCache OglImageCache;
00037
00038 RandomImageWindow(Window* parent, TableDataView* view,
00039 std::string &imageColumn,
00040 int x, int y, int w, int h) :
00041 Window(parent,x,y,w,h),
00042 TableDataViewController(view)
00043 {
00044 Init(imageColumn, w,h);
00045 }
00046
00047 virtual void DisplayFunc()
00048 {
00049 OGC oldOGC;
00050 OGCSave(&oldOGC);
00051 Window::DisplayFunc();
00052 if (GetTableDataView() != 0)
00053 {
00054 ShowImages();
00055 }
00056 OGCRestore(&oldOGC);
00057 }
00058
00059 void SetGetOglImageByIdInterface(GetOglImageByIdInterface* i)
00060 {
00061 mGetOglImageByIdI = i;
00062 }
00063
00064 void SetOglImageCache(OglImageCache* oglImageCache)
00065 {
00066 mOglImageCache = oglImageCache;
00067 }
00068
00069 protected:
00070
00071 OGLIMAGE* LoadViewImage(long long id)
00072 {
00073 if (!mOglImageCache || !mGetOglImageByIdI)
00074 return 0;
00075
00076 OGLIMAGE* im = mOglImageCache->GetImage(id);
00077
00078 if (!im && (im = mGetOglImageByIdI->GetOglImageById(id)))
00079 mOglImageCache->Add(im, id);
00080 return im;
00081 }
00082
00083 virtual void InitViews()
00084 {
00085 mViews.clear();
00086 for (int i=0; i<GetTableDataView()->GetFilteredRows(); i++)
00087 {
00088 int x = ABSRND(W()-64), y = ABSRND(H()-64);
00089 OGLVIEW* view = viewSys.View2D(GetOGLWND(), 0, x, y, 64, 64);
00090 viewSys.SetTags(view, FlexViewTags);
00091 viewSys.ClearTags(view, deletableTag|showBgTag);
00092 mViews.push_back(view);
00093 }
00094 }
00095
00096 virtual void ShowImages()
00097 {
00098 if(mViews.size() != GetTableDataView()->GetFilteredRows())
00099 InitViews();
00100
00101 int px, py, pcol, w, h;
00102 for (int i=0; i<GetTableDataView()->GetFilteredRows(); i++)
00103 {
00104 int x, y;
00105 int col = TableDataViewController::MarkToColor(GetTableDataView()->GetMark(i));
00106 OGLVIEW *view = mViews[i];
00107 viewSys.SetColor(view, OGL_BORDER, col);
00108 viewSys.GetDimensions(view, &x, &y, &w, &h);
00109
00110 if(i > 0)
00111 DrawColLine(px, py, x, y, pcol, col);
00112
00113 view->im=LoadViewImage(GetTableDataView()->GetSortedQuid(mImageColumn, i));
00114
00115 if (view->im)
00116 {
00117 view->zoomX = view->h / (float) view->im->w;
00118 view->zoomY = view->w / (float) view->im->h;
00119 }
00120 viewSys.GetDimensions(view, &px, &py, &w, &h);
00121 pcol = col;
00122 }
00123 SetSolidLineColor(oglGREEN);
00124 DrawRectangle(10, 10, 100, 100);
00125 DrawColLine (50, 50, 50, 150, oglBLUE, oglRED);
00126
00127 }
00128
00129 virtual void KeyboardFunc(int c, int state)
00130 {
00131 switch (c)
00132 {
00133 case ' ':
00134 UpdateScene();
00135 break;
00136 default:
00137 TableDataViewController::KeyboardFunc(c, state);
00138 }
00139 }
00140
00141 virtual void MouseFunc(int msg, int btn, int state, int x, int y)
00142 {
00143 }
00144
00145
00146 void UpdateNumberOfRows() {}
00147 void UpdateSelectionEvent() {}
00148
00149 private:
00150 void Init(std::string imageColumn, int w, int h)
00151 {
00152 mOglImageCache = 0;
00153 mGetOglImageByIdI = 0;
00154 mImageColumn = imageColumn;
00155 InitViews();
00156 }
00157
00158 protected:
00159 std::string mImageColumn;
00160 OglImageCache* mOglImageCache;
00161 GetOglImageByIdInterface* mGetOglImageByIdI;
00162
00163 std::vector<OGLVIEW*> mViews;
00164
00165 private:
00166 ILOG_VAR_DEC;
00167 };
00168
00169 ILOG_VAR_INIT(RandomImageWindow, Application.MediaTable);
00170
00171 } } }
00172
00173 #endif