Upgrading to .net 6

This commit is contained in:
Lars Brubaker 2022-07-15 17:28:39 -07:00
parent 738c6e20ea
commit 32a192c2b8
155 changed files with 2030 additions and 2536 deletions

View file

@ -107,9 +107,10 @@ namespace MatterHackers.MatterControl
{
_themeset = JsonConvert.DeserializeObject<ThemeSet>(File.ReadAllText(ProfileManager.Instance.ProfileThemeSetPath));
ThemeSet.Theme.EnsureDefaults();
MatterHackersThemeConfigExtensions.RebuildTheme(ThemeSet.Theme);
// If the serialized format is older than the current format, null and fall back to latest default below
if (ThemeSet.SchemeVersion != ThemeSet.LatestSchemeVersion)
// If the serialized format is older than the current format, null and fall back to latest default below
if (ThemeSet.SchemeVersion != ThemeSet.LatestSchemeVersion)
{
_themeset = null;
}
@ -163,6 +164,7 @@ namespace MatterHackers.MatterControl
var themeConfig = JsonConvert.DeserializeObject<ThemeConfig>(json);
themeConfig.EnsureDefaults();
MatterHackersThemeConfigExtensions.RebuildTheme(ThemeSet.Theme);
return themeConfig;
}

View file

@ -788,7 +788,7 @@ namespace MatterHackers.MatterControl
await applicationController.Tasks.Execute(task.Title, null, task.Action);
}
// If we have not cancled the show welcome message and there is a window open
if (UserSettings.Instance.get(UserSettingsKey.ShownWelcomeMessage) != "false"
&& ApplicationController.Instance.Workspaces.Count > 0)
@ -802,7 +802,7 @@ namespace MatterHackers.MatterControl
else
{
}
}
}
catch
{

View file

@ -39,6 +39,7 @@ using System.Net;
using System.Net.Http;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
@ -566,10 +567,39 @@ namespace MatterHackers.MatterControl
targetUri += internalLink;
}
Process.Start(targetUri);
ProcessStart(targetUri);
});
}
public static void ProcessStart(string input)
{
try
{
Process.Start(input);
}
catch
{
// hack because of this: https://github.com/dotnet/corefx/issues/10361
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
input = input.Replace("&", "^&");
Process.Start(new ProcessStartInfo("cmd", $"/c start {input}") { CreateNoWindow = true });
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
Process.Start("xdg-open", input);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
Process.Start("open", input);
}
else
{
throw;
}
}
}
internal void MakeGrayscale(ImageBuffer sourceImage)
{
var buffer = sourceImage.GetBuffer();

View file

@ -27,56 +27,15 @@ of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*/
using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using global::MatterControl.Printing;
using Markdig.Agg;
using Markdig.Renderers.Agg;
using MatterHackers.Agg;
using MatterHackers.Agg.Font;
using MatterHackers.Agg.Image;
using MatterHackers.Agg.Platform;
using MatterHackers.Agg.UI;
using MatterHackers.Agg.VertexSource;
using MatterHackers.DataConverters3D;
using MatterHackers.DataConverters3D.UndoCommands;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.CustomWidgets;
using MatterHackers.MatterControl.DataStorage;
using MatterHackers.MatterControl.DesignTools;
using MatterHackers.MatterControl.DesignTools.Operations;
using MatterHackers.MatterControl.Extensibility;
using MatterHackers.MatterControl.Library;
using MatterHackers.MatterControl.PartPreviewWindow;
using MatterHackers.MatterControl.PartPreviewWindow.View3D;
using MatterHackers.MatterControl.Plugins;
using MatterHackers.MatterControl.PrinterCommunication;
using MatterHackers.MatterControl.PrinterControls.PrinterConnections;
using MatterHackers.MatterControl.PrintQueue;
using MatterHackers.MatterControl.SettingsManagement;
using MatterHackers.MatterControl.SlicerConfiguration;
using MatterHackers.MatterControl.Tour;
using MatterHackers.PolygonMesh;
using MatterHackers.PolygonMesh.Processors;
using MatterHackers.VectorMath;
using MatterHackers.VectorMath.TrackBall;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq;
[assembly: InternalsVisibleTo("MatterControl.Tests")]
[assembly: InternalsVisibleTo("MatterControl.AutomationTests")]
@ -84,7 +43,7 @@ using Newtonsoft.Json.Linq;
namespace MatterHackers.MatterControl
{
public class RunningTasksConfig
public class RunningTasksConfig
{
public event EventHandler TasksChanged;

View file

@ -33,9 +33,9 @@ using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MatterHackers.Agg;
using MatterHackers.Agg.Image;
using MatterHackers.Agg.Platform;
using MatterHackers.Agg.UI;
using MatterHackers.ImageProcessing;
using MatterHackers.MatterControl.Library;

View file

@ -42,11 +42,8 @@ using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl
{
public class ThemeConfig
public class ThemeConfig3
{
private ImageBuffer restoreNormal;
private ImageBuffer restoreHover;
public int FontSize7 { get; } = 7;
public int FontSize8 { get; } = 8;
@ -73,10 +70,6 @@ namespace MatterHackers.MatterControl
public double MenuGutterWidth => 35 * GuiWidget.DeviceScale;
public double MicroButtonHeight => 20 * GuiWidget.DeviceScale;
private double MicroButtonWidth => 30 * GuiWidget.DeviceScale;
private readonly int defaultScrollBarWidth = 120;
public void MakeRoundedButton(GuiWidget button, Color? boarderColor = null)
@ -100,44 +93,6 @@ namespace MatterHackers.MatterControl
}
}
public void ApplyPrimaryActionStyle(GuiWidget guiWidget)
{
guiWidget.BackgroundColor = new Color(this.AccentMimimalOverlay, 50);
Color hoverColor = this.AccentMimimalOverlay;
switch (guiWidget)
{
case PopupMenuButton menuButton:
menuButton.HoverColor = hoverColor;
break;
case SimpleFlowButton flowButton:
flowButton.HoverColor = hoverColor;
break;
case SimpleButton button:
button.HoverColor = hoverColor;
break;
}
}
internal void RemovePrimaryActionStyle(GuiWidget guiWidget)
{
guiWidget.BackgroundColor = Color.Transparent;
// Buttons in toolbars should revert to ToolbarButtonHover when reset
bool parentIsToolbar = guiWidget.Parent?.Parent is Toolbar;
switch (guiWidget)
{
case SimpleFlowButton flowButton:
flowButton.HoverColor = parentIsToolbar ? this.ToolbarButtonHover : Color.Transparent;
break;
case SimpleButton button:
button.HoverColor = parentIsToolbar ? this.ToolbarButtonHover : Color.Transparent;
break;
}
}
public BorderDouble TextButtonPadding { get; } = new BorderDouble(14, 0);
public BorderDouble ButtonSpacing { get; } = new BorderDouble(right: 3);
@ -210,8 +165,6 @@ namespace MatterHackers.MatterControl
public BorderDouble SeparatorMargin { get; }
public ImageBuffer GeneratingThumbnailIcon { get; private set; }
public class StateColor
{
public Color BackgroundColor { get; set; }
@ -249,12 +202,6 @@ namespace MatterHackers.MatterControl
public Color BorderColor20 { get; set; }
internal void EnsureDefaults()
{
// EnsureDefaults is called after deserialization and at a point when state should be fully loaded. Invoking RebuildTheme here ensures icons shaded correctly
this.RebuildTheme();
}
public Color RowBorder { get; set; }
public DropListStyle DropList { get; set; } = new DropListStyle();
@ -280,128 +227,12 @@ namespace MatterHackers.MatterControl
public GridColors BedGridColors { get; set; } = new GridColors();
public double ButtonRadius { get; set; } = 3;
public GuiWidget CreateSearchButton()
{
return new IconButton(StaticData.Instance.LoadIcon("icon_search_24x24.png", 16, 16).SetToColor(TextColor), this)
{
ToolTipText = "Search".Localize(),
};
}
public ThemeConfig()
{
this.SeparatorMargin = (this.ButtonSpacing * 2).Clone(left: this.ButtonSpacing.Right);
this.RebuildTheme();
}
public void SetDefaults()
{
this.DisabledColor = new Color(this.LightTextColor, 50);
this.SplashAccentColor = new Color(this.PrimaryAccentColor, 185).OverlayOn(Color.White).ToColor();
}
public void RebuildTheme()
{
int size = (int)(16 * GuiWidget.DeviceScale);
// On Android, use red icon as no hover events, otherwise transparent and red on hover
restoreNormal = ColorCircle(size, (AggContext.OperatingSystem == OSType.Android) ? new Color(200, 0, 0) : Color.Transparent);
restoreHover = ColorCircle(size, new Color("#DB4437"));
this.GeneratingThumbnailIcon = StaticData.Instance.LoadIcon("building_thumbnail_40x40.png", 40, 40).SetToColor(TextColor);
ScrollBar.DefaultBackgroundColor = this.TextColor.WithAlpha(30);
ScrollBar.DefaultThumbColor = this.TextColor.WithAlpha(130);
ScrollBar.DefaultThumbHoverColor = this.PrimaryAccentColor.WithAlpha(130);
}
public JogControls.MoveButton CreateMoveButton(PrinterConfig printer, string label, PrinterConnection.Axis axis, double movementFeedRate, bool levelingButtons = false)
{
return new JogControls.MoveButton(label, printer, axis, movementFeedRate, this)
{
BackgroundColor = this.MinimalShade,
BorderColor = this.BorderColor40,
BackgroundOutlineWidth = 1,
VAnchor = VAnchor.Absolute,
HAnchor = HAnchor.Absolute,
Margin = 0,
Padding = 0,
Height = (levelingButtons ? 45 : 40) * GuiWidget.DeviceScale,
Width = (levelingButtons ? 90 : 40) * GuiWidget.DeviceScale,
};
}
public JogControls.ExtrudeButton CreateExtrudeButton(PrinterConfig printer, string label, double movementFeedRate, int extruderNumber, bool levelingButtons = false)
{
return new JogControls.ExtrudeButton(printer, label, movementFeedRate, extruderNumber, this)
{
BackgroundColor = this.MinimalShade,
BorderColor = this.BorderColor40,
BackgroundOutlineWidth = 1,
VAnchor = VAnchor.Absolute,
HAnchor = HAnchor.Absolute,
Margin = 0,
Padding = 0,
Height = (levelingButtons ? 45 : 40) * GuiWidget.DeviceScale,
Width = (levelingButtons ? 90 : 40) * GuiWidget.DeviceScale,
};
}
public RadioTextButton CreateMicroRadioButton(string text, IList<GuiWidget> siblingRadioButtonList = null)
{
var radioButton = new RadioTextButton(text, this, this.FontSize8)
{
SiblingRadioButtonList = siblingRadioButtonList,
Padding = new BorderDouble(5, 0),
SelectedBackgroundColor = this.SlightShade,
UnselectedBackgroundColor = this.SlightShade,
HoverColor = this.AccentMimimalOverlay,
Margin = new BorderDouble(right: 1),
HAnchor = HAnchor.Absolute,
Height = this.MicroButtonHeight,
Width = this.MicroButtonWidth
};
// Add to sibling list if supplied
siblingRadioButtonList?.Add(radioButton);
return radioButton;
}
public TextButton CreateLightDialogButton(string text)
{
return CreateDialogButton(text, new Color(Color.White, 15), new Color(Color.White, 25));
}
public TextButton CreateDialogButton(string text)
{
return CreateDialogButton(text, this.SlightShade, this.SlightShade.WithAlpha(75));
}
public TextButton CreateDialogButton(string text, Color backgroundColor, Color hoverColor)
{
#if !__ANDROID__
return new TextButton(text, this)
{
BackgroundColor = backgroundColor,
HoverColor = hoverColor,
MinimumSize = new Vector2(75, 0),
Margin = this.ButtonSpacing
};
#else
var button = new TextButton(text, this, this.FontSize14)
{
BackgroundColor = backgroundColor,
HoverColor = hoverColor,
// Enlarge button height and margin on Android
Height = 34 * GuiWidget.DeviceScale,
};
button.Padding = button.Padding * 1.2;
return button;
#endif
}
public Color GetBorderColor(int alpha)
{
return new Color(this.BorderColor, alpha);
@ -419,215 +250,6 @@ namespace MatterHackers.MatterControl
return new BlenderBGRA().Blend(background, overlay);
}
public FlowLayoutWidget CreateMenuItems(PopupMenu popupMenu, IEnumerable<NamedAction> menuActions)
{
// Create menu items in the DropList for each element in this.menuActions
foreach (var menuAction in menuActions)
{
if (menuAction is ActionSeparator)
{
popupMenu.CreateSeparator();
}
else
{
if (menuAction is NamedActionGroup namedActionButtons)
{
var content = new FlowLayoutWidget()
{
HAnchor = HAnchor.Fit | HAnchor.Stretch
};
var textWidget = new TextWidget(menuAction.Title, pointSize: this.DefaultFontSize, textColor: this.TextColor)
{
// Padding = MenuPadding,
VAnchor = VAnchor.Center
};
content.AddChild(textWidget);
content.AddChild(new HorizontalSpacer());
foreach (var actionButton in namedActionButtons.Group)
{
var button = new TextButton(actionButton.Title, this)
{
Border = new BorderDouble(1, 0, 0, 0),
BorderColor = this.MinimalShade,
HoverColor = this.AccentMimimalOverlay,
Enabled = actionButton.IsEnabled()
};
content.AddChild(button);
if (actionButton.IsEnabled())
{
button.Click += (s, e) =>
{
actionButton.Action();
popupMenu.Unfocus();
};
}
}
var menuItem = new PopupMenu.MenuItem(content, this)
{
HAnchor = HAnchor.Fit | HAnchor.Stretch,
VAnchor = VAnchor.Fit,
HoverColor = Color.Transparent,
};
popupMenu.AddChild(menuItem);
menuItem.Padding = new BorderDouble(menuItem.Padding.Left,
menuItem.Padding.Bottom,
0,
menuItem.Padding.Top);
}
else
{
PopupMenu.MenuItem menuItem;
if (menuAction is NamedBoolAction boolAction)
{
menuItem = popupMenu.CreateBoolMenuItem(menuAction.Title, boolAction.GetIsActive, boolAction.SetIsActive);
}
else
{
menuItem = popupMenu.CreateMenuItem(menuAction.Title, menuAction.Icon, menuAction.Shortcut);
}
menuItem.Name = $"{menuAction.Title} Menu Item";
menuItem.Enabled = menuAction is NamedActionGroup
|| (menuAction.Action != null && menuAction.IsEnabled?.Invoke() != false);
menuItem.ClearRemovedFlag();
if (menuItem.Enabled)
{
menuItem.Click += (s, e) =>
{
menuAction.Action();
};
}
}
}
}
return popupMenu;
}
public PopupMenuButton CreateSplitButton(SplitButtonParams buttonParams, OperationGroup operationGroup = null)
{
PopupMenuButton menuButton = null;
GuiWidget innerButton;
if (buttonParams.ButtonText == null)
{
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
{
if (buttonParams.Icon == null)
{
innerButton = new TextButton(buttonParams.ButtonText, this)
{
Name = buttonParams.ButtonName,
Enabled = buttonParams.ButtonEnabled,
ToolTipText = buttonParams.ButtonTooltip,
};
}
else
{
innerButton = new TextIconButton(buttonParams.ButtonText, buttonParams.Icon, this)
{
Name = buttonParams.ButtonName,
Enabled = buttonParams.ButtonEnabled,
ToolTipText = buttonParams.ButtonTooltip,
Padding = new BorderDouble(5, 0, 5, 0)
};
}
}
innerButton.Click += (s, e) =>
{
buttonParams.ButtonAction.Invoke(menuButton);
};
if (operationGroup == null)
{
menuButton = new PopupMenuButton(innerButton, this);
}
else
{
menuButton = new OperationGroupButton(operationGroup, innerButton, this);
}
var theme = ApplicationController.Instance.MenuTheme;
menuButton.DynamicPopupContent = () =>
{
var popupMenu = new PopupMenu(theme);
buttonParams.ExtendPopupMenu?.Invoke(popupMenu);
return popupMenu;
};
menuButton.Name = buttonParams.ButtonName + " Menu SplitButton";
menuButton.BackgroundColor = buttonParams.BackgroundColor;
if (menuButton.BackgroundColor == Color.Transparent)
{
menuButton.BackgroundColor = this.ToolbarButtonBackground;
}
menuButton.HoverColor = this.ToolbarButtonHover;
menuButton.MouseDownColor = this.ToolbarButtonDown;
menuButton.DrawArrow = true;
menuButton.Margin = this.ButtonSpacing;
menuButton.DistinctPopupButton = true;
menuButton.BackgroundRadius = new RadiusCorners(theme.ButtonRadius * GuiWidget.DeviceScale, theme.ButtonRadius * GuiWidget.DeviceScale, 0, 0);
innerButton.Selectable = true;
return menuButton;
}
private static ImageBuffer ColorCircle(int size, Color color)
{
var imageBuffer = new ImageBuffer(size, size);
Graphics2D normalGraphics = imageBuffer.NewGraphics2D();
var center = new Vector2(size / 2.0, size / 2.0);
Color barColor;
if (color != Color.Transparent)
{
normalGraphics.Circle(center, size / 2.0, color);
barColor = Color.White;
}
else
{
barColor = new Color("#999");
}
normalGraphics.Line(center + new Vector2(-size / 4.0, -size / 4.0), center + new Vector2(size / 4.0, size / 4.0), barColor, 2 * GuiWidget.DeviceScale);
normalGraphics.Line(center + new Vector2(-size / 4.0, size / 4.0), center + new Vector2(size / 4.0, -size / 4.0), barColor, 2 * GuiWidget.DeviceScale);
return imageBuffer;
}
public GuiWidget CreateSmallResetButton()
{
return new HoverImageWidget(restoreNormal, restoreHover)
{
VAnchor = VAnchor.Center,
Margin = new BorderDouble(0, 0, 5, 0)
};
}
public SolidSlider CreateSolidSlider(GuiWidget wordOptionContainer, string header, ThemeConfig theme, double min = 0, double max = .5)
{
double scrollBarWidth = 10;
@ -678,55 +300,6 @@ namespace MatterHackers.MatterControl
widget.BorderColor = shadedBorder ? this.MinimalShade : this.BorderColor20;
widget.Border = border;
}
public SectionWidget ApplyBoxStyle(SectionWidget sectionWidget)
{
return ApplyBoxStyle(
sectionWidget,
this.SectionBackgroundColor,
margin: new BorderDouble(this.DefaultContainerPadding, 0, this.DefaultContainerPadding, this.DefaultContainerPadding));
}
public SolidSlider ApplySliderStyle(SolidSlider solidSlider)
{
solidSlider.View.TrackColor = this.SlightShade;
solidSlider.View.TrackRadius = 4;
return solidSlider;
}
public DoubleSolidSlider ApplySliderStyle(DoubleSolidSlider solidSlider)
{
solidSlider.View.TrackColor = this.SlightShade;
solidSlider.View.TrackRadius = 4;
return solidSlider;
}
// ApplySquareBoxStyle
public SectionWidget ApplyBoxStyle(SectionWidget sectionWidget, BorderDouble margin)
{
sectionWidget.BackgroundColor = this.SectionBackgroundColor;
sectionWidget.Margin = 0;
sectionWidget.Border = new BorderDouble(bottom: 1);
sectionWidget.BorderColor = this.RowBorder;
return sectionWidget;
}
public SectionWidget ApplyBoxStyle(SectionWidget sectionWidget, Color backgroundColor, BorderDouble margin)
{
// Enforce panel padding
// sectionWidget.ContentPanel.Padding = new BorderDouble(10, 0, 10, 2);
// sectionWidget.ContentPanel.Padding = 0;
sectionWidget.BorderColor = Color.Transparent;
sectionWidget.BorderRadius = 5;
sectionWidget.Margin = margin;
sectionWidget.BackgroundColor = backgroundColor;
return sectionWidget;
}
}
public class PresetColors
@ -771,4 +344,349 @@ namespace MatterHackers.MatterControl
public Color BackgroundColor { get; set; }
}
public static class MatterHackersThemeConfigExtensions
{
public static JogControls.MoveButton CreateMoveButton(this ThemeConfig config, PrinterConfig printer, string label, PrinterConnection.Axis axis, double movementFeedRate, bool levelingButtons = false)
{
return new JogControls.MoveButton(label, printer, axis, movementFeedRate, config)
{
BackgroundColor = config.MinimalShade,
BorderColor = config.BorderColor40,
BackgroundOutlineWidth = 1,
VAnchor = VAnchor.Absolute,
HAnchor = HAnchor.Absolute,
Margin = 0,
Padding = 0,
Height = (levelingButtons ? 45 : 40) * GuiWidget.DeviceScale,
Width = (levelingButtons ? 90 : 40) * GuiWidget.DeviceScale,
};
}
public static JogControls.ExtrudeButton CreateExtrudeButton(this ThemeConfig config, PrinterConfig printer, string label, double movementFeedRate, int extruderNumber, bool levelingButtons = false)
{
return new JogControls.ExtrudeButton(printer, label, movementFeedRate, extruderNumber, config)
{
BackgroundColor = config.MinimalShade,
BorderColor = config.BorderColor40,
BackgroundOutlineWidth = 1,
VAnchor = VAnchor.Absolute,
HAnchor = HAnchor.Absolute,
Margin = 0,
Padding = 0,
Height = (levelingButtons ? 45 : 40) * GuiWidget.DeviceScale,
Width = (levelingButtons ? 90 : 40) * GuiWidget.DeviceScale,
};
}
public static PopupMenuButton CreateSplitButton(this ThemeConfig config, SplitButtonParams buttonParams, OperationGroup operationGroup = null)
{
PopupMenuButton menuButton = null;
GuiWidget innerButton;
if (buttonParams.ButtonText == null)
{
innerButton = new IconButton(buttonParams.Icon, config)
{
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
{
if (buttonParams.Icon == null)
{
innerButton = new TextButton(buttonParams.ButtonText, config)
{
Name = buttonParams.ButtonName,
Enabled = buttonParams.ButtonEnabled,
ToolTipText = buttonParams.ButtonTooltip,
};
}
else
{
innerButton = new TextIconButton(buttonParams.ButtonText, buttonParams.Icon, config)
{
Name = buttonParams.ButtonName,
Enabled = buttonParams.ButtonEnabled,
ToolTipText = buttonParams.ButtonTooltip,
Padding = new BorderDouble(5, 0, 5, 0)
};
}
}
innerButton.Click += (s, e) =>
{
buttonParams.ButtonAction.Invoke(menuButton);
};
if (operationGroup == null)
{
menuButton = new PopupMenuButton(innerButton, config);
}
else
{
menuButton = new OperationGroupButton(operationGroup, innerButton, config);
}
var theme = ApplicationController.Instance.MenuTheme;
menuButton.DynamicPopupContent = () =>
{
var popupMenu = new PopupMenu(theme);
buttonParams.ExtendPopupMenu?.Invoke(popupMenu);
return popupMenu;
};
menuButton.Name = buttonParams.ButtonName + " Menu SplitButton";
menuButton.BackgroundColor = buttonParams.BackgroundColor;
if (menuButton.BackgroundColor == Color.Transparent)
{
menuButton.BackgroundColor = config.ToolbarButtonBackground;
}
menuButton.HoverColor = config.ToolbarButtonHover;
menuButton.MouseDownColor = config.ToolbarButtonDown;
menuButton.DrawArrow = true;
menuButton.Margin = config.ButtonSpacing;
menuButton.DistinctPopupButton = true;
menuButton.BackgroundRadius = new RadiusCorners(theme.ButtonRadius * GuiWidget.DeviceScale, theme.ButtonRadius * GuiWidget.DeviceScale, 0, 0);
innerButton.Selectable = true;
return menuButton;
}
public static GuiWidget CreateSearchButton(this ThemeConfig config)
{
return new IconButton(StaticData.Instance.LoadIcon("icon_search_24x24.png", 16, 16).SetToColor(config.TextColor), config)
{
ToolTipText = "Search".Localize(),
};
}
public static double MicroButtonHeight => 20 * GuiWidget.DeviceScale;
private static double MicroButtonWidth => 30 * GuiWidget.DeviceScale;
public static RadioTextButton CreateMicroRadioButton(this ThemeConfig config, string text, IList<GuiWidget> siblingRadioButtonList = null)
{
var radioButton = new RadioTextButton(text, config, config.FontSize8)
{
SiblingRadioButtonList = siblingRadioButtonList,
Padding = new BorderDouble(5, 0),
SelectedBackgroundColor = config.SlightShade,
UnselectedBackgroundColor = config.SlightShade,
HoverColor = config.AccentMimimalOverlay,
Margin = new BorderDouble(right: 1),
HAnchor = HAnchor.Absolute,
Height = config.MicroButtonHeight,
Width = MicroButtonWidth
};
// Add to sibling list if supplied
siblingRadioButtonList?.Add(radioButton);
return radioButton;
}
public static FlowLayoutWidget CreateMenuItems(this ThemeConfig config, PopupMenu popupMenu, IEnumerable<NamedAction> menuActions)
{
// Create menu items in the DropList for each element in this.menuActions
foreach (var menuAction in menuActions)
{
if (menuAction is ActionSeparator)
{
popupMenu.CreateSeparator();
}
else
{
if (menuAction is NamedActionGroup namedActionButtons)
{
var content = new FlowLayoutWidget()
{
HAnchor = HAnchor.Fit | HAnchor.Stretch
};
var textWidget = new TextWidget(menuAction.Title, pointSize: config.DefaultFontSize, textColor: config.TextColor)
{
// Padding = MenuPadding,
VAnchor = VAnchor.Center
};
content.AddChild(textWidget);
content.AddChild(new HorizontalSpacer());
foreach (var actionButton in namedActionButtons.Group)
{
var button = new TextButton(actionButton.Title, config)
{
Border = new BorderDouble(1, 0, 0, 0),
BorderColor = config.MinimalShade,
HoverColor = config.AccentMimimalOverlay,
Enabled = actionButton.IsEnabled()
};
content.AddChild(button);
if (actionButton.IsEnabled())
{
button.Click += (s, e) =>
{
actionButton.Action();
popupMenu.Unfocus();
};
}
}
var menuItem = new PopupMenu.MenuItem(content, config)
{
HAnchor = HAnchor.Fit | HAnchor.Stretch,
VAnchor = VAnchor.Fit,
HoverColor = Color.Transparent,
};
popupMenu.AddChild(menuItem);
menuItem.Padding = new BorderDouble(menuItem.Padding.Left,
menuItem.Padding.Bottom,
0,
menuItem.Padding.Top);
}
else
{
PopupMenu.MenuItem menuItem;
if (menuAction is NamedBoolAction boolAction)
{
menuItem = popupMenu.CreateBoolMenuItem(menuAction.Title, boolAction.GetIsActive, boolAction.SetIsActive);
}
else
{
menuItem = popupMenu.CreateMenuItem(menuAction.Title, menuAction.Icon, menuAction.Shortcut);
}
menuItem.Name = $"{menuAction.Title} Menu Item";
menuItem.Enabled = menuAction is NamedActionGroup
|| (menuAction.Action != null && menuAction.IsEnabled?.Invoke() != false);
menuItem.ClearRemovedFlag();
if (menuItem.Enabled)
{
menuItem.Click += (s, e) =>
{
menuAction.Action();
};
}
}
}
}
return popupMenu;
}
public static void ApplyPrimaryActionStyle(this ThemeConfig config, GuiWidget guiWidget)
{
guiWidget.BackgroundColor = new Color(config.AccentMimimalOverlay, 50);
Color hoverColor = config.AccentMimimalOverlay;
switch (guiWidget)
{
case PopupMenuButton menuButton:
menuButton.HoverColor = hoverColor;
break;
case SimpleFlowButton flowButton:
flowButton.HoverColor = hoverColor;
break;
case SimpleButton button:
button.HoverColor = hoverColor;
break;
}
}
public static void RemovePrimaryActionStyle(this ThemeConfig config, GuiWidget guiWidget)
{
guiWidget.BackgroundColor = Color.Transparent;
// Buttons in toolbars should revert to ToolbarButtonHover when reset
bool parentIsToolbar = guiWidget.Parent?.Parent is Toolbar;
switch (guiWidget)
{
case SimpleFlowButton flowButton:
flowButton.HoverColor = parentIsToolbar ? config.ToolbarButtonHover : Color.Transparent;
break;
case SimpleButton button:
button.HoverColor = parentIsToolbar ? config.ToolbarButtonHover : Color.Transparent;
break;
}
}
public static SolidSlider ApplySliderStyle(this ThemeConfig config, SolidSlider solidSlider)
{
solidSlider.View.TrackColor = config.SlightShade;
solidSlider.View.TrackRadius = 4;
return solidSlider;
}
public static DoubleSolidSlider ApplySliderStyle(this ThemeConfig config, DoubleSolidSlider solidSlider)
{
solidSlider.View.TrackColor = config.SlightShade;
solidSlider.View.TrackRadius = 4;
return solidSlider;
}
public static SectionWidget ApplyBoxStyle(this ThemeConfig config, SectionWidget sectionWidget)
{
return config.ApplyBoxStyle(
sectionWidget,
config.SectionBackgroundColor,
margin: new BorderDouble(config.DefaultContainerPadding, 0, config.DefaultContainerPadding, config.DefaultContainerPadding));
}
// ApplySquareBoxStyle
public static SectionWidget ApplyBoxStyle(this ThemeConfig config, SectionWidget sectionWidget, BorderDouble margin)
{
sectionWidget.BackgroundColor = config.SectionBackgroundColor;
sectionWidget.Margin = 0;
sectionWidget.Border = new BorderDouble(bottom: 1);
sectionWidget.BorderColor = config.RowBorder;
return sectionWidget;
}
public static SectionWidget ApplyBoxStyle(this ThemeConfig config, SectionWidget sectionWidget, Color backgroundColor, BorderDouble margin)
{
// Enforce panel padding
// sectionWidget.ContentPanel.Padding = new BorderDouble(10, 0, 10, 2);
// sectionWidget.ContentPanel.Padding = 0;
sectionWidget.BorderColor = Color.Transparent;
sectionWidget.BorderRadius = 5;
sectionWidget.Margin = margin;
sectionWidget.BackgroundColor = backgroundColor;
return sectionWidget;
}
public static GuiWidget CreateSmallResetButton(this ThemeConfig config)
{
return new HoverImageWidget(config.RestoreNormal, config.RestoreHover)
{
VAnchor = VAnchor.Center,
Margin = new BorderDouble(0, 0, 5, 0)
};
}
public static void RebuildTheme(this ThemeConfig config)
{
config.GeneratingThumbnailIcon = StaticData.Instance.LoadIcon("building_thumbnail_40x40.png", 40, 40).SetToColor(config.TextColor);
}
}
}

View file

@ -29,6 +29,7 @@ either expressed or implied, of the FreeBSD Project.
using System.Collections.Generic;
using MatterHackers.Agg;
using MatterHackers.Agg.UI;
namespace MatterHackers.MatterControl
{