From 5ffd29ab7bada1b6b38e7ea8127b5d5d45baa8f4 Mon Sep 17 00:00:00 2001 From: MatterHackers Date: Sat, 1 Apr 2023 13:59:18 -0700 Subject: [PATCH] Adding mare ui hints --- .../Library/OpenInto/ExportStlToExecutable.cs | 2 +- .../PartPreviewWindow/MainViewWidget.cs | 2 +- .../View3D/Object3DControlsLayer.cs | 17 ++++- .../PartPreviewWindow/View3D/View3DWidget.cs | 22 ++++-- .../PartPreviewWindow/ViewStyleButton.cs | 4 +- .../UIFields/DoubleField.cs | 4 +- .../UIFields/ExpressionField.cs | 5 +- .../UIFields/NumberField.cs | 69 ++++++++++++++++++- 8 files changed, 109 insertions(+), 16 deletions(-) diff --git a/MatterControlLib/Library/OpenInto/ExportStlToExecutable.cs b/MatterControlLib/Library/OpenInto/ExportStlToExecutable.cs index e33b71c4a..e9078929f 100644 --- a/MatterControlLib/Library/OpenInto/ExportStlToExecutable.cs +++ b/MatterControlLib/Library/OpenInto/ExportStlToExecutable.cs @@ -127,7 +127,7 @@ namespace MatterControlLib.Library.OpenInto } ApplicationController.Instance.Tasks.Execute( - "Twist".Localize(), + "Open".Localize(), null, async (reporter, cancellationToken) => { diff --git a/MatterControlLib/PartPreviewWindow/MainViewWidget.cs b/MatterControlLib/PartPreviewWindow/MainViewWidget.cs index a1be78da0..ed98c400d 100644 --- a/MatterControlLib/PartPreviewWindow/MainViewWidget.cs +++ b/MatterControlLib/PartPreviewWindow/MainViewWidget.cs @@ -397,7 +397,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow statusMessage = tasksContainer.AddChild(new TextWidget("") { - Margin = new BorderDouble(5, 0, 0, 3), + Margin = new BorderDouble(5, 0, 5, 3), TextColor = theme.TextColor, VAnchor = VAnchor.Center, PointSize = theme.FontSize9, diff --git a/MatterControlLib/PartPreviewWindow/View3D/Object3DControlsLayer.cs b/MatterControlLib/PartPreviewWindow/View3D/Object3DControlsLayer.cs index c5028a635..2dbb7184b 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/Object3DControlsLayer.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/Object3DControlsLayer.cs @@ -471,15 +471,26 @@ namespace MatterHackers.MatterControl.PartPreviewWindow && hitObject3DControl is Object3DControl object3DControl2 && object3DControl2.RootSelection != null) { - ApplicationController.Instance.UiHint = "Click to edit values".Localize(); - } - else if (ApplicationController.Instance.UiHint == "Click to edit values".Localize()) + if (!string.IsNullOrEmpty(object3DControl2.UiHint)) + { + lastControlMessage = "Click and drag".Localize() + " : " + object3DControl2.UiHint + " : " + "Click once to edit values".Localize(); ; + } + else + { + lastControlMessage = "Click to edit values".Localize(); + } + + ApplicationController.Instance.UiHint = lastControlMessage; + } + else if (ApplicationController.Instance.UiHint == lastControlMessage) { ApplicationController.Instance.UiHint = ""; } } } + string lastControlMessage = ""; + public override void OnMouseUp(MouseEventArgs mouseEvent) { Invalidate(); diff --git a/MatterControlLib/PartPreviewWindow/View3D/View3DWidget.cs b/MatterControlLib/PartPreviewWindow/View3D/View3DWidget.cs index 63257f71b..d504dd997 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/View3DWidget.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/View3DWidget.cs @@ -30,6 +30,7 @@ either expressed or implied, of the FreeBSD Project. using AngleSharp.Dom; using AngleSharp.Html.Parser; +using g3; using MatterHackers.Agg; using MatterHackers.Agg.Platform; using MatterHackers.Agg.UI; @@ -506,8 +507,10 @@ namespace MatterHackers.MatterControl.PartPreviewWindow Checked = turntableEnabled, //DoubleBuffer = true, }; + turnTableButton.MouseEnterBounds += (s, e) => ApplicationController.Instance.UiHint = "Switch between turn table and trackball modes".Localize(); + turnTableButton.MouseLeaveBounds += (s, e) => ApplicationController.Instance.UiHint = ""; - AddRoundButton(turnTableButton, RotatedMargin(turnTableButton, -MathHelper.Tau * .4)); // 2 button position + AddRoundButton(turnTableButton, RotatedMargin(turnTableButton, -MathHelper.Tau * .4)); // 2 button position turnTableButton.CheckedStateChanged += (s, e) => { UserSettings.Instance.set(UserSettingsKey.TurntableMode, turnTableButton.Checked.ToString()); @@ -531,7 +534,9 @@ namespace MatterHackers.MatterControl.PartPreviewWindow SiblingRadioButtonList = new List(), Checked = TrackballTumbleWidget.PerspectiveMode, }; - AddRoundButton(projectionButton, RotatedMargin(projectionButton, -MathHelper.Tau * .3)); + projectionButton.MouseEnterBounds += (s, e) => ApplicationController.Instance.UiHint = "Turn on and off perspective rendering".Localize(); + projectionButton.MouseLeaveBounds += (s, e) => ApplicationController.Instance.UiHint = ""; + AddRoundButton(projectionButton, RotatedMargin(projectionButton, -MathHelper.Tau * .3)); projectionButton.CheckedStateChanged += (s, e) => { UserSettings.Instance.set(UserSettingsKey.PerspectiveMode, projectionButton.Checked.ToString()); @@ -559,6 +564,9 @@ namespace MatterHackers.MatterControl.PartPreviewWindow ToggleButton = true, SiblingRadioButtonList = new List(), }; + bedButton.MouseEnterBounds += (s, e) => ApplicationController.Instance.UiHint = "Hide and show the bed".Localize(); + bedButton.MouseLeaveBounds += (s, e) => ApplicationController.Instance.UiHint = ""; + AddRoundButton(bedButton, new Vector2((cubeCenterFromRightTop.X + 18 * scale - bedButton.Width / 2) / scale, startHeight)); var printAreaButton = new ThemedRadioIconButton(StaticData.Instance.LoadIcon("print_area.png", 16, 16).SetToColor(theme.TextColor), theme) { @@ -615,7 +623,10 @@ namespace MatterHackers.MatterControl.PartPreviewWindow Mate = new MateOptions(MateEdge.Right, MateEdge.Top) } }; - modelViewStyleButton.AnchorMate.Mate.VerticalEdge = MateEdge.Bottom; + modelViewStyleButton.MouseEnterBounds += (s, e) => ApplicationController.Instance.UiHint = "Change the current rendering mode".Localize(); + modelViewStyleButton.MouseLeaveBounds += (s, e) => ApplicationController.Instance.UiHint = ""; + + modelViewStyleButton.AnchorMate.Mate.VerticalEdge = MateEdge.Bottom; modelViewStyleButton.AnchorMate.Mate.HorizontalEdge = MateEdge.Right; var marginCenter = cubeCenterFromRightTop.X / scale; AddRoundButton(modelViewStyleButton, new Vector2(marginCenter, startHeight + 1 * ySpacing), true); @@ -649,7 +660,10 @@ namespace MatterHackers.MatterControl.PartPreviewWindow Mate = new MateOptions(MateEdge.Right, MateEdge.Top) } }; - gridSnapButton.AnchorMate.Mate.VerticalEdge = MateEdge.Bottom; + gridSnapButton.MouseEnterBounds += (s, e) => ApplicationController.Instance.UiHint = "Adjust the grid that objects will snap to when moved".Localize(); + gridSnapButton.MouseLeaveBounds += (s, e) => ApplicationController.Instance.UiHint = ""; + + gridSnapButton.AnchorMate.Mate.VerticalEdge = MateEdge.Bottom; gridSnapButton.AnchorMate.Mate.HorizontalEdge = MateEdge.Right; AddRoundButton(gridSnapButton, new Vector2(marginCenter, startHeight + 2 * ySpacing), true); gridSnapButton.BackgroundColor = hudBackgroundColor; diff --git a/MatterControlLib/PartPreviewWindow/ViewStyleButton.cs b/MatterControlLib/PartPreviewWindow/ViewStyleButton.cs index 694b18e12..d8abddc78 100644 --- a/MatterControlLib/PartPreviewWindow/ViewStyleButton.cs +++ b/MatterControlLib/PartPreviewWindow/ViewStyleButton.cs @@ -71,8 +71,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow { Selectable = false }); - - ToolTipText = viewData[renderType].toolTip; + + ToolTipText = viewData[renderType].toolTip; UserSettings.Instance.SettingChanged += UserSettings_SettingChanged; } diff --git a/MatterControlLib/SlicerConfiguration/UIFields/DoubleField.cs b/MatterControlLib/SlicerConfiguration/UIFields/DoubleField.cs index 04d83b063..5ea8f517e 100644 --- a/MatterControlLib/SlicerConfiguration/UIFields/DoubleField.cs +++ b/MatterControlLib/SlicerConfiguration/UIFields/DoubleField.cs @@ -38,9 +38,9 @@ namespace MatterHackers.MatterControl.SlicerConfiguration public DoubleField(ThemeConfig theme) : base (theme) { - } + } - public double DoubleValue + public double DoubleValue { get { return _doubleValue; } set diff --git a/MatterControlLib/SlicerConfiguration/UIFields/ExpressionField.cs b/MatterControlLib/SlicerConfiguration/UIFields/ExpressionField.cs index 4080b329a..9a5691c4f 100644 --- a/MatterControlLib/SlicerConfiguration/UIFields/ExpressionField.cs +++ b/MatterControlLib/SlicerConfiguration/UIFields/ExpressionField.cs @@ -27,6 +27,7 @@ of the authors and should not be interpreted as representing official policies, either expressed or implied, of the FreeBSD Project. */ +using Lucene.Net.Tartarus.Snowball; using MatterHackers.Agg.UI; namespace MatterHackers.MatterControl.SlicerConfiguration @@ -80,7 +81,9 @@ namespace MatterHackers.MatterControl.SlicerConfiguration textEditWidget.ActualTextEditWidget.TextChanged += ActualTextEditWidget_TextChanged; - this.Content = aligner; + NumberField.SetupUpAndDownArrows(textEditWidget.ActualTextEditWidget); + + this.Content = aligner; } private double startingTextEditWidth = 0; diff --git a/MatterControlLib/SlicerConfiguration/UIFields/NumberField.cs b/MatterControlLib/SlicerConfiguration/UIFields/NumberField.cs index 58edc1e57..65d880fc7 100644 --- a/MatterControlLib/SlicerConfiguration/UIFields/NumberField.cs +++ b/MatterControlLib/SlicerConfiguration/UIFields/NumberField.cs @@ -28,6 +28,8 @@ either expressed or implied, of the FreeBSD Project. */ using MatterHackers.Agg.UI; +using MatterHackers.Localizations; +using MatterHackers.MeshVisualizer; namespace MatterHackers.MatterControl.SlicerConfiguration { @@ -45,7 +47,69 @@ namespace MatterHackers.MatterControl.SlicerConfiguration this.theme = theme; } - public override void Initialize(int tabIndex) + public static void SetupUpAndDownArrows(GuiWidget guiWidget) + { + guiWidget.KeyDown += InternalTextEditWidget_KeyDown; + + guiWidget.MouseEnterBounds += (s, e) => + { + var textEditWidget = s as TextEditWidget; + var internalTextEditWidget = textEditWidget.InternalTextEditWidget; + + if (internalTextEditWidget != null + && double.TryParse(internalTextEditWidget.Text, out double value)) + { + ApplicationController.Instance.UiHint = "Up Arrow = +1, Down Arrow = -1, (Shift * 10, Control / 10)".Localize(); + } + }; + guiWidget.MouseLeaveBounds += (s, e) => + { + ApplicationController.Instance.UiHint = ""; + }; + } + + private static void InternalTextEditWidget_KeyDown(object sender, KeyEventArgs e) + { + var textEditWidget = sender as TextEditWidget; + var internalTextEditWidget = textEditWidget.InternalTextEditWidget; + + if (internalTextEditWidget != null) + { + var amount = 1.0; + if (e.Shift) + { + amount = 10; + } + else if (e.Control) + { + amount = .1; + } + + // if the up arrow is pressed and the text is a number + if (e.KeyCode == Keys.Up) + { + if (double.TryParse(internalTextEditWidget.Text, out double value)) + { + value += amount; + internalTextEditWidget.Text = value.ToString(); + e.Handled = true; + internalTextEditWidget.OnEditComplete(e); + } + } + else if (e.KeyCode == Keys.Down) + { + if (double.TryParse(internalTextEditWidget.Text, out double value)) + { + value -= amount; + internalTextEditWidget.Text = value.ToString(); + e.Handled = true; + internalTextEditWidget.OnEditComplete(e); + } + } + } + } + + public override void Initialize(int tabIndex) { numberEdit = new ThemedNumberEdit(0, theme, pixelWidth: ControlWidth, allowDecimals: this.AllowDecimals, allowNegatives: this.AllowNegatives, tabIndex: tabIndex) { @@ -62,8 +126,9 @@ namespace MatterHackers.MatterControl.SlicerConfiguration userInitiated: true); } }; + SetupUpAndDownArrows(numberEdit.ActuallNumberEdit); - this.Content = numberEdit; + this.Content = numberEdit; } } }