00001
00002
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
00112 }
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161 ColorsNamedListener* mListener;
00162 void* mListenerData;
00163 };
00164 }
00165
00166 #endif