1 #ifndef __CtrlLib_DlgColor__ 2 #define __CtrlLib_DlgColor__ 3 4 class WheelRampCtrl : public Ctrl 5 { 6 public: 7 WheelRampCtrl(bool ramp); 8 ~WheelRampCtrl(); 9 10 virtual void Layout(); 11 virtual void Paint(Draw& draw); 12 virtual void SetData(const Value& value); GetData()13 virtual Value GetData() const { return color; } 14 15 virtual void LeftDown(Point pt, dword keyflags); 16 virtual void LeftUp(Point pt, dword keyflags); 17 virtual void LeftDouble(Point pt, dword keyflags); 18 virtual void MouseMove(Point pt, dword keyflags); 19 20 Event<> WhenLeftDouble; 21 22 private: 23 void SetColor(Color color, bool set_norm, bool set_hsv); 24 25 Image PaintRamp(Size size); 26 Image PaintWheel(Size size); 27 void PaintColumn(Draw& draw); 28 29 int ClientToLevel(int y) const; 30 int LevelToClient(int l) const; 31 32 private: 33 bool ramp; 34 Color color; 35 Color normalized_color; 36 int h16, s16, v16; 37 int round_step; 38 enum STYLE { S_WHEEL, S_RECT, S_HEXAGON }; 39 STYLE style; 40 Image cache; 41 int cache_level; 42 Image wheel_cache; 43 Rect wheel_rect; 44 Rect column_rect; 45 46 int firstclick; 47 48 struct WheelBuff 49 { 50 int arg; 51 int l; 52 }; 53 }; 54 55 struct ColorWheelCtrl : public WheelRampCtrl { ColorWheelCtrlColorWheelCtrl56 ColorWheelCtrl() : WheelRampCtrl(false) {} 57 }; 58 59 struct ColorRampCtrl : public WheelRampCtrl { ColorRampCtrlColorRampCtrl60 ColorRampCtrl() : WheelRampCtrl(true) {} 61 }; 62 63 class ColorSelector : public Ctrl 64 { 65 public: 66 ColorSelector(bool not_null = true); 67 68 ColorSelector& NotNull(bool nn = true) { impl->NotNull(nn); return *this; } NoNotNull()69 ColorSelector& NoNotNull() { return NotNull(false); } IsNotNull()70 bool IsNotNull() const { return impl->IsNotNull(); } 71 Get()72 Color Get() const { return impl->Get(); } Set(Color c)73 void Set(Color c) { impl->Set(c); } 74 GetPalette()75 Vector<Color> GetPalette() const { return impl->GetPalette(); } SetPalette(const Vector<Color> & palette)76 void SetPalette(const Vector<Color>& palette) { impl->SetPalette(palette); } 77 SerializeConfig(Stream & stream)78 void SerializeConfig(Stream& stream) { impl->SerializeConfig(stream); } 79 SetData(const Value & color)80 virtual void SetData(const Value& color) { Set(color); } GetData()81 virtual Value GetData() const { return Get(); } 82 GetImplCtrl()83 Ctrl& GetImplCtrl() { return impl->GetCtrl(); } 84 85 public: 86 Event<> WhenSetColor; 87 88 public: 89 class Impl 90 { 91 public: ~Impl()92 virtual ~Impl() {} 93 94 virtual void Set(Color c) = 0; 95 virtual Color Get() const = 0; 96 virtual void NotNull(bool nn) = 0; 97 virtual bool IsNotNull() const = 0; 98 virtual Vector<Color> GetPalette() const = 0; 99 virtual void SetPalette(const Vector<Color>& pal) = 0; 100 virtual void SerializeConfig(Stream& stream) = 0; 101 virtual Ctrl& GetCtrl() = 0; 102 103 protected: Impl()104 Impl() {} 105 }; 106 107 protected: 108 One<Impl> impl; 109 }; 110 111 class ColorCtrl : public DataPusher 112 { 113 public: 114 typedef ColorCtrl CLASSNAME; 115 ColorCtrl(bool not_null = true); 116 virtual ~ColorCtrl(); 117 118 ColorCtrl& NotNull(bool _nn = true) { empty.Show(!_nn); return *this; } NoNotNull()119 ColorCtrl& NoNotNull() { return NotNull(false); } IsNotNull()120 bool IsNotNull() const { return !empty.IsVisible(); } 121 122 protected: 123 virtual void DoAction(); OnClear()124 void OnClear() { SetDataAction(Null); } 125 126 protected: 127 FrameRight<Button> empty; 128 }; 129 130 Color RunDlgSelectColor(Color init_color = Black, bool not_null = true, const char *title = 0, bool *ok = 0); 131 const Display& StdColorDisplayNull(); 132 133 class ColorPopUp : public Ctrl { 134 public: 135 virtual void Paint(Draw& w); 136 virtual void LeftUp(Point p, dword); 137 virtual void LeftDown(Point p, dword); 138 virtual void MouseMove(Point p, dword); 139 virtual void MouseLeave(); 140 virtual bool Key(dword key, int count); 141 virtual void Layout(); 142 143 private: 144 void PopupDeactivate(); 145 146 struct Popup : Ctrl { 147 ColorPopUp *color; 148 DeactivatePopup149 virtual void Deactivate() { color->PopupDeactivate(); } 150 }; 151 152 int Get(Point p); 153 int GetCy(); 154 void Setup(Color c); 155 void Finish(); 156 void Ramp(); 157 void Wheel(); 158 int GetColorCount() const; 159 Color GetColor(int i) const; 160 void Select(); 161 162 void DrawFilledFrame(Draw &w, int x, int y, int cx, int cy, Color fcol, Color bcol); 163 void DrawFilledFrame(Draw &w, Rect &r, Color fcol, Color bcol); 164 165 int colori; 166 bool notnull; 167 bool scolors; 168 bool norampwheel; 169 bool animating; 170 bool hints; 171 bool open; 172 bool withvoid; 173 String nulltext; 174 String voidtext; 175 Color color; 176 177 ColorRampCtrl ramp; 178 ColorWheelCtrl wheel; 179 Button settext; 180 One<Popup> popup; 181 182 static Color hint[18]; 183 184 friend void ColorPopUp_InitHint(); 185 186 public: 187 Event<> WhenCancel; 188 Event<> WhenSelect; 189 190 static void Hint(Color c); 191 192 typedef ColorPopUp CLASSNAME; 193 194 void PopUp(Ctrl *owner, Color c = White); 195 Color Get() const; 196 197 ColorPopUp& NotNull(bool b = true) { notnull = b; return *this; } 198 ColorPopUp& SColors(bool b = true) { scolors = b; return *this; }//Deprecated, BUT NEEDED IN THEIDE NullText(const char * s)199 ColorPopUp& NullText(const char *s) { nulltext = s; Refresh(); return *this; } 200 ColorPopUp& WithVoid(bool b = true) { withvoid = b; Refresh(); return *this; } VoidText(const char * s)201 ColorPopUp& VoidText(const char *s) { voidtext = s; Refresh(); return *this; } 202 ColorPopUp& NoRampWheel(bool b = true) { norampwheel = b; return *this; } 203 ColorPopUp& Hints(bool b = true) { hints = b; return *this; } 204 205 ColorPopUp(); 206 virtual ~ColorPopUp(); 207 }; 208 209 class ColorPusher : public Ctrl { 210 public: 211 virtual void Paint(Draw& w); 212 virtual void LeftDown(Point p, dword); 213 virtual bool Key(dword key, int); GotFocus()214 virtual void GotFocus() { Refresh(); } LostFocus()215 virtual void LostFocus() { Refresh(); } 216 virtual void SetData(const Value& v); 217 virtual Value GetData() const; 218 219 protected: 220 bool push; 221 bool withtext; 222 bool withhex; 223 bool track; 224 Color color, saved_color; 225 ColorPopUp colors; 226 String nulltext; 227 String voidtext; 228 229 void AcceptColors(); 230 void CloseColors(); 231 void NewColor(); 232 void Drop(); 233 234 public: 235 typedef ColorPusher CLASSNAME; 236 NullText(const char * s)237 ColorPusher& NullText(const char *s) { nulltext = s; colors.NullText(s); Refresh(); return *this; } 238 ColorPusher& NotNull(bool b = true) { colors.NotNull(b); return *this; } 239 ColorPusher& WithVoid(bool b = true) { colors.WithVoid(b); return *this; } VoidText(const char * s)240 ColorPusher& VoidText(const char *s) { voidtext = s; colors.VoidText(s); Refresh(); return *this; } 241 ColorPusher& SColors(bool b = true) { colors.SColors(b); return *this; } 242 ColorPusher& WithText(bool b = true) { withtext = b; Refresh(); return *this; } 243 ColorPusher& WithHex(bool b = true) { withhex = b; Refresh(); return *this; } 244 ColorPusher& Track(bool b = true) { track = b; return *this; } NoTrack()245 ColorPusher& NoTrack() { return Track(false); } 246 ColorPusher& NoRampWheel(bool b = true) { colors.NoRampWheel(b); return *this; } 247 248 ColorPusher(); 249 virtual ~ColorPusher(); 250 }; 251 252 class ColorButton : public ColorPusher { 253 public: 254 virtual void Paint(Draw& w); 255 virtual void MouseEnter(Point p, dword keyflags); 256 virtual void MouseLeave(); 257 virtual Size GetMinSize() const; 258 259 protected: 260 Image image, nullimage, staticimage; 261 const ToolButton::Style *style; 262 263 public: ColorImage(const Image & img)264 ColorButton& ColorImage(const Image& img) { image = img; Refresh(); return *this; } NullImage(const Image & img)265 ColorButton& NullImage(const Image& img) { nullimage = img; Refresh(); return *this; } StaticImage(const Image & img)266 ColorButton& StaticImage(const Image& img) { staticimage = img; Refresh(); return *this; } SetStyle(const ToolButton::Style & s)267 ColorButton& SetStyle(const ToolButton::Style& s) { style = &s; Refresh(); return *this; } 268 269 ColorButton(); 270 virtual ~ColorButton(); 271 }; 272 273 String FormatColor(Color c); 274 Color ReadColor(CParser& p); 275 Color RealizeColor(Color c); 276 277 #endif//__TCtrlLib_DlgColor__ 278