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