Improving export behavior from print menu

This commit is contained in:
LarsBrubaker 2021-02-25 23:06:42 -08:00
parent a3274b99df
commit 4792aa05b3
8 changed files with 132 additions and 47 deletions

View file

@ -328,6 +328,7 @@ namespace MatterHackers.MatterControl
{
BackgroundColor = this.MinimalShade,
BorderColor = this.BorderColor40,
RenderOutline = true,
VAnchor = VAnchor.Absolute,
HAnchor = HAnchor.Absolute,
Margin = 0,
@ -343,6 +344,7 @@ namespace MatterHackers.MatterControl
{
BackgroundColor = this.MinimalShade,
BorderColor = this.BorderColor40,
RenderOutline = true,
VAnchor = VAnchor.Absolute,
HAnchor = HAnchor.Absolute,
Margin = 0,
@ -523,19 +525,34 @@ namespace MatterHackers.MatterControl
{
PopupMenuButton menuButton = null;
var innerButton = new IconButton(buttonParams.Icon, this)
GuiWidget innerButton;
if (buttonParams.ButtonText == null)
{
Name = buttonParams.ButtonName + " Inner SplitButton",
ToolTipText = buttonParams.DefaultActionTooltip,
};
innerButton = new IconButton(buttonParams.Icon, this)
{
Name = buttonParams.ButtonName + " Inner SplitButton",
Enabled = buttonParams.ButtonEnabled,
ToolTipText = buttonParams.ButtonTooltip,
};
// Remove right Padding for drop style
innerButton.Padding = innerButton.Padding.Clone(right: 0);
}
else
{
innerButton = new TextButton(buttonParams.ButtonText, this)
{
Name = buttonParams.ButtonName,
Enabled = buttonParams.ButtonEnabled,
ToolTipText = buttonParams.ButtonTooltip,
};
}
innerButton.Click += (s, e) =>
{
buttonParams.DefaultAction.Invoke(menuButton);
buttonParams.ButtonAction.Invoke(menuButton);
};
// Remove right Padding for drop style
innerButton.Padding = innerButton.Padding.Clone(right: 0);
if (operationGroup == null)
{
@ -555,7 +572,15 @@ namespace MatterHackers.MatterControl
};
menuButton.Name = buttonParams.ButtonName + " Menu SplitButton";
menuButton.BackgroundColor = this.ToolbarButtonBackground;
if (buttonParams.ButtonText == null)
{
menuButton.BackgroundColor = this.ToolbarButtonBackground;
}
else
{
menuButton.BackgroundColor = this.MinimalShade;
}
menuButton.HoverColor = this.ToolbarButtonHover;
menuButton.MouseDownColor = this.ToolbarButtonDown;
menuButton.DrawArrow = true;
@ -723,14 +748,18 @@ namespace MatterHackers.MatterControl
{
public ImageBuffer Icon { get; set; }
public Action<GuiWidget> DefaultAction { get; set; }
public bool ButtonEnabled { get; set; } = true;
public string DefaultActionTooltip { get; set; }
public string ButtonName { get; set; }
public Action<GuiWidget> ButtonAction { get; set; }
public string ButtonTooltip { get; set; }
public Action MenuAction { get; set; }
public Action<PopupMenu> ExtendPopupMenu { get; set; }
public string ButtonName { get; set; }
public string ButtonText { get; set; }
}
}

View file

@ -53,8 +53,16 @@ namespace MatterHackers.MatterControl
public ExportPrintItemPage(IEnumerable<ILibraryItem> libraryItems, bool centerOnBed, PrinterConfig printer)
{
this.WindowTitle = "Export File".Localize();
this.HeaderText = "Export selection to".Localize() + ":";
this.Name = "Export Item Window";
if (libraryItems.First().Name == printer.Bed.Scene.Name)
{
this.HeaderText = "Export bed to".Localize() + ":";
this.Name = "Export Scene Window";
}
else
{
this.HeaderText = "Export selection to".Localize() + ":";
this.Name = "Export Item Window";
}
var commonMargin = new BorderDouble(4, 2);

View file

@ -146,7 +146,11 @@ namespace MatterHackers.MatterControl.CustomWidgets
bounds -= BackgroundInset;
var stroke = 1 * GuiWidget.DeviceScale;
var expand = stroke / 2;
var rect = new RoundedRect(bounds.Left + expand, bounds.Bottom + expand, bounds.Right - expand, bounds.Top - expand, RoundRadius);
var rect = new RoundedRect(bounds.Left + expand,
bounds.Bottom + expand,
bounds.Right - expand,
bounds.Top - expand,
RoundRadius * GuiWidget.DeviceScale);
var rectOutline = new Stroke(rect, stroke);
graphics2D.Render(rectOutline, theme.EditFieldColors.Focused.BorderColor);
@ -157,7 +161,11 @@ namespace MatterHackers.MatterControl.CustomWidgets
{
var bounds = this.LocalBounds;
bounds -= BackgroundInset;
var rect = new RoundedRect(bounds.Left, bounds.Bottom, bounds.Right, bounds.Top, RoundRadius);
var rect = new RoundedRect(bounds.Left,
bounds.Bottom,
bounds.Right,
bounds.Top,
RoundRadius * GuiWidget.DeviceScale);
if (BackgroundColor.Alpha0To255 > 0)
{
@ -168,7 +176,11 @@ namespace MatterHackers.MatterControl.CustomWidgets
{
var stroke = 1 * GuiWidget.DeviceScale;
var expand = stroke / 2;
rect = new RoundedRect(bounds.Left + expand, bounds.Bottom + expand, bounds.Right - expand, bounds.Top - expand, RoundRadius);
rect = new RoundedRect(bounds.Left + expand,
bounds.Bottom + expand,
bounds.Right - expand,
bounds.Top - expand,
RoundRadius * GuiWidget.DeviceScale);
var rectOutline = new Stroke(rect, stroke);
graphics2D.Render(rectOutline, BorderColor);
@ -191,6 +203,9 @@ namespace MatterHackers.MatterControl.CustomWidgets
public BorderDouble BackgroundInset { get; set; }
/// <summary>
/// This is in device units and will be scaled when drawn to the screen (do not scale the input by DeviceScale)
/// </summary>
public double RoundRadius { get; set; }
public bool RenderOutline { get; set; }
@ -198,6 +213,9 @@ namespace MatterHackers.MatterControl.CustomWidgets
public class SimpleFlowButton : FlowLayoutWidget
{
/// <summary>
/// This is in device units and will be scaled when drawn to the screen (do not scale the input by DeviceScale)
/// </summary>
public double RoundRadius { get; set; }
public bool RenderOutline { get; set; }
@ -247,7 +265,11 @@ namespace MatterHackers.MatterControl.CustomWidgets
public override void OnDrawBackground(Graphics2D graphics2D)
{
var bounds = this.LocalBounds;
var rect = new RoundedRect(bounds.Left, bounds.Bottom, bounds.Right, bounds.Top, RoundRadius);
var rect = new RoundedRect(bounds.Left,
bounds.Bottom,
bounds.Right,
bounds.Top,
RoundRadius * GuiWidget.DeviceScale);
if (BackgroundColor.Alpha0To255 > 0)
{
@ -258,7 +280,11 @@ namespace MatterHackers.MatterControl.CustomWidgets
{
var stroke = 1 * GuiWidget.DeviceScale;
var expand = stroke / 2;
rect = new RoundedRect(bounds.Left + expand, bounds.Bottom + expand, bounds.Right - expand, bounds.Top - expand, RoundRadius);
rect = new RoundedRect(bounds.Left + expand,
bounds.Bottom + expand,
bounds.Right - expand,
bounds.Top - expand,
RoundRadius * GuiWidget.DeviceScale);
var rectOutline = new Stroke(rect, stroke);
graphics2D.Render(rectOutline, BorderColor);

View file

@ -102,23 +102,14 @@ namespace MatterHackers.MatterControl
public void DrawTrackAndThumb(Graphics2D graphics2D)
{
RoundedRect track = new RoundedRect(GetTrackBounds(), this.TrackRadius);
Vector2 ValuePrintPosition;
if (sliderAttachedTo.Orientation == Orientation.Horizontal)
{
ValuePrintPosition = new Vector2(sliderAttachedTo.TotalWidthInPixels / 2, -TrackHeight - 12);
}
else
{
ValuePrintPosition = new Vector2(0, -TrackHeight - 12);
}
var track = new RoundedRect(GetTrackBounds(), this.TrackRadius);
// draw the track
graphics2D.Render(track, TrackColor);
// now do the thumb
RectangleDouble thumbBounds = sliderAttachedTo.GetThumbHitBounds();
RoundedRect thumbOutside = new RoundedRect(thumbBounds, 0);
var thumbOutside = new RoundedRect(thumbBounds, 2 * GuiWidget.DeviceScale);
graphics2D.Render(thumbOutside, this.ThumbColor); // ColorF.GetTweenColor(ThumbColor.ToColorF(), ColorF.Black.ToColorF(), .2).ToColor());
}
}

View file

@ -155,7 +155,7 @@ namespace MatterHackers.MatterControl.CustomWidgets
this.ContentPanel.BorderColor = Color.Transparent;
}
public int BorderRadius { get; set; } = 0;
public int BorderRadius { get; set; }
public bool ExpandableWhenDisabled { get; set; }

View file

@ -204,20 +204,35 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
exportPlugin.Initialize(printer);
var exportGCodeButton = menuTheme.CreateDialogButton("Export".Localize());
exportGCodeButton.Name = "Export Gcode Button";
exportGCodeButton.Enabled = exportPlugin.Enabled;
exportGCodeButton.ToolTipText = exportPlugin.Enabled ? exportType : exportPlugin.DisabledReason;
exportGCodeButton.Click += (s, e) =>
var exportGCodeButton = menuTheme.CreateSplitButton(new SplitButtonParams()
{
this.CloseMenu();
ExportPrintItemPage.DoExport(
new[] { new InMemoryLibraryItem(printer.Bed.Scene) },
printer,
exportPlugin);
};
ButtonText = "Export".Localize(),
ButtonTooltip = exportPlugin.Enabled ? exportType : exportPlugin.DisabledReason,
ExtendPopupMenu = (popupMenu) =>
{
var operationMenu = popupMenu.CreateMenuItem("Options...");
operationMenu.Click += (s, e) =>
{
ApplicationController.Instance.ExportLibraryItems(
new[] { new InMemoryLibraryItem(printer.Bed.Scene) },
centerOnBed: false,
printer: printer);
this.CloseMenu();
};
},
ButtonEnabled = exportPlugin.Enabled,
ButtonName = "Export Gcode Button",
ButtonAction = (widget) =>
{
this.CloseMenu();
ExportPrintItemPage.DoExport(
new[] { new InMemoryLibraryItem(printer.Bed.Scene) },
printer,
exportPlugin);
},
});
exportGCodeButton.ToolTipText = "More Export Options".Localize();
setupRow.AddChild(exportGCodeButton);
}

View file

@ -295,11 +295,11 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
new SplitButtonParams()
{
Icon = defaultOperation.Icon(theme.InvertIcons),
DefaultAction = (menuButton) =>
ButtonAction = (menuButton) =>
{
defaultOperation.Action.Invoke(sceneContext);
},
DefaultActionTooltip = defaultOperation.HelpText ?? defaultOperation.Title,
ButtonTooltip = defaultOperation.HelpText ?? defaultOperation.Title,
ButtonName = defaultOperation.Title,
ExtendPopupMenu = (PopupMenu popupMenu) =>
{
@ -816,7 +816,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
{
ButtonName = "Save",
Icon = StaticData.Instance.LoadIcon("save_grey_16x.png", 16, 16, theme.InvertIcons),
DefaultAction = (menuButton) =>
ButtonAction = (menuButton) =>
{
ApplicationController.Instance.Tasks.Execute("Saving".Localize(), sceneContext.Printer, async (progress, cancellationToken) =>
{
@ -834,7 +834,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
menuButton.Enabled = true;
}).ConfigureAwait(false);
},
DefaultActionTooltip = "Save".Localize(),
ButtonTooltip = "Save".Localize(),
ExtendPopupMenu = (PopupMenu popupMenu) =>
{
var saveAs = popupMenu.CreateMenuItem("Save As".Localize());

View file

@ -32,6 +32,7 @@ using System.Linq;
using MatterHackers.Agg;
using MatterHackers.Agg.Image;
using MatterHackers.Agg.UI;
using MatterHackers.Agg.VertexSource;
using MatterHackers.MatterControl.PartPreviewWindow;
using MatterHackers.VectorMath;
@ -190,6 +191,8 @@ namespace MatterHackers.MatterControl.CustomWidgets
set => base.BackgroundColor = value;
}
public int BorderRadius { get; set; } = 3;
public override void OnLoad(EventArgs args)
{
// The top level SystemWindow - due to single window implementation details, multiple SystemWindow parents may exist - proceed to the topmost one
@ -277,6 +280,19 @@ namespace MatterHackers.MatterControl.CustomWidgets
{
}
public override void OnDrawBackground(Graphics2D graphics2D)
{
if (this.BorderRadius > 0)
{
var rect = new RoundedRect(this.LocalBounds, this.BorderRadius);
graphics2D.Render(rect, this.BackgroundColor);
}
else
{
base.OnDrawBackground(graphics2D);
}
}
protected void ShowPopover(SettingsRow settingsRow)
{
// Only display popovers when we're the active widget, exit if we're not first under mouse