2015-04-08 15:20:10 -07:00
|
|
|
|
using MatterHackers.Agg;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
using MatterHackers.Agg.UI;
|
|
|
|
|
|
using MatterHackers.VectorMath;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Diagnostics;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
|
|
|
|
|
namespace MatterHackers.MatterControl
|
|
|
|
|
|
{
|
2015-04-08 15:20:10 -07:00
|
|
|
|
public class SlidePanel : GuiWidget
|
|
|
|
|
|
{
|
|
|
|
|
|
public List<GuiWidget> panels = new List<GuiWidget>();
|
|
|
|
|
|
|
|
|
|
|
|
private int currentPanelIndex = -1;
|
|
|
|
|
|
private int desiredPanelIndex = 0;
|
|
|
|
|
|
private Stopwatch timeHasBeenChanging = new Stopwatch();
|
|
|
|
|
|
|
|
|
|
|
|
public SlidePanel(int count)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.AnchorAll();
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
GuiWidget newPanel = new FlowLayoutWidget(FlowDirection.TopToBottom);
|
|
|
|
|
|
panels.Add(newPanel);
|
|
|
|
|
|
AddChild(newPanel);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public int PanelIndex
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return currentPanelIndex;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
if (currentPanelIndex != value)
|
|
|
|
|
|
{
|
|
|
|
|
|
desiredPanelIndex = value;
|
|
|
|
|
|
timeHasBeenChanging.Restart();
|
|
|
|
|
|
SetSlidePosition();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-04-18 11:31:31 -07:00
|
|
|
|
public void SetPanelIndexImmediate(int index)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
|
|
|
|
|
desiredPanelIndex = index;
|
|
|
|
|
|
SetSlidePosition();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public GuiWidget GetPanel(int index)
|
|
|
|
|
|
{
|
|
|
|
|
|
return panels[index];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void OnBoundsChanged(EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (int i = 0; i < panels.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
panels[i].LocalBounds = LocalBounds;
|
|
|
|
|
|
}
|
|
|
|
|
|
SetSlidePosition();
|
|
|
|
|
|
base.OnBoundsChanged(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void OnDraw(Graphics2D graphics2D)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.OnDraw(graphics2D);
|
|
|
|
|
|
if (currentPanelIndex != desiredPanelIndex)
|
|
|
|
|
|
{
|
|
|
|
|
|
SetSlidePosition();
|
|
|
|
|
|
Invalidate();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void SetSlidePosition()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (currentPanelIndex != desiredPanelIndex)
|
|
|
|
|
|
{
|
|
|
|
|
|
// set this based on the time that has elapsed and it should give us a nice result (we can even ease in ease out)
|
|
|
|
|
|
double maxOffsetPerDraw = timeHasBeenChanging.ElapsedMilliseconds;
|
|
|
|
|
|
|
|
|
|
|
|
double desiredOffset = desiredPanelIndex * -Width;
|
2017-10-31 12:51:16 -07:00
|
|
|
|
double currentOffset = panels[0].OriginRelativeParent.X;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
double delta = desiredOffset - currentOffset;
|
|
|
|
|
|
if (delta < 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
delta = Math.Max(-maxOffsetPerDraw, delta);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
delta = Math.Min(maxOffsetPerDraw, delta);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
double offsetThisDraw = currentOffset + delta;
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < panels.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
panels[i].OriginRelativeParent = new Vector2(offsetThisDraw, 0);
|
|
|
|
|
|
offsetThisDraw += Width;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (currentOffset + delta == desiredOffset)
|
|
|
|
|
|
{
|
|
|
|
|
|
currentPanelIndex = desiredPanelIndex;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
double desiredOffset = desiredPanelIndex * -Width;
|
|
|
|
|
|
for (int i = 0; i < panels.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
panels[i].OriginRelativeParent = new Vector2(desiredOffset, 0);
|
|
|
|
|
|
desiredOffset += Width;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|