2013-11-17 23:27:23 +13:00
|
|
|
|
#region License Information (GPL v3)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
ShareX - A program that allows you to take screenshots and share any file type
|
2020-02-05 20:19:48 +13:00
|
|
|
|
Copyright (c) 2007-2020 ShareX Team
|
2013-11-17 23:27:23 +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)
|
|
|
|
|
|
2018-04-24 23:15:17 +12:00
|
|
|
|
using System;
|
2013-11-17 23:27:23 +13:00
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
2014-12-11 09:25:20 +13:00
|
|
|
|
namespace ShareX.HelpersLib
|
2013-11-17 23:27:23 +13:00
|
|
|
|
{
|
|
|
|
|
[DefaultEvent("ColorChanged")]
|
|
|
|
|
public class ColorButton : Button
|
|
|
|
|
{
|
|
|
|
|
public delegate void ColorChangedEventHandler(Color color);
|
|
|
|
|
public event ColorChangedEventHandler ColorChanged;
|
|
|
|
|
|
|
|
|
|
private Color color;
|
|
|
|
|
|
|
|
|
|
public Color Color
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return color;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
color = value;
|
2019-05-26 01:11:52 +12:00
|
|
|
|
|
2013-11-17 23:27:23 +13:00
|
|
|
|
OnColorChanged(color);
|
2019-05-26 01:11:52 +12:00
|
|
|
|
|
|
|
|
|
Invalidate();
|
2013-11-17 23:27:23 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-24 20:13:23 +12:00
|
|
|
|
[DefaultValue(typeof(Color), "DarkGray")]
|
|
|
|
|
public Color BorderColor { get; set; } = Color.DarkGray;
|
|
|
|
|
|
2018-04-20 06:59:02 +12:00
|
|
|
|
[DefaultValue(3)]
|
2018-04-18 14:20:41 +12:00
|
|
|
|
public int Offset { get; set; } = 3;
|
|
|
|
|
|
2018-04-24 23:15:17 +12:00
|
|
|
|
[DefaultValue(false)]
|
|
|
|
|
public bool HoverEffect { get; set; } = false;
|
|
|
|
|
|
2016-09-02 00:06:30 +12:00
|
|
|
|
[DefaultValue(false)]
|
|
|
|
|
public bool ManualButtonClick { get; set; }
|
|
|
|
|
|
2018-04-24 23:15:17 +12:00
|
|
|
|
private bool isMouseHover;
|
|
|
|
|
|
2013-11-17 23:27:23 +13:00
|
|
|
|
protected void OnColorChanged(Color color)
|
|
|
|
|
{
|
|
|
|
|
if (ColorChanged != null)
|
|
|
|
|
{
|
|
|
|
|
ColorChanged(color);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnMouseClick(MouseEventArgs mevent)
|
|
|
|
|
{
|
|
|
|
|
base.OnMouseClick(mevent);
|
|
|
|
|
|
2016-09-02 00:06:30 +12:00
|
|
|
|
if (!ManualButtonClick)
|
|
|
|
|
{
|
|
|
|
|
ShowColorDialog();
|
|
|
|
|
}
|
2014-09-08 18:40:04 +12:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ShowColorDialog()
|
|
|
|
|
{
|
2018-04-24 19:28:34 +12:00
|
|
|
|
if (ColorPickerForm.PickColor(Color, out Color newColor, FindForm()))
|
2013-11-17 23:27:23 +13:00
|
|
|
|
{
|
2017-05-28 10:29:33 +12:00
|
|
|
|
Color = newColor;
|
2013-11-17 23:27:23 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-24 23:15:17 +12:00
|
|
|
|
protected override void OnMouseEnter(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
isMouseHover = true;
|
|
|
|
|
|
|
|
|
|
base.OnMouseEnter(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnMouseLeave(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
isMouseHover = false;
|
|
|
|
|
|
|
|
|
|
base.OnMouseLeave(e);
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-17 23:27:23 +13:00
|
|
|
|
protected override void OnPaint(PaintEventArgs pevent)
|
|
|
|
|
{
|
2021-01-01 14:52:35 +13:00
|
|
|
|
base.OnPaint(pevent);
|
2013-11-17 23:27:23 +13:00
|
|
|
|
|
2018-05-17 01:27:11 +12:00
|
|
|
|
int boxSize = ClientRectangle.Height - (Offset * 2);
|
2018-04-18 14:20:41 +12:00
|
|
|
|
Rectangle boxRectangle = new Rectangle(ClientRectangle.Width - Offset - boxSize, Offset, boxSize, boxSize);
|
2013-11-17 23:27:23 +13:00
|
|
|
|
|
|
|
|
|
Graphics g = pevent.Graphics;
|
|
|
|
|
|
2020-09-30 10:52:20 +13:00
|
|
|
|
if (Color.IsTransparent())
|
2013-11-17 23:27:23 +13:00
|
|
|
|
{
|
2017-03-25 10:16:44 +13:00
|
|
|
|
using (Image checker = ImageHelpers.CreateCheckerPattern(boxSize, boxSize))
|
2013-11-17 23:27:23 +13:00
|
|
|
|
{
|
|
|
|
|
g.DrawImage(checker, boxRectangle);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-02 00:06:30 +12:00
|
|
|
|
if (Color.A > 0)
|
2013-11-17 23:27:23 +13:00
|
|
|
|
{
|
2016-09-02 00:06:30 +12:00
|
|
|
|
using (Brush brush = new SolidBrush(Color))
|
|
|
|
|
{
|
|
|
|
|
g.FillRectangle(brush, boxRectangle);
|
|
|
|
|
}
|
2013-11-17 23:27:23 +13:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-24 23:15:17 +12:00
|
|
|
|
if (HoverEffect && isMouseHover)
|
|
|
|
|
{
|
|
|
|
|
using (Brush hoverBrush = new SolidBrush(Color.FromArgb(100, 255, 255, 255)))
|
|
|
|
|
{
|
|
|
|
|
g.FillRectangle(hoverBrush, boxRectangle);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-24 20:13:23 +12:00
|
|
|
|
using (Pen borderPen = new Pen(BorderColor))
|
|
|
|
|
{
|
|
|
|
|
g.DrawRectangleProper(borderPen, boxRectangle);
|
|
|
|
|
}
|
2013-11-17 23:27:23 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|