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
|
2020-02-05 20:19:48 +13:00
|
|
|
|
Copyright (c) 2007-2020 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;
|
2019-05-23 03:38:22 +12:00
|
|
|
|
using System.ComponentModel;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Drawing.Drawing2D;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
2014-12-11 09:25:20 +13:00
|
|
|
|
namespace ShareX.HelpersLib
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2014-06-28 09:41:07 +12:00
|
|
|
|
public class BlackStyleProgressBar : Control
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2019-05-23 03:38:22 +12:00
|
|
|
|
[DefaultValue(0)]
|
|
|
|
|
public int Minimum
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2019-05-23 03:38:22 +12:00
|
|
|
|
return minimum;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2019-05-23 03:38:22 +12:00
|
|
|
|
if (minimum != value)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
|
|
|
|
if (value < 0)
|
|
|
|
|
{
|
2020-11-28 22:55:42 +13:00
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(Minimum));
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-23 03:38:22 +12:00
|
|
|
|
if (maximum < value)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2019-05-23 03:38:22 +12:00
|
|
|
|
maximum = value;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-23 03:38:22 +12:00
|
|
|
|
minimum = value;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2019-05-23 03:38:22 +12:00
|
|
|
|
if (this.value < minimum)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2019-05-23 03:38:22 +12:00
|
|
|
|
this.value = minimum;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-23 03:38:22 +12:00
|
|
|
|
Invalidate();
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-12 00:14:58 +12:00
|
|
|
|
private int minimum;
|
|
|
|
|
|
2019-05-23 03:38:22 +12:00
|
|
|
|
[DefaultValue(100)]
|
|
|
|
|
public int Maximum
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2019-05-23 03:38:22 +12:00
|
|
|
|
return maximum;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2019-05-23 03:38:22 +12:00
|
|
|
|
if (maximum != value)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
|
|
|
|
if (value < 0)
|
|
|
|
|
{
|
2020-11-28 22:55:42 +13:00
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(Maximum));
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-23 03:38:22 +12:00
|
|
|
|
if (minimum > value)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2019-05-23 03:38:22 +12:00
|
|
|
|
minimum = value;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-23 03:38:22 +12:00
|
|
|
|
maximum = value;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2019-05-23 03:38:22 +12:00
|
|
|
|
if (this.value > maximum)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2019-05-23 03:38:22 +12:00
|
|
|
|
this.value = maximum;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-23 03:38:22 +12:00
|
|
|
|
Invalidate();
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-12 00:14:58 +12:00
|
|
|
|
private int maximum;
|
|
|
|
|
|
2019-05-23 03:38:22 +12:00
|
|
|
|
[DefaultValue(0)]
|
2013-11-03 23:53:49 +13:00
|
|
|
|
public int Value
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (this.value != value)
|
|
|
|
|
{
|
2020-11-28 22:55:42 +13:00
|
|
|
|
if (value < minimum || value > maximum)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2020-11-28 22:55:42 +13:00
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(Value));
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.value = value;
|
|
|
|
|
|
2019-05-23 03:38:22 +12:00
|
|
|
|
Invalidate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-12 00:14:58 +12:00
|
|
|
|
private int value;
|
|
|
|
|
|
2019-05-23 03:38:22 +12:00
|
|
|
|
[DefaultValue(false)]
|
|
|
|
|
public bool ShowPercentageText
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return showPercentageText;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (showPercentageText != value)
|
|
|
|
|
{
|
|
|
|
|
showPercentageText = value;
|
|
|
|
|
|
|
|
|
|
Invalidate();
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-23 03:38:22 +12:00
|
|
|
|
private bool showPercentageText;
|
|
|
|
|
|
2019-06-12 00:14:58 +12:00
|
|
|
|
public override string Text
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return text;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (text != value)
|
|
|
|
|
{
|
|
|
|
|
text = value;
|
|
|
|
|
|
|
|
|
|
Invalidate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string text;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2014-06-28 09:41:07 +12:00
|
|
|
|
public BlackStyleProgressBar()
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2014-06-28 09:41:07 +12:00
|
|
|
|
SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw | ControlStyles.OptimizedDoubleBuffer | ControlStyles.SupportsTransparentBackColor, true);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
|
|
|
|
minimum = 0;
|
2019-05-23 03:38:22 +12:00
|
|
|
|
maximum = 100;
|
|
|
|
|
value = 0;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnPaint(PaintEventArgs pe)
|
|
|
|
|
{
|
|
|
|
|
base.OnPaint(pe);
|
|
|
|
|
|
|
|
|
|
Graphics g = pe.Graphics;
|
|
|
|
|
|
|
|
|
|
DrawBackground(g);
|
|
|
|
|
|
|
|
|
|
if (Value > Minimum && Value <= Maximum)
|
|
|
|
|
{
|
|
|
|
|
DrawProgressBar(g);
|
2019-06-12 00:14:58 +12:00
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(Text))
|
|
|
|
|
{
|
|
|
|
|
DrawText(g, Text);
|
|
|
|
|
}
|
|
|
|
|
else if (ShowPercentageText)
|
|
|
|
|
{
|
|
|
|
|
DrawText(g, Value + "%");
|
|
|
|
|
}
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DrawBackground(Graphics g)
|
|
|
|
|
{
|
|
|
|
|
using (LinearGradientBrush backgroundBrush = new LinearGradientBrush(new Rectangle(1, 1, ClientSize.Width - 2, ClientSize.Height - 2),
|
|
|
|
|
Color.FromArgb(50, 50, 50), Color.FromArgb(60, 60, 60), LinearGradientMode.Vertical))
|
|
|
|
|
{
|
|
|
|
|
g.FillRectangle(backgroundBrush, new Rectangle(1, 1, ClientSize.Width - 2, ClientSize.Height - 2));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
using (Pen borderShadowPen = new Pen(Color.FromArgb(45, 45, 45)))
|
|
|
|
|
{
|
|
|
|
|
g.DrawLine(borderShadowPen, new Point(1, 1), new Point(ClientSize.Width - 2, 1));
|
|
|
|
|
g.DrawLine(borderShadowPen, new Point(ClientSize.Width - 2, 1), new Point(ClientSize.Width - 2, ClientSize.Height - 2));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
using (Pen borderPen = new Pen(Color.FromArgb(30, 30, 30)))
|
|
|
|
|
{
|
|
|
|
|
g.DrawRectangle(borderPen, new Rectangle(0, 0, ClientSize.Width - 1, ClientSize.Height - 1));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DrawProgressBar(Graphics g)
|
|
|
|
|
{
|
|
|
|
|
double progressBarSize = (double)Value / Maximum * (ClientSize.Width - 2);
|
|
|
|
|
Rectangle progressBarRect = new Rectangle(1, 1, (int)progressBarSize, ClientSize.Height - 2);
|
|
|
|
|
|
|
|
|
|
using (LinearGradientBrush progressBarBrush = new LinearGradientBrush(progressBarRect, Color.Black, Color.Black, LinearGradientMode.Vertical))
|
|
|
|
|
{
|
|
|
|
|
ColorBlend cb = new ColorBlend();
|
|
|
|
|
cb.Positions = new float[] { 0, 0.49f, 0.50f, 1 };
|
|
|
|
|
cb.Colors = new Color[] { Color.FromArgb(102, 163, 226), Color.FromArgb(83, 135, 186), Color.FromArgb(75, 121, 175), Color.FromArgb(56, 93, 135) };
|
|
|
|
|
progressBarBrush.InterpolationColors = cb;
|
|
|
|
|
|
|
|
|
|
g.FillRectangle(progressBarBrush, progressBarRect);
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-28 09:41:07 +12:00
|
|
|
|
using (LinearGradientBrush innerBorderBrush = new LinearGradientBrush(progressBarRect, Color.FromArgb(133, 192, 241), Color.FromArgb(76, 119, 163), LinearGradientMode.Vertical))
|
2013-11-03 23:53:49 +13:00
|
|
|
|
using (Pen innerBorderPen = new Pen(innerBorderBrush))
|
|
|
|
|
{
|
|
|
|
|
g.DrawRectangle(innerBorderPen, new Rectangle(progressBarRect.X, progressBarRect.Y, progressBarRect.Width - 1, progressBarRect.Height - 1));
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-05-23 03:38:22 +12:00
|
|
|
|
|
|
|
|
|
private void DrawText(Graphics g, string text)
|
|
|
|
|
{
|
2019-06-12 00:14:58 +12:00
|
|
|
|
TextRenderer.DrawText(g, text, Font, ClientRectangle.LocationOffset(0, 1), Color.Black, TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter);
|
|
|
|
|
TextRenderer.DrawText(g, text, Font, ClientRectangle, ForeColor, TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter);
|
2019-05-23 03:38:22 +12:00
|
|
|
|
}
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
}
|