Added UpdateOpacity method

This commit is contained in:
Jaex 2018-04-03 23:27:33 +03:00
parent 37a6127e57
commit d7e369a210

View file

@ -48,8 +48,8 @@ internal class ImageEditorScrollbar : DrawableObject
private bool shouldDraw = true;
private bool shouldDrawBefore = true;
private Stopwatch changeTime;
private int opacityLast = 255;
private int opacityCurrent = 255;
private int opacityLast;
private int opacityCurrent;
private RegionCaptureForm form;
public ImageEditorScrollbar(Orientation orientation, RegionCaptureForm form)
@ -59,10 +59,10 @@ public ImageEditorScrollbar(Orientation orientation, RegionCaptureForm form)
changeTime = Stopwatch.StartNew();
if (form.ClientArea.Contains(form.CanvasRectangle))
if (!form.ClientArea.Contains(form.CanvasRectangle))
{
opacityLast = 0;
opacityCurrent = 0;
opacityLast = 255;
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);
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;
UpdateOpacity();
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);
if (shouldDraw != shouldDrawBefore)
{
changeTime = Stopwatch.StartNew();
opacityLast = opacityCurrent;
}
shouldDrawBefore = shouldDraw;
UpdateOpacity();
if (shouldDraw)
{
opacityCurrent = opacityLast + OpacityGain(changeTime);
}
else
{
opacityCurrent = opacityLast - OpacityLoss(changeTime);
}
opacityCurrent = opacityCurrent.Between(0, 255);
Visible = opacityCurrent > 0;
if (Visible)
{
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)
{
return (int)Math.Min(255.0f, 255.0f * changeTime.ElapsedMilliseconds / Math.Max(0, (float)FadeInTime));