00001 #ifndef MediaTable_TableWindowCell_h
00002 #define MediaTable_TableWindowCell_h
00003
00004 #include "TableDataSource.h"
00005 #include "TableViewCache.h"
00006
00007 #ifndef OglGui_StaticText_h
00008 #include "OglGui/StaticText.h"
00009 #endif
00010
00011 namespace Impala {
00012 namespace Application {
00013 namespace MediaTable {
00014
00015 class TableWindowCell : public OglGui::Window
00016 {
00017 public:
00018 typedef OglGui::Window Window;
00019 typedef OglGui::StaticText StaticText;
00020
00021 TableWindowCell(Window *parent, TableDataView *source, TableViewCache *cache,
00022 String column) :
00023 Window(parent, 0, 0, parent->W(), 20)
00024 {
00025 Init(parent, source, cache, column);
00026 }
00027
00028 void UpdateRow(int y, int row, int height, int displaymode = DISPLAY_NOCHANGE,
00029 int dispattr = NONE)
00030 {
00031 SetDimensions(0,mParent->H()-y,mParent->W(),height);
00032 SetVisible(true);
00033
00034
00035 if (displaymode!=DISPLAY_NOCHANGE && displaymode!=mCurrentDisplayMode)
00036 {
00037 mCurrentDisplayMode = displaymode;
00038 mDisplayAsText->SetVisible(mCurrentDisplayMode == DISPLAY_TEXT ||
00039 mCurrentDisplayMode == DISPLAY_NUMBER);
00040 mDisplayAsDot ->SetVisible(mCurrentDisplayMode == DISPLAY_DOT);
00041 }
00042
00043 String txt;
00044 double dVal;
00045 switch (mCurrentDisplayMode)
00046 {
00047 case DISPLAY_TEXT:
00048 case DISPLAY_NUMBER:
00049 txt = mSource->GetSortedTextData(mColumn, row);
00050 mDisplayAsText->SetText(txt);
00051 break;
00052 case DISPLAY_DOT:
00053 dVal = mSource->GetSortedNormalizedData(mColumn, row);
00054 mDisplayAsDot->SetBackground(Gradient(dVal, dispattr));
00055 break;
00056 case DISPLAY_IMAGE:
00057 mViewCache->ShowView(mColumn, row, 0,mParent->H() - y,W(),H());
00058 break;
00059 case DISPLAY_FILLED:
00060 dVal = mSource->GetSortedNormalizedData(mColumn, row);
00061 mFillBgColor = Gradient(dVal, dispattr);
00062 break;
00063 }
00064 }
00065
00066 virtual void DisplayFunc()
00067 {
00068 if (mCurrentDisplayMode == DISPLAY_FILLED)
00069 {
00070 OGC myOGC;
00071 INT oldBlendInfo[3];
00072 OGCSave(&myOGC);
00073 oglSys.StartBlend( &oldBlendInfo[0] );
00074 SetSolidFillColor(mFillBgColor);
00075 FillRectangle(1, 1, W(), H()-1);
00076 oglSys.EndBlend( &oldBlendInfo[0] );
00077 OGCRestore(&myOGC);
00078 }
00079 Window::DisplayFunc();
00080 }
00081
00082 private:
00083
00084 int Gradient(double val, int grtype = GRADIENT_REDFADE)
00085 {
00086 int r=0,g=0,b=0, a=255;
00087 if (grtype == NONE) grtype = GRADIENT_BLACKFADE;
00088 switch (grtype)
00089 {
00090 case GRADIENT_BLACKFADE:
00091 a = val * 256;
00092 r = g = b = 0;
00093 break;
00094 case GRADIENT_REDFADE:
00095 a = val * 256;
00096 r = 128;
00097 break;
00098 case GRADIENT_GREENFADE:
00099 a = val * 256;
00100 g = 128;
00101 break;
00102 case GRADIENT_BLUEFADE:
00103 a = val * 256;
00104 b = 128;
00105 break;
00106 }
00107 if (a>255) a = 255;
00108 if (r>255) r = 255;
00109 if (g>255) g = 255;
00110 if (b>255) b = 255;
00111 return ARGB2COLOR(a,r,g,b);
00112 }
00113
00114 void Init(Window *parent, TableDataView *source, TableViewCache *cache,
00115 String column)
00116 {
00117 mParent = parent;
00118 mSource = source;
00119 mColumn = column;
00120 mViewCache = cache;
00121 mFillBgColor = 0;
00122 mCurrentDisplayMode = DISPLAY_TEXT;
00123 ConnectTo(parent, OglGui::L2L|OglGui::R2R);
00124 SetVisible(false);
00125
00126 mDisplayAsText = new StaticText(this, 0, 0, W(), H(), "");
00127 mDisplayAsText->ConnectTo(this);
00128 mDisplayAsText->SetVisible(true);
00129 mDisplayAsText->SetCentered(false);
00130
00131
00132 mDisplayAsDot = new Window(this, W() / 2 - 4, H() / 2 - 4, 8, 8);
00133 mDisplayAsDot->ScaleTo(this);
00134 mDisplayAsDot->SetVisible(false);
00135
00136 oglSys.SetNoMouseInput(mDisplayAsText->GetOGLWND(),1);
00137 oglSys.SetNoMouseInput(mDisplayAsDot->GetOGLWND(),1);
00138 }
00139
00140
00141 unsigned long mFillBgColor;
00142 int mCurrentDisplayMode;
00143
00144 String mColumn;
00145
00146 TableDataView* mSource;
00147 TableViewCache* mViewCache;
00148
00149 Window* mParent;
00150 Window* mDisplayAsDot;
00151 StaticText* mDisplayAsText;
00152
00153 public:
00154 static const int DISPLAY_NOCHANGE = 0;
00155 static const int DISPLAY_TEXT = 1;
00156 static const int DISPLAY_NUMBER = 2;
00157 static const int DISPLAY_DOT = 3;
00158 static const int DISPLAY_IMAGE = 4;
00159 static const int DISPLAY_FILLED = 5;
00160
00161 static const int NONE = 0;
00162 static const int GRADIENT_REDFADE = 1;
00163 static const int GRADIENT_GREENFADE = 2;
00164 static const int GRADIENT_BLUEFADE = 3;
00165 static const int GRADIENT_BLACKFADE = 4;
00166 };
00167
00168 }
00169 }
00170 }
00171
00172 #endif // TableWindowCell_h