diff --git a/MatterControlLib/ApplicationView/PrinterModels.cs b/MatterControlLib/ApplicationView/PrinterModels.cs index d3413d892..2d37d9fcf 100644 --- a/MatterControlLib/ApplicationView/PrinterModels.cs +++ b/MatterControlLib/ApplicationView/PrinterModels.cs @@ -778,12 +778,16 @@ namespace MatterHackers.MatterControl { if (viewMode != value) { + // Capture before/after state + var eventArgs = new ViewModeChangedEventArgs() + { + ViewMode = value, + PreviousMode = viewMode + }; + viewMode = value; - ViewModeChanged?.Invoke(this, new ViewModeChangedEventArgs() - { - ViewMode = this.ViewMode - }); + this.ViewModeChanged?.Invoke(this, eventArgs); } } } diff --git a/MatterControlLib/PartPreviewWindow/PrinterTabPage.cs b/MatterControlLib/PartPreviewWindow/PrinterTabPage.cs index 1c03c6890..239c6b196 100644 --- a/MatterControlLib/PartPreviewWindow/PrinterTabPage.cs +++ b/MatterControlLib/PartPreviewWindow/PrinterTabPage.cs @@ -537,17 +537,21 @@ namespace MatterHackers.MatterControl.PartPreviewWindow { bottomRow.Name = printer.Bed.EditContext.GCodeFilePath; } + await ApplicationController.Instance.Tasks.Execute("Saving".Localize(), printer.Bed.SaveChanges); - // start up a new slice on a backgroud thread + + // start up a new slice on a background thread await ApplicationController.Instance.SliceItemLoadOutput( printer, printer.Bed.Scene, printer.Bed.EditContext.GCodeFilePath); + // Switch to the 3D layer view if on Model view if (printer.ViewState.ViewMode == PartViewMode.Model) { printer.ViewState.ViewMode = PartViewMode.Layers3D; } + // when it is done queue it to the change to gcode stream var message2 = "Would you like to switch to the new G-Code? Before you switch, check that your are seeing the changes you expect.".Localize(); var caption2 = "Switch to new G-Code?".Localize(); diff --git a/MatterControlLib/PartPreviewWindow/Toolbar.cs b/MatterControlLib/PartPreviewWindow/Toolbar.cs index b0fec7c55..4321bc126 100644 --- a/MatterControlLib/PartPreviewWindow/Toolbar.cs +++ b/MatterControlLib/PartPreviewWindow/Toolbar.cs @@ -70,6 +70,11 @@ namespace MatterHackers.MatterControl.PartPreviewWindow { ActionArea.AddChild(childToAdd, indexInChildrenList); } + + public void AddChildDirect(GuiWidget guiWidget) + { + base.AddChild(guiWidget); + } } public class ToolbarSeparator : VerticalLine diff --git a/MatterControlLib/PartPreviewWindow/View3D/PrinterBar/PrinterActionsBar.cs b/MatterControlLib/PartPreviewWindow/View3D/PrinterBar/PrinterActionsBar.cs index aa4aca151..8d95fa819 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/PrinterBar/PrinterActionsBar.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/PrinterBar/PrinterActionsBar.cs @@ -60,6 +60,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow internal RadioIconButton layers3DButton; internal RadioIconButton modelViewButton; + private Dictionary viewModes = new Dictionary(); + public PrinterActionsBar(PrinterConfig printer, PrinterTabPage printerTabPage, ThemeConfig theme) : base(theme) { @@ -120,6 +122,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow buttonGroupB.Add(modelViewButton); AddChild(modelViewButton); + viewModes.Add(PartViewMode.Model, modelViewButton); + iconPath = Path.Combine("ViewTransformControls", "gcode_3d.png"); layers3DButton = new RadioIconButton(AggContext.StaticData.LoadIcon(iconPath, 16, 16, theme.InvertIcons), theme) { @@ -132,6 +136,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow layers3DButton.Click += SwitchModes_Click; buttonGroupB.Add(layers3DButton); + viewModes.Add(PartViewMode.Layers3D, layers3DButton); + if (!UserSettings.Instance.IsTouchScreen) { this.AddChild(layers3DButton); @@ -150,6 +156,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow buttonGroupB.Add(layers2DButton); this.AddChild(layers2DButton); + viewModes.Add(PartViewMode.Layers2D, layers2DButton); + this.AddChild(new HorizontalSpacer()); bool shareTemp = printer.Settings.GetValue(SettingsKey.extruders_share_temperature); @@ -179,28 +187,19 @@ namespace MatterHackers.MatterControl.PartPreviewWindow printer.ViewState.ViewModeChanged += (s, e) => { - RadioIconButton activeButton = null; - if (e.ViewMode == PartViewMode.Layers2D) + if (viewModes[e.ViewMode] is RadioIconButton activeButton + && viewModes[e.PreviousMode] is RadioIconButton previousButton + && !buttonIsBeingClicked) { - activeButton = layers2DButton; - } - else if (e.ViewMode == PartViewMode.Layers3D) - { - activeButton = layers3DButton; - } - else - { - activeButton = modelViewButton; - } - - if(activeButton != null) - { - activeButton.Checked = true; - - if (!buttonIsBeingClicked) - { - activeButton.FlashBackground(theme.PrimaryAccentColor.WithContrast(theme.TextColor, 6).ToColor()); - } + // Show slide to animation from previous to current, on completion update view to current by setting active.Checked + previousButton.SlideToNewState( + activeButton, + this, + () => + { + activeButton.Checked = true; + }, + theme); } }; diff --git a/MatterControlLib/PartPreviewWindow/View3D/PrinterBar/WidgetAnimationExtensions.cs b/MatterControlLib/PartPreviewWindow/View3D/PrinterBar/WidgetAnimationExtensions.cs index 55e3a6db7..fab304a30 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/PrinterBar/WidgetAnimationExtensions.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/PrinterBar/WidgetAnimationExtensions.cs @@ -27,8 +27,11 @@ of the authors and should not be interpreted as representing official policies, either expressed or implied, of the FreeBSD Project. */ +using System; +using System.Threading.Tasks; using MatterHackers.Agg; using MatterHackers.Agg.UI; +using MatterHackers.MatterControl.CustomWidgets; namespace MatterHackers.MatterControl.PartPreviewWindow { @@ -63,5 +66,59 @@ namespace MatterHackers.MatterControl.PartPreviewWindow }; flashBackground.Start(); } + + public static void SlideToNewState(this RadioIconButton widget, RadioIconButton newActiveButton, OverflowBar parent, Action animationComplete, ThemeConfig theme) + { + double displayTime = 600; + double elapsedMs = 0; + + var box = new GuiWidget() + { + HAnchor = HAnchor.Absolute, + VAnchor = VAnchor.Absolute, + Position = widget.Position + new VectorMath.Vector2(widget.Margin.Width, widget.Margin.Height), + Size = widget.Size, + BackgroundColor = theme.AccentMimimalOverlay, + Border = 1, + BorderColor = theme.PrimaryAccentColor + }; + parent.AddChildDirect(box); + + var startX = box.Position.X; + var startY = box.Position.Y; + var xdistance = (newActiveButton.Position.X + newActiveButton.Margin.Width) - startX; + var direction = xdistance > 0 ? 1 : -1; + var startedMS = UiThread.CurrentTimerMs; + + Animation animation = null; + animation = new Animation() + { + DrawTarget = widget, + FramesPerSecond = 20, + Update = (s1, updateEvent) => + { + elapsedMs = UiThread.CurrentTimerMs - startedMS; + if (elapsedMs < (displayTime + 300)) + { + var ratio = Math.Min(1, elapsedMs / displayTime); + double blend = Easing.Cubic.In(ratio); + box.Position = new VectorMath.Vector2(startX + (xdistance * blend), startY); + + //Console.WriteLine("Ms: {0}, Ratio: {1}, Easing: {2}, Position: {3}", elapsedMs, ratio, blend, box.Position); + box.Invalidate(); + } + else + { + animation.Stop(); + + animationComplete?.Invoke(); + + UiThread.RunOnIdle(box.Close, .3); + } + } + }; + + animation.Start(); + } } } \ No newline at end of file diff --git a/MatterControlLib/PartPreviewWindow/ViewControls3D.cs b/MatterControlLib/PartPreviewWindow/ViewControls3D.cs index 8be3c0558..a194193a3 100644 --- a/MatterControlLib/PartPreviewWindow/ViewControls3D.cs +++ b/MatterControlLib/PartPreviewWindow/ViewControls3D.cs @@ -66,6 +66,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow public class ViewModeChangedEventArgs : EventArgs { public PartViewMode ViewMode { get; set; } + public PartViewMode PreviousMode { get; set; } } public class TransformStateChangedEventArgs : EventArgs @@ -102,10 +103,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow public ViewControls3DButtons ActiveButton { - get - { - return activeTransformState; - } + get => activeTransformState; set { this.activeTransformState = value;