Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

TableCell.h

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

Generated on Fri Mar 19 09:30:41 2010 for ImpalaSrc by  doxygen 1.5.1