From 3091a719ee23a79cfd25037bbbe1eefc824ab650 Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Wed, 11 Apr 2018 17:35:34 -0700 Subject: [PATCH] Made RoundedToggleSwitch play mouse down animation Made UiThread SetInterval return a RunningInterval Added EaseIn EaseOut and EaseInOut to agg_basics --- ActionBar/TemperatureWidgetBed.cs | 5 ++- ActionBar/TemperatureWidgetExtruder.cs | 5 ++- ApplicationView/ApplicationController.cs | 2 +- .../PrintLeveling/LevelWizardBase.cs | 29 +++++++++++++- .../PrintLeveling/LevelingStrings.cs | 21 ---------- .../PrintLeveling/ProbeCalibrationWizard.cs | 3 +- .../WizardPages/FindBedHeight.cs | 6 ++- .../WizardPages/WaitForTempPage.cs | 5 ++- ConfigurationPage/RunningMacroPage.cs | 16 +++++--- ControlElements/AttentionGetter.cs | 16 ++------ CustomWidgets/InlineEditControl.cs | 3 +- PartPreviewWindow/PrinterTabPage.cs | 5 ++- PartPreviewWindow/RoundedToggleSwitch.cs | 40 +++++++++++++++++++ PartPreviewWindow/View3D/MeshViewerWidget.cs | 15 +------ Submodules/agg-sharp | 2 +- 15 files changed, 104 insertions(+), 69 deletions(-) diff --git a/ActionBar/TemperatureWidgetBed.cs b/ActionBar/TemperatureWidgetBed.cs index 5beaa389f..32d240d0a 100644 --- a/ActionBar/TemperatureWidgetBed.cs +++ b/ActionBar/TemperatureWidgetBed.cs @@ -134,10 +134,11 @@ namespace MatterHackers.MatterControl.ActionBar Margin = new BorderDouble(0, 5, 0, 0), }; - UiThread.SetInterval(() => + var runningInterval = UiThread.SetInterval(() => { graph.AddData(this.ActualTemperature); - }, 1, () => !HasBeenClosed); + }, 1); + this.Closed += (s, e) => runningInterval.Continue = false; var valueField = temperatureRow.Descendants().FirstOrDefault(); var settingsRow = temperatureRow.DescendantsAndSelf().FirstOrDefault(); diff --git a/ActionBar/TemperatureWidgetExtruder.cs b/ActionBar/TemperatureWidgetExtruder.cs index fa379a10b..f074c9c19 100644 --- a/ActionBar/TemperatureWidgetExtruder.cs +++ b/ActionBar/TemperatureWidgetExtruder.cs @@ -271,10 +271,11 @@ namespace MatterHackers.MatterControl.ActionBar Width = widget.Width - 20, Height = 35, // this works better if it is a common multiple of the Width }; - UiThread.SetInterval(() => + var runningInterval = UiThread.SetInterval(() => { graph.AddData(this.ActualTemperature); - }, 1, () => !HasBeenClosed); + }, 1); + this.Closed += (s, e) => runningInterval.Continue = false; var valueField = temperatureRow.Descendants().FirstOrDefault(); valueField.Name = "Temperature Input"; diff --git a/ApplicationView/ApplicationController.cs b/ApplicationView/ApplicationController.cs index d4b51b4a9..3c95d881b 100644 --- a/ApplicationView/ApplicationController.cs +++ b/ApplicationView/ApplicationController.cs @@ -2176,7 +2176,7 @@ namespace MatterHackers.MatterControl UiThread.SetInterval(() => { ApplicationController.Instance.ActivePrinter.Connection.OnIdle(); - }, .1, () => true); + }, .1); return ApplicationController.Instance.MainView; } diff --git a/ConfigurationPage/PrintLeveling/LevelWizardBase.cs b/ConfigurationPage/PrintLeveling/LevelWizardBase.cs index 90219e20b..dfe5694b1 100644 --- a/ConfigurationPage/PrintLeveling/LevelWizardBase.cs +++ b/ConfigurationPage/PrintLeveling/LevelWizardBase.cs @@ -99,7 +99,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling } yield return new HomePrinterPage(printer, this, - levelingStrings.HomingPageStepText, + "Homing The Printer".Localize(), levelingStrings.HomingPageInstructions(useZProbe, hasHeatedBed), useZProbe, theme); @@ -181,9 +181,34 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling i++; } + this.nextButton.Enabled = false; this.cancelButton.Visible = false; this.doneButton.Visible = true; - yield return new LastPagelInstructions(printer, this, "Done".Localize(), levelingStrings.DoneInstructions, probePositions, theme); + var done1 = "Print Leveling is now configured and enabled.".Localize(); + string done2 = "If you need to recalibrate the printer in the future, the print leveling controls can be found under: Controls, Calibration"; + string done3 = "Click 'Done' to close this window.".Localize(); + + var doneString = ""; + if (useZProbe) + { + doneString = $"{"Congratulations!".Localize()} {done1}\n" + + "\n" + + $"{done2}\n" + + "\n" + + $"{done3}"; + } + else + { + doneString = $"{"Congratulations!".Localize()} {done1}\n" + + "\n" + + $"\t• {"Remove the paper".Localize()}\n" + + "\n" + + $"{done2}\n" + + "\n" + + $"{done3}"; + } + + yield return new LastPagelInstructions(printer, this, "Done".Localize(), doneString, probePositions, theme); } } diff --git a/ConfigurationPage/PrintLeveling/LevelingStrings.cs b/ConfigurationPage/PrintLeveling/LevelingStrings.cs index dbd9725ea..fd00f19a5 100644 --- a/ConfigurationPage/PrintLeveling/LevelingStrings.cs +++ b/ConfigurationPage/PrintLeveling/LevelingStrings.cs @@ -36,13 +36,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling { public class LevelingStrings { - public string HomingPageStepText = "Homing The Printer".Localize(); public string initialPrinterSetupStepText = "Initial Printer Setup".Localize(); - private string doneLine1 = "Congratulations!"; - private string doneLine1b = "Auto Print Leveling is now configured and enabled.".Localize(); - private string doneLine2 = "Remove the paper".Localize(); - private string doneLine3 = "If you need to recalibrate the printer in the future, the print leveling controls can be found under: Controls, Calibration"; - private string doneLine3b = "Click 'Done' to close this window.".Localize(); private int stepNumber = 1; private string welcomeLine1 = "Welcome to the print leveling wizard. Here is a quick overview on what we are going to do.".Localize(); private string selectMaterial = "Select the material you are printing".Localize(); @@ -58,21 +52,6 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling this.printerSettings = printerSettings; } - public string DoneInstructions - { - get - { - if (printerSettings.Helpers.UseZProbe()) - { - return $"{doneLine1} {doneLine1b}\n\n{doneLine3}\n\n{doneLine3b}"; - } - else - { - return $"{doneLine1} {doneLine1b}\n\n\t• {doneLine2}\n\n{doneLine3}\n\n{doneLine3b}"; - } - } - } - public string HomingPageInstructions(bool useZProbe, bool heatBed) { string line1 = "The printer should now be 'homing'.".Localize(); diff --git a/ConfigurationPage/PrintLeveling/ProbeCalibrationWizard.cs b/ConfigurationPage/PrintLeveling/ProbeCalibrationWizard.cs index 163bac70a..4d0bce4a0 100644 --- a/ConfigurationPage/PrintLeveling/ProbeCalibrationWizard.cs +++ b/ConfigurationPage/PrintLeveling/ProbeCalibrationWizard.cs @@ -93,7 +93,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling // add in the homing printer page yield return new HomePrinterPage(printer, this, - levelingStrings.HomingPageStepText, + "Homing The Printer".Localize(), levelingStrings.HomingPageInstructions(true, false), false, theme); @@ -135,6 +135,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling this.cancelButton.Visible = false; this.doneButton.Visible = true; + this.nextButton.Enabled = false; yield return new CalibrateProbeLastPagelInstructions(printer, this, "Done".Localize(), "Your Probe is now calibrated.".Localize() + "\n\n\t• " + "Remove the paper".Localize() + "\n\n" + "Click 'Done' to close this window.".Localize(), diff --git a/ConfigurationPage/PrintLeveling/WizardPages/FindBedHeight.cs b/ConfigurationPage/PrintLeveling/WizardPages/FindBedHeight.cs index 4cb544dc6..730b3f371 100644 --- a/ConfigurationPage/PrintLeveling/WizardPages/FindBedHeight.cs +++ b/ConfigurationPage/PrintLeveling/WizardPages/FindBedHeight.cs @@ -77,11 +77,13 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling Margin = new BorderDouble(10, 0), }; - UiThread.SetInterval(() => + var runningInterval = UiThread.SetInterval(() => { Vector3 destinationPosition = printer.Connection.CurrentDestination; zPosition.Text = "Z: {0:0.00}".FormatWith(destinationPosition.Z); - }, .3, () => !HasBeenClosed); + }, .3); + + this.Closed += (s, e) => runningInterval.Continue = false; zButtonsAndInfo.AddChild(zPosition); diff --git a/ConfigurationPage/PrintLeveling/WizardPages/WaitForTempPage.cs b/ConfigurationPage/PrintLeveling/WizardPages/WaitForTempPage.cs index 5c83a3e5d..967cee696 100644 --- a/ConfigurationPage/PrintLeveling/WizardPages/WaitForTempPage.cs +++ b/ConfigurationPage/PrintLeveling/WizardPages/WaitForTempPage.cs @@ -161,7 +161,8 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling { bedStartingTemp = printer.Connection.ActualBedTemperature; - UiThread.SetInterval(ShowTempChangeProgress, 1, () => !HasBeenClosed); + var runningInterval = UiThread.SetInterval(ShowTempChangeProgress, 1); + this.Closed += (s, e) => runningInterval.Continue = false; if (bedTargetTemp > 0) { @@ -171,7 +172,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling if (hotEndTargetTemp > 0) { - // start heating the bed and show our progress + // start heating the hot end and show our progress printer.Connection.SetTargetHotendTemperature(0, hotEndTargetTemp); } diff --git a/ConfigurationPage/RunningMacroPage.cs b/ConfigurationPage/RunningMacroPage.cs index 59af26865..718eddfc7 100644 --- a/ConfigurationPage/RunningMacroPage.cs +++ b/ConfigurationPage/RunningMacroPage.cs @@ -44,6 +44,7 @@ namespace MatterHackers.MatterControl.PrinterControls { private long startTimeMs; private ProgressBar progressBar; + private RunningInterval runningInterval; private TextWidget progressBarText; @@ -111,10 +112,7 @@ namespace MatterHackers.MatterControl.PrinterControls { timeToWaitMs = (long)(macroData.countDown * 1000); startTimeMs = UiThread.CurrentTimerMs; - UiThread.SetInterval(CountDownTime, .2, () => - { - return (!HasBeenClosed && progressBar.RatioComplete < 1); - }); + runningInterval = UiThread.SetInterval(CountDownTime, .2); } } @@ -150,6 +148,10 @@ namespace MatterHackers.MatterControl.PrinterControls private void CountDownTime() { + if(runningInterval != null) + { + runningInterval.Continue = !HasBeenClosed && progressBar.RatioComplete < 1; + } progressBar.Visible = true; long timeSinceStartMs = UiThread.CurrentTimerMs - startTimeMs; progressBar.RatioComplete = timeToWaitMs == 0 ? 1 : Math.Max(0, Math.Min(1, ((double)timeSinceStartMs / (double)timeToWaitMs))); @@ -165,8 +167,10 @@ namespace MatterHackers.MatterControl.PrinterControls && stringEvent.Data.Contains("M104")) { startingTemp = printer.Connection.GetActualHotendTemperature(0); - UiThread.SetInterval(() => + RunningInterval runningInterval = null; + runningInterval = UiThread.SetInterval(() => { + runningInterval.Continue = !HasBeenClosed && progressBar.RatioComplete < 1; progressBar.Visible = true; double targetTemp = printer.Connection.GetTargetHotendTemperature(0); double actualTemp = printer.Connection.GetActualHotendTemperature(0); @@ -175,7 +179,7 @@ namespace MatterHackers.MatterControl.PrinterControls double ratioDone = totalDelta != 0 ? (currentDelta / totalDelta) : 1; progressBar.RatioComplete = Math.Min(Math.Max(0, ratioDone), 1); progressBarText.Text = $"Temperature: {actualTemp:0} / {targetTemp:0}"; - }, 1, () => !HasBeenClosed && progressBar.RatioComplete < 1); + }, 1); } } } diff --git a/ControlElements/AttentionGetter.cs b/ControlElements/AttentionGetter.cs index db0e6c403..7b38ab099 100644 --- a/ControlElements/AttentionGetter.cs +++ b/ControlElements/AttentionGetter.cs @@ -96,7 +96,7 @@ namespace MatterHackers.MatterControl time = 1 - (time - 1); } - double lightnessMultiplier = EaseInOutQuad(time); + double lightnessMultiplier = agg_basics.EaseInOutQuad(time); widgetToHighlight.BackgroundColor = startColor.AdjustLightness(1 + lightnessChange * lightnessMultiplier).ToColor(); if (widgetToHighlight.HasBeenClosed || timeSinceStart.Elapsed.TotalSeconds > cycles * pulseTime) @@ -110,17 +110,6 @@ namespace MatterHackers.MatterControl } } - private double EaseInOutQuad(double t) - { - if (t <= 0.5f) - { - return 2.0f * (t * t); - } - - t -= 0.5f; - return 2.0f * t * (1.0f - t) + 0.5; - } - private void ConnectToWidget(object drawingWidget, DrawEventArgs e) { GuiWidget parent = drawingWidget as GuiWidget; @@ -131,7 +120,8 @@ namespace MatterHackers.MatterControl startColor = parent.BackgroundColor; timeSinceStart = Stopwatch.StartNew(); widgetToHighlight.AfterDraw -= ConnectToWidget; - UiThread.SetInterval(ChangeBackgroundColor, animationDelay, () => parent.HasBeenClosed); + var runningInterval = UiThread.SetInterval(ChangeBackgroundColor, animationDelay); + parent.Closed += (s, e2) => runningInterval.Continue = false; } } } \ No newline at end of file diff --git a/CustomWidgets/InlineEditControl.cs b/CustomWidgets/InlineEditControl.cs index c88f6935b..e7a4c4933 100644 --- a/CustomWidgets/InlineEditControl.cs +++ b/CustomWidgets/InlineEditControl.cs @@ -81,7 +81,8 @@ namespace MatterHackers.MatterControl.CustomWidgets VAnchor = VAnchor.Fit; HAnchor = HAnchor.Fit; - UiThread.SetInterval(HideIfApplicable, .1, () => !HasBeenClosed); + var runningInterval = UiThread.SetInterval(HideIfApplicable, .1); + this.Closed += (s, e) => runningInterval.Continue = false; } public Color TextColor { get; set; } = Color.Black; diff --git a/PartPreviewWindow/PrinterTabPage.cs b/PartPreviewWindow/PrinterTabPage.cs index 0248d109b..0e1c432de 100644 --- a/PartPreviewWindow/PrinterTabPage.cs +++ b/PartPreviewWindow/PrinterTabPage.cs @@ -541,7 +541,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow timeContainer.AddChild(timeWidget); - UiThread.SetInterval( + var runningInterval = UiThread.SetInterval( () => { int secondsPrinted = printer.Connection.SecondsPrinted; @@ -569,7 +569,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow bodyRow.Visible = false; break; } - }, 1, () => !bodyRow.HasBeenClosed); + }, 1); + bodyRow.Closed += (s, e) => runningInterval.Continue = false; bodyRow.Visible = false; diff --git a/PartPreviewWindow/RoundedToggleSwitch.cs b/PartPreviewWindow/RoundedToggleSwitch.cs index 0ea5f9ef0..ebeb1d932 100644 --- a/PartPreviewWindow/RoundedToggleSwitch.cs +++ b/PartPreviewWindow/RoundedToggleSwitch.cs @@ -28,6 +28,7 @@ either expressed or implied, of the FreeBSD Project. */ using System; +using System.Linq; using MatterHackers.Agg; using MatterHackers.Agg.Image; using MatterHackers.Agg.UI; @@ -82,16 +83,55 @@ namespace MatterHackers.MatterControl.CustomWidgets this.MinimumSize = new Vector2(minWidth, theme.ButtonHeight); } + double animationRatio = 0; + double finalRadius = 22; + Animation animation; public override void OnMouseDown(MouseEventArgs mouseEvent) { mouseIsDown = true; base.OnMouseDown(mouseEvent); + // animation up + animationRatio = 0; + animation = new Animation(this, (t) => + { + if (animation.Continue) + { + animationRatio += 1.0 / 7.0; + } + if (animationRatio >= 1) + { + animation.Continue = false; + } + }, 1.0 / 30.0); + + this.Parents().First().AfterDraw += RoundedToggleSwitch_AfterDraw; + + Closed += (s, e) => + { + animation.Continue = false; + }; + this.Invalidate(); } + private void RoundedToggleSwitch_AfterDraw(object sender, DrawEventArgs e) + { + var position = new Vector2((this.Checked) ? LocalBounds.Right - toggleRadiusPlusPadding : toggleRadiusPlusPadding, centerY); + position = this.TransformToScreenSpace(position); + Color toggleColor = (this.Checked) ? theme.Colors.PrimaryAccentColor : Color.Gray; + + e.Graphics2D.Circle(position, + finalRadius * agg_basics.EaseOutQuartic(animationRatio), + new Color(toggleColor, 100)); + } + public override void OnMouseUp(MouseEventArgs mouseEvent) { + this.Parents().First().AfterDraw -= RoundedToggleSwitch_AfterDraw; + + animation.Continue = false; + animationRatio = 0; mouseIsDown = false; base.OnMouseUp(mouseEvent); diff --git a/PartPreviewWindow/View3D/MeshViewerWidget.cs b/PartPreviewWindow/View3D/MeshViewerWidget.cs index 2ccb5dedc..2ec5eca7d 100644 --- a/PartPreviewWindow/View3D/MeshViewerWidget.cs +++ b/PartPreviewWindow/View3D/MeshViewerWidget.cs @@ -525,11 +525,11 @@ namespace MatterHackers.MeshVisualizer var accentColor = Color.LightGray; if (secondsSinceSelectionChanged < .25) { - selectionColor = Color.White.Blend(accentColor, EaseInOut(secondsSinceSelectionChanged * 4)); + selectionColor = Color.White.Blend(accentColor, agg_basics.EaseInOutQuad(secondsSinceSelectionChanged * 4)); } else { - selectionColor = accentColor.Blend(Color.White, EaseInOut((secondsSinceSelectionChanged - .25) * 4)); + selectionColor = accentColor.Blend(Color.White, agg_basics.EaseInOutQuad((secondsSinceSelectionChanged - .25) * 4)); } Invalidate(); } @@ -678,17 +678,6 @@ namespace MatterHackers.MeshVisualizer } } - private double EaseInOut(double t) - { - if (t <= 0.5f) - { - return 2.0f * (t * t); - } - - t -= 0.5f; - return 2.0f * t * (1.0f - t) + 0.5; - } - public enum EditorType { Printer, Part } public EditorType EditorMode { get; set; } = EditorType.Part; diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index 7f81c4b5a..af88c2020 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit 7f81c4b5adcac1a8d25727fe0a1157bac059b8cb +Subproject commit af88c2020bde9ba76fc369ec105ac480b1cb2c25