CtrlLib: ColorPopup now has button to enter the color as text

git-svn-id: svn://ultimatepp.org/upp/trunk@11195 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2017-06-23 11:17:23 +00:00
parent 572d0c083f
commit de8d2fa9da
5 changed files with 106 additions and 731 deletions

View file

@ -112,7 +112,7 @@ static int sCharFilterHex(int c)
Color ColorFromText(const char *s)
{
Vector<String> h = Split(s, sCharFilterNoDigit);
if(h.GetCount() == 3 && (strchr(s, ',') || strchr(s, ';') || strchr(s, '.'))) {
if(h.GetCount() == 3 && (strchr(s, ',') || strchr(s, ';') || strchr(s, '.') || strchr(s, ' '))) {
int r = atoi(h[0]);
int g = atoi(h[1]);
int b = atoi(h[2]);
@ -222,7 +222,7 @@ void ColorPopUp::Paint(Draw& w)
for(int x = 0; x < 18 * 16; x += 16) {
if(i >= GetColorCount()) {
if(!norampwheel) {
Rect r(8 * 16 + 1, cy + 4, 10 * 16 - 1, sz.cy - 4);
Rect r(8 * 16 + 1, cy + 4, 10 * 16 - 1, sz.cy - 4 - 24);
DrawFilledFrame(w, r, SColorText, color);
r.Inflate(1);
@ -414,6 +414,11 @@ void ColorPopUp::Select()
Finish();
}
void ColorPopUp::Layout()
{
settext.LeftPos(8 * 16, 2 * 16).BottomPos(2, 24);
}
ColorPopUp::ColorPopUp()
{
norampwheel = false;
@ -432,6 +437,25 @@ ColorPopUp::ColorPopUp()
BackPaint();
nulltext = t_("(transparent)");
voidtext = t_("(none)");
settext.SetImage(CtrlImg::color_edit());
settext << [=] {
String text;
if(!IsNull(color) && color != VoidColor())
text = ColorToHtml(color);
EditText(text, "Set Color", "Color value");
Color c = ColorFromText(text);
if(IsNull(c))
return;
color = c;
ramp <<= wheel <<= c;
colori = 999;
WhenAction();
Refresh();
Finish();
};
Add(settext);
}
}

View file

@ -17,10 +17,10 @@ void ColorPusher::Paint(Draw& w)
w.DrawText(max(2, (sz.cx - GetTextSize(nulltext, StdFont()).cx) / 2), ty,
voidtext, StdFont(), SColorText());
else
if(withtext) {
if(withtext || withhex) {
w.DrawRect(2, 2, sz.cy - 4, sz.cy - 4, color);
DrawFrame(w, 1, 1, sz.cy - 2, sz.cy - 2, SColorText);
w.DrawText(sz.cy + 2, ty, FormatColor(color), StdFont(), SColorText());
w.DrawText(sz.cy + 2, ty, withhex ? ColorToHtml(color) : FormatColor(color), StdFont(), SColorText());
}
else {
w.DrawRect(2, 2, sz.cx - 4, sz.cy - 4, color);
@ -101,7 +101,7 @@ ColorPusher::ColorPusher()
nulltext = t_("(transparent)");
voidtext = t_("(none)");
color = Null;
track = push = withtext = false;
track = push = withtext = withhex = false;
colors.WhenSelect = THISBACK(AcceptColors);
colors.WhenCancel = THISBACK(CloseColors);
colors.WhenAction = THISBACK(NewColor);

View file

@ -109,6 +109,7 @@ IMAGE_ID(BigDotH)
IMAGE_ID(Bg)
IMAGE_ID(SortUp)
IMAGE_ID(SortDown)
IMAGE_ID(color_edit)
IMAGE_BEGIN_DATA
IMAGE_DATA(120,156,237,155,237,113,131,48,12,134,181,68,254,247,55,119,189,235,6,76,225,37,178,68,152,135,37,178,4,75,100,10)
@ -551,17 +552,36 @@ IMAGE_DATA(220,166,247,221,111,180,43,132,127,211,142,219,28,121,177,218,120,183
IMAGE_END_DATA(1216, 23)
IMAGE_BEGIN_DATA
IMAGE_DATA(120,156,237,88,59,78,195,64,16,93,139,134,130,34,18,23,200,81,104,144,168,64,138,228,243,112,0,238,192,1,144,184)
IMAGE_DATA(3,13,20,64,97,139,124,148,196,49,118,18,19,62,166,72,67,251,136,29,59,153,181,119,23,7,4,142,208,140,53,26)
IMAGE_DATA(123,102,223,204,123,187,155,38,162,33,26,2,167,66,103,246,194,161,113,91,139,202,112,39,246,33,174,219,151,120,135,35)
IMAGE_DATA(121,146,75,106,154,62,54,197,197,112,75,248,60,71,250,208,30,210,204,243,139,51,58,43,125,79,114,148,75,86,91,205)
IMAGE_DATA(94,214,220,212,139,26,242,153,235,53,14,229,64,214,186,202,168,194,19,14,210,108,217,151,90,142,142,15,8,255,117,173)
IMAGE_DATA(10,94,214,226,110,128,87,241,222,12,175,159,45,227,77,252,76,220,242,187,164,226,24,23,162,138,27,185,67,74,14,203)
IMAGE_DATA(249,198,217,202,251,187,246,226,125,208,222,223,159,254,126,74,125,52,94,198,53,133,69,63,81,107,180,22,116,182,134,76)
IMAGE_DATA(179,64,6,184,66,93,177,206,217,217,134,176,126,214,207,250,89,63,235,103,253,172,159,245,179,126,214,207,250,89,63,235)
IMAGE_DATA(103,253,255,95,255,206,226,49,24,74,25,19,32,104,181,190,4,36,255,212,196,36,38,128,251,236,251,38,141,69,64,214)
IMAGE_DATA(53,141,185,211,188,176,196,254,106,245,124,254,129,135,246,0,237,206,16,157,174,135,110,111,132,94,223,71,127,16,96,48)
IMAGE_DATA(12,49,244,198,240,252,9,70,143,83,248,65,132,32,156,33,156,60,99,60,125,193,36,122,197,244,233,13,209,44,198,237)
IMAGE_DATA(157,3,177,43,246,76,155,243,219,86,222,75,185,6,205,26,40,220,84,211,245,217,46,171,249,48,190,99,85,54,187,202)
IMAGE_DATA(65,84,57,164,63,61,192,79,137,53,141,129,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
IMAGE_END_DATA(416, 11)
IMAGE_DATA(120,156,237,153,127,76,212,101,28,199,143,181,182,254,104,147,173,63,90,182,57,107,53,182,230,106,211,213,98,101,70,9)
IMAGE_DATA(20,153,46,140,86,17,148,242,99,19,133,36,144,227,151,2,195,179,21,173,105,1,2,241,107,32,105,8,73,104,208,143)
IMAGE_DATA(205,168,80,59,181,141,131,227,247,175,227,56,56,32,40,209,193,73,202,243,234,238,56,228,123,220,143,176,86,56,247,253)
IMAGE_DATA(220,62,251,220,247,249,60,239,231,253,126,63,207,243,253,231,78,225,169,240,84,144,166,112,21,65,230,196,69,6,185,68)
IMAGE_DATA(217,112,91,130,124,57,163,173,102,130,38,187,180,140,89,122,46,214,9,146,226,198,209,56,224,231,199,36,235,72,215,176)
IMAGE_DATA(227,44,174,204,146,114,89,191,91,198,164,90,108,189,27,220,115,61,141,53,23,123,152,231,92,152,211,36,213,32,153,171)
IMAGE_DATA(113,90,157,225,37,26,236,184,237,115,206,203,11,155,159,149,232,95,232,45,5,111,239,69,115,19,120,103,186,111,14,239)
IMAGE_DATA(154,219,30,239,78,159,59,109,243,119,201,153,198,241,69,213,153,54,201,29,114,170,97,142,223,45,183,211,251,187,144,139)
IMAGE_DATA(239,131,203,251,251,111,223,31,135,117,92,164,35,110,181,194,67,250,200,178,86,15,179,156,91,70,204,234,69,98,160,129)
IMAGE_DATA(229,170,203,201,109,219,16,217,191,236,95,246,47,251,151,253,203,254,101,255,178,127,217,191,236,95,246,47,251,151,253,203)
IMAGE_DATA(254,111,127,255,119,152,63,110,2,135,17,119,0,93,96,224,223,2,44,191,212,140,75,170,5,112,209,246,124,214,90,23)
IMAGE_DATA(3,108,171,90,235,124,74,199,21,30,138,123,110,204,158,156,156,166,69,219,133,182,181,155,214,182,30,218,218,123,105,239)
IMAGE_DATA(236,163,179,75,71,87,247,0,221,61,122,122,250,6,233,237,55,208,167,27,66,55,96,100,96,112,4,189,97,148,193,161)
IMAGE_DATA(49,12,195,191,49,100,28,231,252,133,38,20,119,41,238,118,183,57,255,117,56,238,165,125,15,23,115,112,146,238,122,174)
IMAGE_DATA(214,185,181,98,153,15,227,159,196,82,54,123,41,7,177,148,67,250,95,15,176,193,242,87,203,237,18,34,49,30,107,38)
IMAGE_DATA(188,199,108,108,12,215,119,69,161,252,124,140,248,35,35,196,148,142,176,179,104,152,136,124,3,161,57,122,252,189,61,183)
IMAGE_DATA(118,84,188,78,247,87,42,154,138,252,216,244,196,138,80,43,246,251,111,16,223,214,33,234,78,34,78,214,224,187,191,159)
IMAGE_DATA(79,234,199,73,172,24,38,174,108,24,85,245,40,225,7,114,49,158,86,114,169,249,20,92,25,226,143,230,42,190,78,243)
IMAGE_DATA(25,153,141,219,141,168,63,133,80,101,32,50,82,17,39,170,240,78,233,228,195,218,49,98,74,12,68,21,14,82,82,85)
IMAGE_DATA(193,104,115,58,51,131,181,24,27,178,152,110,249,146,235,186,70,46,22,108,55,89,244,90,56,197,190,36,68,210,30,68)
IMAGE_DATA(229,49,30,137,239,32,179,122,132,136,60,61,170,146,42,38,180,123,153,157,110,100,186,119,23,19,231,163,105,47,15,67)
IMAGE_DATA(93,248,22,145,37,155,249,51,60,204,202,105,241,47,98,163,17,71,202,88,181,163,141,148,163,70,50,10,190,224,247,150)
IMAGE_DATA(36,102,77,231,152,234,121,27,147,62,152,203,109,201,116,23,7,80,211,88,192,203,185,190,92,13,14,182,114,138,119,119)
IMAGE_DATA(34,118,68,32,74,139,89,249,142,134,172,188,82,140,23,148,54,108,40,166,129,55,153,212,166,208,126,216,143,131,39,226)
IMAGE_DATA(40,255,245,40,27,179,214,51,253,202,86,43,167,136,220,142,216,22,130,248,44,159,151,194,179,209,214,39,152,53,255,132)
IMAGE_DATA(169,63,140,171,250,16,46,153,117,116,30,246,231,64,173,146,184,218,36,10,127,41,229,233,244,199,153,242,15,176,114,138)
IMAGE_DATA(80,179,142,55,94,163,67,21,73,107,93,50,154,250,131,24,212,65,76,245,7,51,209,148,136,250,163,77,28,111,204,39)
IMAGE_DATA(182,70,73,212,241,221,228,154,245,175,75,120,148,43,235,125,172,156,34,47,23,145,243,41,149,31,60,15,151,117,116,20)
IMAGE_DATA(188,202,233,228,149,156,201,123,145,186,76,95,214,62,115,140,98,117,25,249,103,139,200,249,57,143,67,13,217,172,137,246)
IMAGE_DATA(34,125,227,251,236,219,144,201,222,39,211,72,93,151,74,102,248,26,102,206,101,51,163,62,132,90,229,67,249,182,135,120)
IMAGE_DATA(204,187,130,21,94,63,240,240,150,84,30,8,72,102,149,159,146,251,159,219,195,125,27,226,28,94,220,192,167,60,77,251)
IMAGE_DATA(67,188,174,125,167,242,191,246,113,212,218,31,239,93,113,231,131,203,241,94,44,53,254,2,54,237,94,147,0,0,0,0)
IMAGE_END_DATA(1024, 12)

View file

@ -139,6 +139,7 @@ public:
virtual void MouseMove(Point p, dword);
virtual void MouseLeave();
virtual bool Key(dword key, int count);
virtual void Layout();
private:
void PopupDeactivate();
@ -146,7 +147,7 @@ private:
struct Popup : Ctrl {
ColorPopUp *color;
virtual void Deactivate() { color->PopupDeactivate(); }
virtual void Deactivate() { color->PopupDeactivate(); }
};
int Get(Point p);
@ -159,8 +160,8 @@ private:
Color GetColor(int i) const;
void Select();
void DrawFilledFrame(Draw &w, int x, int y, int cx, int cy, Color fcol, Color bcol);
void DrawFilledFrame(Draw &w, Rect &r, Color fcol, Color bcol);
void DrawFilledFrame(Draw &w, int x, int y, int cx, int cy, Color fcol, Color bcol);
void DrawFilledFrame(Draw &w, Rect &r, Color fcol, Color bcol);
int colori;
bool notnull;
@ -176,6 +177,7 @@ private:
ColorRampCtrl ramp;
ColorWheelCtrl wheel;
Button settext;
One<Popup> popup;
static Color hint[18];
@ -196,8 +198,8 @@ public:
ColorPopUp& NotNull(bool b = true) { notnull = b; return *this; }
ColorPopUp& SColors(bool b = true) { scolors = b; return *this; }//Deprecated
ColorPopUp& NullText(const char *s) { nulltext = s; Refresh(); return *this; }
ColorPopUp& VoidText(const char *s) { voidtext = s; Refresh(); return *this; }
ColorPopUp& WithVoid(bool b = true) { withvoid = b; Refresh(); return *this; }
ColorPopUp& VoidText(const char *s) { voidtext = s; Refresh(); return *this; }
ColorPopUp& NoRampWheel(bool b = true) { norampwheel = b; return *this; }
ColorPopUp& Hints(bool b = true) { hints = b; return *this; }
@ -218,6 +220,7 @@ public:
protected:
bool push;
bool withtext;
bool withhex;
bool track;
Color color, saved_color;
ColorPopUp colors;
@ -234,10 +237,11 @@ public:
ColorPusher& NullText(const char *s) { nulltext = s; colors.NullText(s); Refresh(); return *this; }
ColorPusher& NotNull(bool b = true) { colors.NotNull(b); return *this; }
ColorPusher& VoidText(const char *s) { voidtext = s; colors.VoidText(s); Refresh(); return *this; }
ColorPusher& WithVoid(bool b = true) { colors.WithVoid(b); return *this; }
ColorPusher& VoidText(const char *s) { voidtext = s; colors.VoidText(s); Refresh(); return *this; }
ColorPusher& SColors(bool b = true) { colors.SColors(b); return *this; }
ColorPusher& WithText() { withtext = true; return *this; }
ColorPusher& WithText() { withtext = true; Refresh(); return *this; }
ColorPusher& WithHex() { withhex = true; Refresh(); return *this; }
ColorPusher& Track(bool b = true) { track = b; return *this; }
ColorPusher& NoTrack() { return Track(false); }
ColorPusher& NoRampWheel(bool b = true) { colors.NoRampWheel(b); return *this; }

File diff suppressed because one or more lines are too long