mirror of
https://github.com/ShareX/ShareX.git
synced 2024-07-04 22:21:23 +12:00
Added UpdateOpacity method
This commit is contained in:
parent
37a6127e57
commit
d7e369a210
|
@ -48,8 +48,8 @@ internal class ImageEditorScrollbar : DrawableObject
|
||||||
private bool shouldDraw = true;
|
private bool shouldDraw = true;
|
||||||
private bool shouldDrawBefore = true;
|
private bool shouldDrawBefore = true;
|
||||||
private Stopwatch changeTime;
|
private Stopwatch changeTime;
|
||||||
private int opacityLast = 255;
|
private int opacityLast;
|
||||||
private int opacityCurrent = 255;
|
private int opacityCurrent;
|
||||||
private RegionCaptureForm form;
|
private RegionCaptureForm form;
|
||||||
|
|
||||||
public ImageEditorScrollbar(Orientation orientation, RegionCaptureForm form)
|
public ImageEditorScrollbar(Orientation orientation, RegionCaptureForm form)
|
||||||
|
@ -59,10 +59,10 @@ public ImageEditorScrollbar(Orientation orientation, RegionCaptureForm form)
|
||||||
|
|
||||||
changeTime = Stopwatch.StartNew();
|
changeTime = Stopwatch.StartNew();
|
||||||
|
|
||||||
if (form.ClientArea.Contains(form.CanvasRectangle))
|
if (!form.ClientArea.Contains(form.CanvasRectangle))
|
||||||
{
|
{
|
||||||
opacityLast = 0;
|
opacityLast = 255;
|
||||||
opacityCurrent = 0;
|
opacityCurrent = 255;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,24 +75,7 @@ public void Update()
|
||||||
{
|
{
|
||||||
shouldDraw = form.ShapeManager.IsPanning && (form.CanvasRectangle.Left < form.ClientArea.Left || form.CanvasRectangle.Right > form.ClientArea.Right);
|
shouldDraw = form.ShapeManager.IsPanning && (form.CanvasRectangle.Left < form.ClientArea.Left || form.CanvasRectangle.Right > form.ClientArea.Right);
|
||||||
|
|
||||||
if (shouldDraw != shouldDrawBefore)
|
UpdateOpacity();
|
||||||
{
|
|
||||||
changeTime = Stopwatch.StartNew();
|
|
||||||
opacityLast = opacityCurrent;
|
|
||||||
}
|
|
||||||
shouldDrawBefore = shouldDraw;
|
|
||||||
|
|
||||||
if (shouldDraw)
|
|
||||||
{
|
|
||||||
opacityCurrent = opacityLast + OpacityGain(changeTime);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
opacityCurrent = opacityLast - OpacityLoss(changeTime);
|
|
||||||
}
|
|
||||||
opacityCurrent = opacityCurrent.Between(0, 255);
|
|
||||||
|
|
||||||
Visible = opacityCurrent > 0;
|
|
||||||
|
|
||||||
if (Visible)
|
if (Visible)
|
||||||
{
|
{
|
||||||
|
@ -114,24 +97,8 @@ public void Update()
|
||||||
{
|
{
|
||||||
shouldDraw = form.ShapeManager.IsPanning && (form.CanvasRectangle.Top < form.ClientArea.Top || form.CanvasRectangle.Bottom > form.ClientArea.Bottom);
|
shouldDraw = form.ShapeManager.IsPanning && (form.CanvasRectangle.Top < form.ClientArea.Top || form.CanvasRectangle.Bottom > form.ClientArea.Bottom);
|
||||||
|
|
||||||
if (shouldDraw != shouldDrawBefore)
|
UpdateOpacity();
|
||||||
{
|
|
||||||
changeTime = Stopwatch.StartNew();
|
|
||||||
opacityLast = opacityCurrent;
|
|
||||||
}
|
|
||||||
shouldDrawBefore = shouldDraw;
|
|
||||||
|
|
||||||
if (shouldDraw)
|
|
||||||
{
|
|
||||||
opacityCurrent = opacityLast + OpacityGain(changeTime);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
opacityCurrent = opacityLast - OpacityLoss(changeTime);
|
|
||||||
}
|
|
||||||
opacityCurrent = opacityCurrent.Between(0, 255);
|
|
||||||
|
|
||||||
Visible = opacityCurrent > 0;
|
|
||||||
if (Visible)
|
if (Visible)
|
||||||
{
|
{
|
||||||
int verticalTrackLength = form.ClientArea.Height - Margin * 2 - Thickness - Padding * 2;
|
int verticalTrackLength = form.ClientArea.Height - Margin * 2 - Thickness - Padding * 2;
|
||||||
|
@ -164,6 +131,30 @@ public override void OnDraw(Graphics g)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void UpdateOpacity()
|
||||||
|
{
|
||||||
|
if (shouldDraw != shouldDrawBefore)
|
||||||
|
{
|
||||||
|
changeTime = Stopwatch.StartNew();
|
||||||
|
opacityLast = opacityCurrent;
|
||||||
|
}
|
||||||
|
|
||||||
|
shouldDrawBefore = shouldDraw;
|
||||||
|
|
||||||
|
if (shouldDraw)
|
||||||
|
{
|
||||||
|
opacityCurrent = opacityLast + OpacityGain(changeTime);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
opacityCurrent = opacityLast - OpacityLoss(changeTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
opacityCurrent = opacityCurrent.Between(0, 255);
|
||||||
|
|
||||||
|
Visible = opacityCurrent > 0;
|
||||||
|
}
|
||||||
|
|
||||||
private int OpacityGain(Stopwatch changeTime)
|
private int OpacityGain(Stopwatch changeTime)
|
||||||
{
|
{
|
||||||
return (int)Math.Min(255.0f, 255.0f * changeTime.ElapsedMilliseconds / Math.Max(0, (float)FadeInTime));
|
return (int)Math.Min(255.0f, 255.0f * changeTime.ElapsedMilliseconds / Math.Max(0, (float)FadeInTime));
|
||||||
|
|
Loading…
Reference in a new issue