00001 #ifndef MediaTable_TableOverviewWindow_h
00002 #define MediaTable_TableOverviewWindow_h
00003
00004 #include "TableDataView.h"
00005
00006 namespace Impala {
00007 namespace Application {
00008 namespace MediaTable {
00009
00010 class TableOverviewWindow : public OglGui::Window,
00011 public TableDataViewListener
00012 {
00013 public:
00014 typedef OglGui::Window Window;
00015
00016 TableOverviewWindow(OglGui::Window* parent, TableDataView *source,
00017 int width, int height) :
00018 Window(parent, width, height)
00019 {
00020 Init(source, width, height);
00021 }
00022
00023 TableOverviewWindow(Window* parent, TableDataView *source,
00024 int x, int y, int width, int height) :
00025 Window(parent, x, y, width, height)
00026 {
00027 Init(source, width, height);
00028 }
00029
00030
00031
00032 virtual void UpdateSelectionEvent()
00033 {
00034 mPixelCacheSynced = false;
00035 }
00036
00037 virtual void MouseFunc(int msg, int but, int state, int x, int y)
00038 {
00039 if ((msg==oglMouseDown || msg==oglMouseMove) && state==oglLeftButton)
00040 {
00041
00042
00043 int row = PixelToRow(mDrawOffset+mDrawHeight - y);
00044 ILOG_USER("overview window scroll event to "<<row);
00045 mSource->SetStartRow(row);
00046 if (row + mSource->GetNumberOfRows() > mSource->GetTotalRows())
00047 row = mSource->GetTotalRows() - mSource->GetNumberOfRows();
00048 if (row != mSource->GetStartRow())
00049 mSource->SetStartRow(row);
00050 mSource->DoUpdateScrollFromSourceEvent();
00051 }
00052 }
00053
00054
00055 virtual void
00056 KeyboardFunc(int c, int state)
00057 {
00058 }
00059
00060 virtual void ReshapeFunc(int w, int h)
00061 {
00062 Window::ReshapeFunc(w,h);
00063 mPixelCacheSynced = false;
00064 }
00065
00066 inline int RowToPixel(int row)
00067 {
00068 return row * mDrawHeight / mSource->GetFilteredRows();
00069 }
00070
00071 inline int PixelToRow(int pixel)
00072 {
00073 return pixel * mSource->GetFilteredRows() / mDrawHeight;
00074 }
00075
00076 inline void PixelToRows(int pixel, int *startrow, int *endrow)
00077 {
00078 *startrow = PixelToRow(pixel);
00079 *endrow = PixelToRow(pixel+1) -1 ;
00080
00081
00082 }
00083
00084 void UpdatePixelCache(int height)
00085 {
00086 mSelPixelCache.clear();
00087
00088 if (height < mSource->GetFilteredRows())
00089 {
00090 ILOG_DEBUG("Updating selection cache...");
00091
00092 for (int pixelrow = 0; pixelrow < height; pixelrow++)
00093 {
00094 int start, stop;
00095 PixelToRows(pixelrow, &start, &stop);
00096 unsigned long avgcol = 0;
00097 for (int y=start; y<=stop; y++)
00098 {
00099 int mark = mSource->GetMark(y);
00100 if (mark)
00101 {
00102 avgcol = MarkToColor(mark);
00103 break;
00104 }
00105 }
00106
00107 mSelPixelCache.push_back(avgcol);
00108 }
00109 mPixelCacheSynced = true;
00110 }
00111 }
00112
00113
00114
00115 virtual void DisplayFunc()
00116 {
00117 if (mSource->GetFilteredRows() == 0)
00118 {
00119 Window::DisplayFunc();
00120 return;
00121 }
00122
00123 OGC myOGC;
00124 OGCSave(&myOGC);
00125 SetStipple((short)oglDot);
00126 SetSolidLineColor(0xff777777);
00127
00128 mDrawHeight = H() - 32 - mHeaderHeight;
00129 mDrawOffset = 16;
00130
00131 if (mDrawHeight < mSource->GetFilteredRows())
00132 {
00133 if (mDrawHeight > mSelPixelCache.size())
00134 mPixelCacheSynced=false;
00135
00136
00137 if (!mPixelCacheSynced)
00138 UpdatePixelCache(mDrawHeight);
00139
00140 for (int i=0; i<mDrawHeight; i++)
00141 {
00142 unsigned long avgcol = mSelPixelCache[i];
00143 if (avgcol > 0)
00144 {
00145 SetSolidFillColor(avgcol);
00146 FillRectangle(0, mDrawOffset+mDrawHeight-i, W(), 1);
00147 }
00148 }
00149 }
00150 else
00151 {
00152
00153 for (int y = 0; y < mSource->GetFilteredRows(); y++)
00154 {
00155 int mark = mSource->GetMark(y);
00156 if (mark)
00157 {
00158 SetSolidFillColor(MarkToColor(mark));
00159 int l = RowToPixel(1);
00160 int s = RowToPixel(y) + l;
00161 FillRectangle(0, mDrawOffset+mDrawHeight-s, W(), l+1);
00162 }
00163 }
00164 }
00165
00166
00167 SetSolidFillColor(0xffffffff);
00168 int l = RowToPixel(mSource->GetNumberOfRows());
00169 int s = RowToPixel(mSource->GetStartRow()) + l;
00170 FillRectangle(0,mDrawOffset+mDrawHeight-s, 8,l);
00171 FillRectangle(W()-8,mDrawOffset+mDrawHeight-s, 8,l);
00172
00173 OGCRestore(&myOGC);
00174 Window::DisplayFunc();
00175 }
00176
00177 void
00178 SetHeaderHeight(int height)
00179 {
00180 ILOG_DEBUG("SetHeaderHeight(" << height << ")");
00181 mPixelCacheSynced = false;
00182 mHeaderHeight = height;
00183 mPixelCacheSynced = false;
00184 }
00185
00186 private :
00187
00188 int MarkToColor(int m)
00189 {
00190 int r=127,g=127,b=127;
00191 if (m == -1)
00192 return ARGB2COLOR(255, 200, 200, 200);
00193 if (m & 1)
00194 r = g = b = 255;
00195 if (m & 2)
00196 r = g = b = 80;
00197 if (m & 4)
00198 r += 64;
00199 if (m & 8)
00200 g += 64;
00201 if (m & 16)
00202 b += 64;
00203 if (m & 32)
00204 { r += 64; g += 64; }
00205 if (m & 64)
00206 { g += 64; b += 64; }
00207 if (m & 128)
00208 { r += 64; b += 64; }
00209 if (r>255) r = 255;
00210 if (g>255) g = 255;
00211 if (b>255) b = 255;
00212 return ARGB2COLOR(255,r,g,b);
00213 }
00214
00215 void Init(TableDataView *source, int w, int h)
00216 {
00217 mSource = source;
00218 mReady = true;
00219 mPixelCacheSynced = false;
00220 mDrawHeight = H();
00221 mDrawOffset = 8;
00222 mHeaderHeight = 0;
00223
00224 mSource->AddTableDataViewListener(this);
00225 SetBackground(oglBLACK);
00226 SetBorderFillShaded(DEEP_SHADE_DOWN);
00227 SetBorderType(1);
00228 }
00229
00230 TableDataView* mSource;
00231 std::vector<unsigned long> mSelPixelCache;
00232
00233 bool mPixelCacheSynced;
00234 bool mReady;
00235 int mDrawHeight;
00236 int mDrawOffset;
00237 int mHeaderHeight;
00238
00239 ILOG_VAR_DEC;
00240 };
00241
00242 ILOG_VAR_INIT(TableOverviewWindow, Application.MediaTable);
00243
00244 }
00245 }
00246 }
00247
00248 #endif // TableOverviewWindow_h