2018-04-04 08:08:24 +12:00
|
|
|
|
#region License Information (GPL v3)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
ShareX - A program that allows you to take screenshots and share any file type
|
|
|
|
|
Copyright (c) 2007-2018 ShareX Team
|
|
|
|
|
|
|
|
|
|
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 ShareX.HelpersLib;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Drawing.Drawing2D;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace ShareX.ScreenCaptureLib
|
|
|
|
|
{
|
|
|
|
|
internal class ImageEditorScrollbar : DrawableObject
|
|
|
|
|
{
|
|
|
|
|
public Orientation Orientation { get; set; }
|
|
|
|
|
public int Thickness { get; set; } = 10;
|
|
|
|
|
public int Margin { get; set; } = 15;
|
|
|
|
|
public int Padding { get; set; } = 2;
|
2018-04-04 09:39:56 +12:00
|
|
|
|
public float Opacity { get; set; }
|
2018-04-04 08:08:24 +12:00
|
|
|
|
public Rectangle ThumbRectangle { get; set; }
|
|
|
|
|
|
|
|
|
|
private RegionCaptureForm form;
|
|
|
|
|
|
|
|
|
|
public ImageEditorScrollbar(Orientation orientation, RegionCaptureForm form)
|
|
|
|
|
{
|
|
|
|
|
Orientation = orientation;
|
|
|
|
|
this.form = form;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Update()
|
|
|
|
|
{
|
2018-04-04 09:39:56 +12:00
|
|
|
|
UpdateOpacity();
|
2018-04-04 08:08:24 +12:00
|
|
|
|
|
2018-04-04 09:39:56 +12:00
|
|
|
|
if (Visible)
|
2018-04-04 08:08:24 +12:00
|
|
|
|
{
|
2018-04-04 09:39:56 +12:00
|
|
|
|
Rectangle imageRectangleVisible = form.CanvasRectangle;
|
|
|
|
|
imageRectangleVisible.Intersect(form.ClientArea);
|
2018-04-04 08:08:24 +12:00
|
|
|
|
|
2018-04-04 09:39:56 +12:00
|
|
|
|
if (Orientation == Orientation.Horizontal)
|
2018-04-04 08:08:24 +12:00
|
|
|
|
{
|
2018-04-04 11:01:32 +12:00
|
|
|
|
int horizontalTrackLength = form.ClientArea.Width - Margin * 2 - Padding * 2 - Thickness;
|
2018-04-04 08:08:24 +12:00
|
|
|
|
|
2018-04-04 11:01:32 +12:00
|
|
|
|
Rectangle = new Rectangle(Margin, form.ClientArea.Bottom - Margin - Padding * 2 - Thickness - 1, horizontalTrackLength, Padding * 2 + Thickness);
|
|
|
|
|
|
|
|
|
|
int horizontalThumbLength = Math.Max(Thickness, (int)Math.Round((float)imageRectangleVisible.Width /
|
|
|
|
|
form.CanvasRectangle.Width * (horizontalTrackLength - Padding * 2)));
|
2018-04-04 08:08:24 +12:00
|
|
|
|
|
|
|
|
|
double limitHorizontal = (horizontalTrackLength - horizontalThumbLength) / 2.0f;
|
2018-04-04 11:01:32 +12:00
|
|
|
|
double thumbHorizontalPositionX = Math.Round(Rectangle.X + Rectangle.Width / 2.0f - (horizontalThumbLength / 2.0f) + Padding -
|
|
|
|
|
Math.Min(limitHorizontal, Math.Max(-limitHorizontal, form.CanvasCenterOffset.X / form.CanvasRectangle.Width * (horizontalTrackLength - Padding * 2))));
|
2018-04-04 08:08:24 +12:00
|
|
|
|
|
2018-04-04 11:01:32 +12:00
|
|
|
|
ThumbRectangle = new Rectangle((int)thumbHorizontalPositionX, form.ClientArea.Bottom - Margin - Padding - Thickness - 1, horizontalThumbLength, Thickness);
|
2018-04-04 08:08:24 +12:00
|
|
|
|
}
|
2018-04-04 09:39:56 +12:00
|
|
|
|
else
|
2018-04-04 08:08:24 +12:00
|
|
|
|
{
|
2018-04-04 11:01:32 +12:00
|
|
|
|
int verticalTrackLength = form.ClientArea.Height - Margin * 2 - Padding * 2 - Thickness;
|
|
|
|
|
|
|
|
|
|
Rectangle = new Rectangle(form.ClientArea.Right - Margin - Padding * 2 - Thickness - 1, Margin, Padding * 2 + Thickness, verticalTrackLength);
|
2018-04-04 08:08:24 +12:00
|
|
|
|
|
2018-04-04 11:01:32 +12:00
|
|
|
|
int verticalThumbLength = Math.Max(Thickness, (int)Math.Round((float)imageRectangleVisible.Height /
|
|
|
|
|
form.CanvasRectangle.Height * (verticalTrackLength - Padding * 2)));
|
2018-04-04 08:08:24 +12:00
|
|
|
|
|
|
|
|
|
double limitVertical = (verticalTrackLength - verticalThumbLength) / 2.0f;
|
2018-04-04 11:01:32 +12:00
|
|
|
|
double thumbVerticalPositionY = Math.Round(Rectangle.Y + Rectangle.Height / 2.0f - (verticalThumbLength / 2.0f) + Padding -
|
2018-04-04 08:08:24 +12:00
|
|
|
|
Math.Min(limitVertical, Math.Max(-limitVertical, form.CanvasCenterOffset.Y / form.CanvasRectangle.Height * verticalTrackLength)));
|
|
|
|
|
|
2018-04-04 11:01:32 +12:00
|
|
|
|
ThumbRectangle = new Rectangle(form.ClientArea.Right - Margin - Padding - Thickness - 1, (int)thumbVerticalPositionY, Thickness, verticalThumbLength);
|
2018-04-04 08:08:24 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-04 09:39:56 +12:00
|
|
|
|
private void UpdateOpacity()
|
2018-04-04 08:08:24 +12:00
|
|
|
|
{
|
2018-04-04 09:39:56 +12:00
|
|
|
|
bool isScrollbarNeeded;
|
2018-04-04 08:08:24 +12:00
|
|
|
|
|
2018-04-04 09:39:56 +12:00
|
|
|
|
if (Orientation == Orientation.Horizontal)
|
2018-04-04 08:08:24 +12:00
|
|
|
|
{
|
2018-04-04 09:39:56 +12:00
|
|
|
|
isScrollbarNeeded = form.CanvasRectangle.Left < form.ClientArea.Left || form.CanvasRectangle.Right > form.ClientArea.Right;
|
2018-04-04 08:08:24 +12:00
|
|
|
|
}
|
2018-04-04 09:39:56 +12:00
|
|
|
|
else
|
2018-04-04 08:27:33 +12:00
|
|
|
|
{
|
2018-04-04 09:39:56 +12:00
|
|
|
|
isScrollbarNeeded = form.CanvasRectangle.Top < form.ClientArea.Top || form.CanvasRectangle.Bottom > form.ClientArea.Bottom;
|
2018-04-04 08:27:33 +12:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-04 09:39:56 +12:00
|
|
|
|
if (!isScrollbarNeeded)
|
|
|
|
|
{
|
|
|
|
|
Opacity = 0f;
|
|
|
|
|
}
|
|
|
|
|
else if (form.ShapeManager.IsPanning || IsCursorHover)
|
2018-04-04 08:27:33 +12:00
|
|
|
|
{
|
2018-04-04 09:39:56 +12:00
|
|
|
|
Opacity = 1f;
|
2018-04-04 08:27:33 +12:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-04-04 11:01:32 +12:00
|
|
|
|
Opacity = 0.8f;
|
2018-04-04 08:27:33 +12:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-04 09:39:56 +12:00
|
|
|
|
Visible = Opacity > 0;
|
2018-04-04 08:27:33 +12:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-04 09:39:56 +12:00
|
|
|
|
public override void OnDraw(Graphics g)
|
2018-04-04 08:08:24 +12:00
|
|
|
|
{
|
2018-04-04 09:39:56 +12:00
|
|
|
|
if (!Visible) return;
|
2018-04-04 08:08:24 +12:00
|
|
|
|
|
2018-04-04 09:39:56 +12:00
|
|
|
|
using (Brush trackBrush = new SolidBrush(Color.FromArgb((int)(255 * Opacity), 60, 60, 60)))
|
|
|
|
|
using (Brush thumbBrush = new SolidBrush(Color.FromArgb((int)(255 * Opacity), 130, 130, 130)))
|
|
|
|
|
{
|
|
|
|
|
g.SmoothingMode = SmoothingMode.HighQuality;
|
|
|
|
|
g.DrawCapsule(trackBrush, Rectangle);
|
|
|
|
|
g.DrawCapsule(thumbBrush, ThumbRectangle);
|
|
|
|
|
g.SmoothingMode = SmoothingMode.None;
|
|
|
|
|
}
|
2018-04-04 08:08:24 +12:00
|
|
|
|
}
|
2018-04-04 11:01:32 +12:00
|
|
|
|
|
|
|
|
|
public override void OnMouseDown(Point position)
|
|
|
|
|
{
|
|
|
|
|
base.OnMouseDown(position);
|
|
|
|
|
|
|
|
|
|
// Pan here
|
|
|
|
|
}
|
2018-04-04 08:08:24 +12:00
|
|
|
|
}
|
|
|
|
|
}
|