From 2aeb2080dc3704ce8aa0cba74eeed26acb275aa3 Mon Sep 17 00:00:00 2001 From: cxl Date: Thu, 20 Dec 2018 13:47:28 +0000 Subject: [PATCH] .upptst git-svn-id: svn://ultimatepp.org/upp/trunk@12630 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- upptst/DarkingColors/DarkingColors.upp | 9 +++++ upptst/DarkingColors/main.cpp | 48 ++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 upptst/DarkingColors/DarkingColors.upp create mode 100644 upptst/DarkingColors/main.cpp diff --git a/upptst/DarkingColors/DarkingColors.upp b/upptst/DarkingColors/DarkingColors.upp new file mode 100644 index 000000000..5872304d3 --- /dev/null +++ b/upptst/DarkingColors/DarkingColors.upp @@ -0,0 +1,9 @@ +uses + CtrlLib; + +file + main.cpp; + +mainconfig + "" = "GUI"; + diff --git a/upptst/DarkingColors/main.cpp b/upptst/DarkingColors/main.cpp new file mode 100644 index 000000000..3b58cf180 --- /dev/null +++ b/upptst/DarkingColors/main.cpp @@ -0,0 +1,48 @@ +#include + +using namespace Upp; + +Color MakeDark0(Color c) +{ + int n = Grayscale(c); + if(n < 70) + return Color(min(c.GetR() + 128, 255), min(c.GetG() + 128, 255), min(c.GetB() + 128, 255)); + if(n > 190) + return Color(max(c.GetR() - 128, 0), max(c.GetG() - 128, 0), max(c.GetB() - 128, 0)); + return c; +} + +Color MakeDark(Color c) +{ + double h, s, v; + const double m = 1/255.0; + RGBtoHSV(c.GetR() * m, c.GetG() * m, c.GetB() * m, h, s, v); + DDUMP(c); + DDUMP(h); + DDUMP(s); + DDUMP(v); + if(s > v) + return HsvColorf(h, 1 - s, v); + else + return HsvColorf(h, s, 1 - v); +} + +struct ColorTest : TopWindow { + ColorSelector color; + + void Paint(Draw& w) override { + Size sz = GetSize(); + w.DrawRect(0, 0, sz.cx, sz.cy / 2, ~color); + w.DrawRect(0, sz.cy / 2, sz.cx, sz.cy / 2 + 1, MakeDark(~color)); + } + + ColorTest() { + Add(color.LeftPosZ(0, 300).TopPosZ(0, 300)); + color << [=] { Refresh(); }; + } +}; + +GUI_APP_MAIN +{ + ColorTest().Run(); +}