mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-04 12:14:45 +13:00
Added ScrollbarManager
This commit is contained in:
parent
fbf5f88ce1
commit
6c1047eab8
3 changed files with 141 additions and 63 deletions
|
@ -101,6 +101,7 @@ public Color CurrentColor
|
||||||
private TextAnimation editorPanTipAnimation;
|
private TextAnimation editorPanTipAnimation;
|
||||||
private Bitmap bmpBackgroundImage;
|
private Bitmap bmpBackgroundImage;
|
||||||
private Cursor defaultCursor;
|
private Cursor defaultCursor;
|
||||||
|
private ScrollbarManager scrollbarManager;
|
||||||
|
|
||||||
public RegionCaptureForm(RegionCaptureMode mode, RegionCaptureOptions options, Image canvas = null)
|
public RegionCaptureForm(RegionCaptureMode mode, RegionCaptureOptions options, Image canvas = null)
|
||||||
{
|
{
|
||||||
|
@ -118,7 +119,12 @@ public RegionCaptureForm(RegionCaptureMode mode, RegionCaptureOptions options, I
|
||||||
{
|
{
|
||||||
Duration = TimeSpan.FromMilliseconds(200)
|
Duration = TimeSpan.FromMilliseconds(200)
|
||||||
};
|
};
|
||||||
if (IsEditorMode && Options.ShowEditorPanTip)
|
|
||||||
|
if (IsEditorMode)
|
||||||
|
{
|
||||||
|
scrollbarManager = new ScrollbarManager(this);
|
||||||
|
|
||||||
|
if (Options.ShowEditorPanTip)
|
||||||
{
|
{
|
||||||
editorPanTipAnimation = new TextAnimation()
|
editorPanTipAnimation = new TextAnimation()
|
||||||
{
|
{
|
||||||
|
@ -127,6 +133,7 @@ public RegionCaptureForm(RegionCaptureMode mode, RegionCaptureOptions options, I
|
||||||
Text = Resources.RegionCaptureForm_TipYouCanPanImageByHoldingMouseMiddleButtonAndDragging
|
Text = Resources.RegionCaptureForm_TipYouCanPanImageByHoldingMouseMiddleButtonAndDragging
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
borderPen = new Pen(Color.Black);
|
borderPen = new Pen(Color.Black);
|
||||||
borderDotPen = new Pen(Color.White) { DashPattern = new float[] { 5, 5 } };
|
borderDotPen = new Pen(Color.White) { DashPattern = new float[] { 5, 5 } };
|
||||||
|
@ -667,6 +674,11 @@ private void UpdateCoordinates()
|
||||||
borderDotPen.DashOffset = (float)timerStart.Elapsed.TotalSeconds * -15;
|
borderDotPen.DashOffset = (float)timerStart.Elapsed.TotalSeconds * -15;
|
||||||
|
|
||||||
ShapeManager.Update();
|
ShapeManager.Update();
|
||||||
|
|
||||||
|
if (scrollbarManager != null)
|
||||||
|
{
|
||||||
|
scrollbarManager.Update();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnPaintBackground(PaintEventArgs e)
|
protected override void OnPaintBackground(PaintEventArgs e)
|
||||||
|
@ -864,10 +876,10 @@ private void Draw(Graphics g)
|
||||||
DrawTextAnimation(g, ShapeManager.MenuTextAnimation);
|
DrawTextAnimation(g, ShapeManager.MenuTextAnimation);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw scroll bars while panning
|
// Draw scroll bars
|
||||||
if (ShapeManager.IsPanning)
|
if (scrollbarManager != null)
|
||||||
{
|
{
|
||||||
DrawPanningScrollbars(g);
|
scrollbarManager.Draw(g);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1023,60 +1035,6 @@ private void DrawBottomTipAnimation(Graphics g, TextAnimation textAnimation)
|
||||||
DrawTextAnimation(g, textAnimation, textRectangle, padding);
|
DrawTextAnimation(g, textAnimation, textRectangle, padding);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DrawPanningScrollbars(Graphics g)
|
|
||||||
{
|
|
||||||
if (ClientArea.Contains(CanvasRectangle)) return;
|
|
||||||
|
|
||||||
int scrollbarThickness = 10;
|
|
||||||
int trackMargin = 15;
|
|
||||||
int trackPadding = 2;
|
|
||||||
|
|
||||||
Rectangle imageRectangleVisible = CanvasRectangle;
|
|
||||||
imageRectangleVisible.Intersect(ClientArea);
|
|
||||||
|
|
||||||
using (Brush trackBrush = new SolidBrush(Color.FromArgb(255, 60, 60, 60)))
|
|
||||||
using (Brush thumbBrush = new SolidBrush(Color.FromArgb(255, 130, 130, 130)))
|
|
||||||
{
|
|
||||||
if (CanvasRectangle.Left < ClientArea.Left || CanvasRectangle.Right > ClientArea.Right)
|
|
||||||
{
|
|
||||||
int trackHorizontalLength = ClientArea.Width - trackMargin * 2 - scrollbarThickness - trackPadding * 2;
|
|
||||||
int thumbHorizontalLength = Math.Max(scrollbarThickness, (int)Math.Round((float)imageRectangleVisible.Width / CanvasRectangle.Width * trackHorizontalLength));
|
|
||||||
|
|
||||||
Rectangle trackHorizontalRegion = new Rectangle(new Point(trackMargin - trackPadding, ClientArea.Bottom - (scrollbarThickness + trackMargin) - trackPadding), new Size(trackHorizontalLength + trackPadding * 2, scrollbarThickness + trackPadding * 2));
|
|
||||||
|
|
||||||
double limitHorizontal = (trackHorizontalLength - thumbHorizontalLength) / 2.0f;
|
|
||||||
double thumbHorizontalPositionX = Math.Round(trackHorizontalRegion.X + trackHorizontalRegion.Width / 2.0f - (thumbHorizontalLength / 2.0f) -
|
|
||||||
Math.Min(limitHorizontal, Math.Max(-limitHorizontal, CanvasCenterOffset.X / CanvasRectangle.Width * trackHorizontalLength)));
|
|
||||||
|
|
||||||
Rectangle thumbHorizontalRegion = new Rectangle(new Point((int)thumbHorizontalPositionX, ClientArea.Bottom - (scrollbarThickness + trackMargin)), new Size(thumbHorizontalLength, scrollbarThickness));
|
|
||||||
|
|
||||||
g.SmoothingMode = SmoothingMode.HighQuality;
|
|
||||||
g.DrawCapsule(trackBrush, trackHorizontalRegion);
|
|
||||||
g.DrawCapsule(thumbBrush, thumbHorizontalRegion);
|
|
||||||
g.SmoothingMode = SmoothingMode.None;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (CanvasRectangle.Top < ClientArea.Top || CanvasRectangle.Bottom > ClientArea.Bottom)
|
|
||||||
{
|
|
||||||
int trackVerticalLength = ClientArea.Height - trackMargin * 2 - scrollbarThickness - trackPadding * 2;
|
|
||||||
int thumbVerticalLength = Math.Max(scrollbarThickness, (int)Math.Round((float)imageRectangleVisible.Height / CanvasRectangle.Height * trackVerticalLength));
|
|
||||||
|
|
||||||
Rectangle trackVerticalRegion = new Rectangle(new Point(ClientArea.Right - (scrollbarThickness + trackMargin) - trackPadding, trackMargin - trackPadding), new Size(scrollbarThickness + trackPadding * 2, trackVerticalLength + trackPadding * 2));
|
|
||||||
|
|
||||||
double limitVertical = (trackVerticalLength - thumbVerticalLength) / 2.0f;
|
|
||||||
double thumbVerticalPositionY = Math.Round(trackVerticalRegion.Y + trackVerticalRegion.Height / 2.0f - (thumbVerticalLength / 2.0f) -
|
|
||||||
Math.Min(limitVertical, Math.Max(-limitVertical, CanvasCenterOffset.Y / CanvasRectangle.Height * trackVerticalLength)));
|
|
||||||
|
|
||||||
Rectangle thumbVerticalRegion = new Rectangle(new Point(ClientArea.Right - (scrollbarThickness + trackMargin), (int)thumbVerticalPositionY), new Size(scrollbarThickness, thumbVerticalLength));
|
|
||||||
|
|
||||||
g.SmoothingMode = SmoothingMode.HighQuality;
|
|
||||||
g.DrawCapsule(trackBrush, trackVerticalRegion);
|
|
||||||
g.DrawCapsule(thumbBrush, thumbVerticalRegion);
|
|
||||||
g.SmoothingMode = SmoothingMode.None;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void WriteTips(StringBuilder sb)
|
private void WriteTips(StringBuilder sb)
|
||||||
{
|
{
|
||||||
sb.AppendLine(Resources.RectangleRegion_WriteTips__F1__Hide_tips);
|
sb.AppendLine(Resources.RectangleRegion_WriteTips__F1__Hide_tips);
|
||||||
|
|
119
ShareX.ScreenCaptureLib/RegionHelpers/ScrollbarManager.cs
Normal file
119
ShareX.ScreenCaptureLib/RegionHelpers/ScrollbarManager.cs
Normal file
|
@ -0,0 +1,119 @@
|
||||||
|
#region License Information (GPL v3)
|
||||||
|
|
||||||
|
/*
|
||||||
|
ShareX - A program that allows you to take screenshots and share any file type
|
||||||
|
Copyright (c) 2007-2017 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;
|
||||||
|
|
||||||
|
namespace ShareX.ScreenCaptureLib
|
||||||
|
{
|
||||||
|
internal class ScrollbarManager
|
||||||
|
{
|
||||||
|
public bool IsVisible => form.ShapeManager.IsPanning && (IsHorizontalScrollbarVisible || IsVerticalScrollbarVisible);
|
||||||
|
public bool IsHorizontalScrollbarVisible { get; private set; }
|
||||||
|
public bool IsVerticalScrollbarVisible { get; private set; }
|
||||||
|
|
||||||
|
public int Thickness { get; set; } = 10;
|
||||||
|
public int Margin { get; set; } = 15;
|
||||||
|
public int Padding { get; set; } = 2;
|
||||||
|
|
||||||
|
private RegionCaptureForm form;
|
||||||
|
private Rectangle horizontalTrackRectangle, horizontalThumbRectangle, verticalTrackRectangle, verticalThumbRectangle;
|
||||||
|
|
||||||
|
public ScrollbarManager(RegionCaptureForm regionCaptureForm)
|
||||||
|
{
|
||||||
|
form = regionCaptureForm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update()
|
||||||
|
{
|
||||||
|
Rectangle imageRectangleVisible = form.CanvasRectangle;
|
||||||
|
imageRectangleVisible.Intersect(form.ClientArea);
|
||||||
|
|
||||||
|
IsHorizontalScrollbarVisible = form.CanvasRectangle.Left < form.ClientArea.Left || form.CanvasRectangle.Right > form.ClientArea.Right;
|
||||||
|
|
||||||
|
if (IsHorizontalScrollbarVisible)
|
||||||
|
{
|
||||||
|
int horizontalTrackLength = form.ClientArea.Width - Margin * 2 - Thickness - Padding * 2;
|
||||||
|
int horizontalThumbLength = Math.Max(Thickness, (int)Math.Round((float)imageRectangleVisible.Width / form.CanvasRectangle.Width * horizontalTrackLength));
|
||||||
|
|
||||||
|
horizontalTrackRectangle = new Rectangle(new Point(Margin - Padding, form.ClientArea.Bottom - (Thickness + Margin) - Padding),
|
||||||
|
new Size(horizontalTrackLength + Padding * 2, Thickness + Padding * 2));
|
||||||
|
|
||||||
|
double limitHorizontal = (horizontalTrackLength - horizontalThumbLength) / 2.0f;
|
||||||
|
double thumbHorizontalPositionX = Math.Round(horizontalTrackRectangle.X + horizontalTrackRectangle.Width / 2.0f - (horizontalThumbLength / 2.0f) -
|
||||||
|
Math.Min(limitHorizontal, Math.Max(-limitHorizontal, form.CanvasCenterOffset.X / form.CanvasRectangle.Width * horizontalTrackLength)));
|
||||||
|
|
||||||
|
horizontalThumbRectangle = new Rectangle(new Point((int)thumbHorizontalPositionX, form.ClientArea.Bottom - (Thickness + Margin)),
|
||||||
|
new Size(horizontalThumbLength, Thickness));
|
||||||
|
}
|
||||||
|
|
||||||
|
IsVerticalScrollbarVisible = form.CanvasRectangle.Top < form.ClientArea.Top || form.CanvasRectangle.Bottom > form.ClientArea.Bottom;
|
||||||
|
|
||||||
|
if (IsVerticalScrollbarVisible)
|
||||||
|
{
|
||||||
|
int verticalTrackLength = form.ClientArea.Height - Margin * 2 - Thickness - Padding * 2;
|
||||||
|
int verticalThumbLength = Math.Max(Thickness, (int)Math.Round((float)imageRectangleVisible.Height / form.CanvasRectangle.Height * verticalTrackLength));
|
||||||
|
|
||||||
|
verticalTrackRectangle = new Rectangle(new Point(form.ClientArea.Right - (Thickness + Margin) - Padding, Margin - Padding),
|
||||||
|
new Size(Thickness + Padding * 2, verticalTrackLength + Padding * 2));
|
||||||
|
|
||||||
|
double limitVertical = (verticalTrackLength - verticalThumbLength) / 2.0f;
|
||||||
|
double thumbVerticalPositionY = Math.Round(verticalTrackRectangle.Y + verticalTrackRectangle.Height / 2.0f - (verticalThumbLength / 2.0f) -
|
||||||
|
Math.Min(limitVertical, Math.Max(-limitVertical, form.CanvasCenterOffset.Y / form.CanvasRectangle.Height * verticalTrackLength)));
|
||||||
|
|
||||||
|
verticalThumbRectangle = new Rectangle(new Point(form.ClientArea.Right - (Thickness + Margin), (int)thumbVerticalPositionY),
|
||||||
|
new Size(Thickness, verticalThumbLength));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Draw(Graphics g)
|
||||||
|
{
|
||||||
|
if (IsVisible)
|
||||||
|
{
|
||||||
|
using (Brush trackBrush = new SolidBrush(Color.FromArgb(255, 60, 60, 60)))
|
||||||
|
using (Brush thumbBrush = new SolidBrush(Color.FromArgb(255, 130, 130, 130)))
|
||||||
|
{
|
||||||
|
if (IsHorizontalScrollbarVisible)
|
||||||
|
{
|
||||||
|
g.SmoothingMode = SmoothingMode.HighQuality;
|
||||||
|
g.DrawCapsule(trackBrush, horizontalTrackRectangle);
|
||||||
|
g.DrawCapsule(thumbBrush, horizontalThumbRectangle);
|
||||||
|
g.SmoothingMode = SmoothingMode.None;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsVerticalScrollbarVisible)
|
||||||
|
{
|
||||||
|
g.SmoothingMode = SmoothingMode.HighQuality;
|
||||||
|
g.DrawCapsule(trackBrush, verticalTrackRectangle);
|
||||||
|
g.DrawCapsule(thumbBrush, verticalThumbRectangle);
|
||||||
|
g.SmoothingMode = SmoothingMode.None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -93,6 +93,7 @@
|
||||||
<Compile Include="Forms\ImageSizeForm.Designer.cs">
|
<Compile Include="Forms\ImageSizeForm.Designer.cs">
|
||||||
<DependentUpon>ImageSizeForm.cs</DependentUpon>
|
<DependentUpon>ImageSizeForm.cs</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="RegionHelpers\ScrollbarManager.cs" />
|
||||||
<Compile Include="Shapes\AnnotationOptions.cs" />
|
<Compile Include="Shapes\AnnotationOptions.cs" />
|
||||||
<Compile Include="Enums.cs" />
|
<Compile Include="Enums.cs" />
|
||||||
<Compile Include="Forms\RegionCaptureSimpleAnnotateForm.cs">
|
<Compile Include="Forms\RegionCaptureSimpleAnnotateForm.cs">
|
||||||
|
|
Loading…
Reference in a new issue