2013-11-03 23:53:49 +13:00
|
|
|
|
#region License Information (GPL v3)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
ShareX - A program that allows you to take screenshots and share any file type
|
2016-01-04 04:16:01 +13:00
|
|
|
|
Copyright (c) 2007-2016 ShareX Team
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
|
|
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#endregion License Information (GPL v3)
|
|
|
|
|
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
|
2014-12-11 09:25:20 +13:00
|
|
|
|
namespace ShareX.HelpersLib
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
|
|
|
|
public class ColorSlider : ColorUserControl
|
|
|
|
|
{
|
|
|
|
|
public ColorSlider()
|
|
|
|
|
{
|
|
|
|
|
Initialize();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
Name = "ColorSlider";
|
2013-11-04 07:48:46 +13:00
|
|
|
|
ClientSize = new Size(30, 256);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
base.Initialize();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void DrawCrosshair(Graphics g)
|
|
|
|
|
{
|
2013-11-04 07:48:46 +13:00
|
|
|
|
DrawCrosshair(g, Pens.Black, 3, 11);
|
|
|
|
|
DrawCrosshair(g, Pens.White, 4, 9);
|
|
|
|
|
}
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2013-11-04 07:48:46 +13:00
|
|
|
|
private void DrawCrosshair(Graphics g, Pen pen, int offset, int height)
|
|
|
|
|
{
|
|
|
|
|
g.DrawRectangleProper(pen, new Rectangle(offset, lastPos.Y - height / 2, ClientWidth - offset * 2, height));
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Y = Hue 360 -> 0
|
|
|
|
|
protected override void DrawHue()
|
|
|
|
|
{
|
|
|
|
|
using (Graphics g = Graphics.FromImage(bmp))
|
|
|
|
|
{
|
|
|
|
|
HSB color = new HSB(0.0, 1.0, 1.0, SelectedColor.RGBA.Alpha);
|
|
|
|
|
|
2013-11-04 07:48:46 +13:00
|
|
|
|
for (int y = 0; y < ClientHeight; y++)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2013-11-04 07:48:46 +13:00
|
|
|
|
color.Hue = 1.0 - (double)y / (ClientHeight - 1);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
|
|
|
|
using (Pen pen = new Pen(color))
|
|
|
|
|
{
|
2013-11-04 07:48:46 +13:00
|
|
|
|
g.DrawLine(pen, 0, y, ClientWidth, y);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Y = Saturation 100 -> 0
|
|
|
|
|
protected override void DrawSaturation()
|
|
|
|
|
{
|
|
|
|
|
using (Graphics g = Graphics.FromImage(bmp))
|
|
|
|
|
{
|
|
|
|
|
HSB color = new HSB(SelectedColor.HSB.Hue, 0.0, SelectedColor.HSB.Brightness, SelectedColor.RGBA.Alpha);
|
|
|
|
|
|
2013-11-04 07:48:46 +13:00
|
|
|
|
for (int y = 0; y < ClientHeight; y++)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2013-11-04 07:48:46 +13:00
|
|
|
|
color.Saturation = 1.0 - (double)y / (ClientHeight - 1);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
|
|
|
|
using (Pen pen = new Pen(color))
|
|
|
|
|
{
|
2013-11-04 07:48:46 +13:00
|
|
|
|
g.DrawLine(pen, 0, y, ClientWidth, y);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Y = Brightness 100 -> 0
|
|
|
|
|
protected override void DrawBrightness()
|
|
|
|
|
{
|
|
|
|
|
using (Graphics g = Graphics.FromImage(bmp))
|
|
|
|
|
{
|
|
|
|
|
HSB color = new HSB(SelectedColor.HSB.Hue, SelectedColor.HSB.Saturation, 0.0, SelectedColor.RGBA.Alpha);
|
|
|
|
|
|
2013-11-04 07:48:46 +13:00
|
|
|
|
for (int y = 0; y < ClientHeight; y++)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2013-11-04 07:48:46 +13:00
|
|
|
|
color.Brightness = 1.0 - (double)y / (ClientHeight - 1);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
|
|
|
|
using (Pen pen = new Pen(color))
|
|
|
|
|
{
|
2013-11-04 07:48:46 +13:00
|
|
|
|
g.DrawLine(pen, 0, y, ClientWidth, y);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Y = Red 255 -> 0
|
|
|
|
|
protected override void DrawRed()
|
|
|
|
|
{
|
|
|
|
|
using (Graphics g = Graphics.FromImage(bmp))
|
|
|
|
|
{
|
|
|
|
|
RGBA color = new RGBA(0, SelectedColor.RGBA.Green, SelectedColor.RGBA.Blue, SelectedColor.RGBA.Alpha);
|
|
|
|
|
|
2013-11-04 07:48:46 +13:00
|
|
|
|
for (int y = 0; y < ClientHeight; y++)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2013-11-04 07:48:46 +13:00
|
|
|
|
color.Red = 255 - Round(255 * (double)y / (ClientHeight - 1));
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
|
|
|
|
using (Pen pen = new Pen(color))
|
|
|
|
|
{
|
2013-11-04 07:48:46 +13:00
|
|
|
|
g.DrawLine(pen, 0, y, ClientWidth, y);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Y = Green 255 -> 0
|
|
|
|
|
protected override void DrawGreen()
|
|
|
|
|
{
|
|
|
|
|
using (Graphics g = Graphics.FromImage(bmp))
|
|
|
|
|
{
|
|
|
|
|
RGBA color = new RGBA(SelectedColor.RGBA.Red, 0, SelectedColor.RGBA.Blue, SelectedColor.RGBA.Alpha);
|
|
|
|
|
|
2013-11-04 07:48:46 +13:00
|
|
|
|
for (int y = 0; y < ClientHeight; y++)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2013-11-04 07:48:46 +13:00
|
|
|
|
color.Green = 255 - Round(255 * (double)y / (ClientHeight - 1));
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
|
|
|
|
using (Pen pen = new Pen(color))
|
|
|
|
|
{
|
2013-11-04 07:48:46 +13:00
|
|
|
|
g.DrawLine(pen, 0, y, ClientWidth, y);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Y = Blue 255 -> 0
|
|
|
|
|
protected override void DrawBlue()
|
|
|
|
|
{
|
|
|
|
|
using (Graphics g = Graphics.FromImage(bmp))
|
|
|
|
|
{
|
|
|
|
|
RGBA color = new RGBA(SelectedColor.RGBA.Red, SelectedColor.RGBA.Green, 0, SelectedColor.RGBA.Alpha);
|
|
|
|
|
|
2013-11-04 07:48:46 +13:00
|
|
|
|
for (int y = 0; y < ClientHeight; y++)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2013-11-04 07:48:46 +13:00
|
|
|
|
color.Blue = 255 - Round(255 * (double)y / (ClientHeight - 1));
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
|
|
|
|
using (Pen pen = new Pen(color))
|
|
|
|
|
{
|
2013-11-04 07:48:46 +13:00
|
|
|
|
g.DrawLine(pen, 0, y, ClientWidth, y);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|