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

ColorsNamed.h

Go to the documentation of this file.
00001 //345678901234567890123456789012345678901234567890123456789012345678901234567890
00002 // Author: Richard van Balen, for University of Amsterdam
00004 
00005 #ifndef OglGui_ColorsNamed_h
00006 #define OglGui_ColorsNamed_h
00007 
00008 #include "OglGui/Animator.h"
00009 #ifndef OglGui_ScrollWnd_h
00010 #include "OglGui/ScrollWnd.h"
00011 #endif
00012 
00013 #include "OglGui/ColorsNamedListener.h"
00014 
00015 namespace OglGui {
00016 
00017 class ColorsNamed : public ScrollWnd,
00018                     public WindowListener
00019 {
00020 public:
00021     const static int    PREF_H = 252;
00022     const static int    PREF_W  = 200;
00023 
00024     ColorsNamed(int x, int y, int w, int h, bool shaded=false) :
00025         ScrollWnd(x,y,w,h,true,1,0)
00026     {
00027         Init(w,h,shaded);
00028     }
00029 
00030     ColorsNamed(Window* parent, int w, int h, bool shaded=false) :
00031         ScrollWnd(parent,w,h,true,1,0)
00032     {
00033         Init(w,h,shaded);
00034     }
00035 
00036     ColorsNamed(Window* parent, int x, int y, int w, int h, bool shaded=false) :
00037         ScrollWnd(parent,x,y,w,h,true,1,0)
00038     {
00039         Init(w,h,shaded);
00040     }
00041 
00042     void SetColorsNamedListener(ColorsNamedListener* l, void* userData=0)
00043     {
00044         mListener = l;
00045         mListenerData = userData;
00046     }
00047 
00048     virtual void
00049     WindowMouseEvent(Window *src, int msg, int but, int state,
00050                      int x, int y, void* userData )
00051     {
00052         if (!mListener)
00053             return;
00054         if (msg == oglMouseDown || msg == oglMouseDblClick)
00055         {
00056             StaticText* txt   = (StaticText*) src;
00057             StaticText* txt2  = (StaticText*) userData;
00058             ULONG       col   = src->GetBorderBackground();
00059             std::string str   = txt2 ? txt2->GetText() : txt->GetText();
00060 
00061             mListener->OnColorName(this, str, col, msg, mListenerData);
00062         }
00063     }
00064 
00065 
00066 private:
00067     void Init(int w, int h, bool shaded)
00068     {
00069         Window* parent = ContentPane();
00070         char*   str;
00071 
00072         int i = 0;
00073         while(str = GetOglColorName(i))
00074             i++;
00075 
00076         int cellW = (shaded ? 164 : 134);
00077         int cpW   = 8 + ((i/8)+1)* cellW;
00078         int cpH   = 8 + 8*28;
00079         parent->SetDimensions(cpW,cpH);
00080 
00081         i = 0;
00082         StaticText* txt;
00083         while(str = GetOglColorName(i))
00084         {
00085             txt = new StaticText(parent,4+cellW*(i/8),cpH-32-(i%8)*28,
00086                                  128,26,str);
00087             int   r, g, b;
00088             OglColorStr2RGB(str, &r, &g, &b);
00089             ULONG bg = ARGB2COLOR(255,r,g,b);
00090             txt->SetBorderType(BEV_ETCHED);
00091             txt->SetBorderFillShaded(shaded ? 2 : 0);
00092             txt->SetBorderBackground(bg);
00093             txt->SetWindowListener(this);
00094 
00095             if (shaded)
00096             {
00097                 txt = new StaticText(parent,4+cellW*(i/8)+130,cpH-32-(i%8)*28,
00098                                      26,26, "");
00099                 txt->SetBorderType(BEV_ETCHED);
00100                 txt->SetBorderFillShaded(0);
00101                 txt->SetBorderBackground(bg);
00102                 txt->SetWindowListener(this, (void*) txt);
00103             }
00104             i++;
00105         }
00106         parent->SetAllowChildScaling(true);
00107         parent->ScaleChildren(0,0);
00108         parent->ConnectTo(this,B2B|T2T);
00109         parent->SetAllowChildScaling(false);
00110         mListener = 0;
00111         //new Animator(parent,0,0,40,40);
00112     }
00113 
00114 /*
00115     void Init(int w, int h, bool shaded)
00116     {
00117         Window* parent = ContentPane();
00118 
00119         int i = 0;
00120         while(oglStrColors[i][0])
00121             i++;
00122 
00123         int cellW = (shaded ? 164 : 134);
00124         int cpW   = 8 + ((i/8)+1)* cellW;
00125         int cpH   = 8 + 8*28;
00126         parent->SetDimensions(cpW,cpH);
00127 
00128         i = 0;
00129         StaticText* txt;
00130         while(oglStrColors[i][0])
00131         {
00132             txt = new StaticText(parent,4+cellW*(i/8),cpH-32-(i%8)*28,
00133                                  128,26,oglStrColors[i][0]);
00134             int   r, g, b;
00135             OglColorStr2RGB(oglStrColors[i][0], &r, &g, &b);
00136             ULONG bg = ARGB2COLOR(255,r,g,b);
00137             txt->SetBorderType(BEV_ETCHED);
00138             txt->SetBorderFillShaded(shaded ? 2 : 0);
00139             txt->SetBorderBackground(bg);
00140             txt->SetWindowListener(this);
00141 
00142             if (shaded)
00143             {
00144                 txt = new StaticText(parent,4+cellW*(i/8)+130,cpH-32-(i%8)*28,
00145                                      26,26, "");
00146                 txt->SetBorderType(BEV_ETCHED);
00147                 txt->SetBorderFillShaded(0);
00148                 txt->SetBorderBackground(bg);
00149                 txt->SetWindowListener(this, (void*) txt);
00150             }
00151             i++;
00152         }
00153         parent->SetAllowChildScaling(true);
00154         parent->ScaleChildren(0,0);
00155         parent->ConnectTo(this,B2B|T2T);
00156         parent->SetAllowChildScaling(false);
00157         mListener = 0;
00158         //new Animator(parent,0,0,40,40);
00159     }
00160 */
00161     ColorsNamedListener*    mListener;
00162     void*                   mListenerData;
00163 };
00164 } // namespace OglGui
00165 
00166 #endif

Generated on Fri Mar 19 09:31:34 2010 for ImpalaSrc by  doxygen 1.5.1