From e5a63b052e915f8bfc5136672eaa370af50ae4b5 Mon Sep 17 00:00:00 2001 From: John Lewin Date: Fri, 29 Apr 2016 07:45:15 -0700 Subject: [PATCH] Migrate Theme support to Agg.UI --- AboutPage/AboutWidget.cs | 2 +- AboutPage/ContactForm.cs | 2 +- ActionBar/ActionBarPlus.cs | 4 +- ActionBar/PrintActionRow.cs | 8 +- ActionBar/PrintStatusRow.cs | 2 +- ActionBar/TemperatureWidgetBase.cs | 2 +- ApplicationView/MainApplicationWidget.cs | 4 +- .../ApplicationSettingsView.cs | 5 +- .../PrintLeveling/InstructionsPage.cs | 2 +- ControlElements/StyledMessageBoxWindow.cs | 4 +- ControlElements/ThemeFactory.cs | 385 ------------------ .../LibrarySelector/FolderBreadCrumbWidget.cs | 2 +- .../LibrarySelector/LibrarySelectorWidget.cs | 2 +- CustomWidgets/PartThumbnailWidget.cs | 2 +- CustomWidgets/PluginChooserWindow.cs | 2 +- CustomWidgets/PrintProgressBarWidget.cs | 4 +- CustomWidgets/ThemeColorSelectorWidget.cs | 62 ++- CustomWidgets/WizardControl.cs | 4 +- History/PrintHistoryListItem.cs | 2 +- Library/LibraryDataView.cs | 2 +- Library/LibraryRowItem.cs | 4 +- Library/LibraryRowItemPart.cs | 2 +- MatterControl.csproj | 1 - MatterControlApplication.cs | 33 +- .../BaseClasses/PartPreview3DWidget.cs | 2 +- .../BaseClasses/PartPreviewWidget.cs | 2 +- PartPreviewWindow/PartPreviewContent.cs | 2 +- PartPreviewWindow/PartPreviewMainWindow.cs | 2 +- PartPreviewWindow/SaveAsWindow.cs | 2 +- PartPreviewWindow/View3D/View3DWidget.cs | 6 +- PartPreviewWindow/ViewControls2D.cs | 6 +- PartPreviewWindow/ViewControls3D.cs | 4 +- PartPreviewWindow/ViewGcodeBasic.cs | 2 +- .../ControlWidgets/AdjustmentControls.cs | 2 +- Queue/QueueDataWidget.cs | 4 +- Queue/QueueRowItem.cs | 2 +- SettingsManagement/UserSettings.cs | 19 + SetupWizard/SetupWizardHome.cs | 2 +- SetupWizard/WizardPanel.cs | 2 +- .../Settings/ActiveSliceSettings.cs | 25 +- Submodules/agg-sharp | 2 +- 41 files changed, 155 insertions(+), 473 deletions(-) delete mode 100644 ControlElements/ThemeFactory.cs diff --git a/AboutPage/AboutWidget.cs b/AboutPage/AboutWidget.cs index d630f79e1..96578c09c 100644 --- a/AboutPage/AboutWidget.cs +++ b/AboutPage/AboutWidget.cs @@ -64,7 +64,7 @@ namespace MatterHackers.MatterControl customInfoTopToBottom.VAnchor = VAnchor.Max_FitToChildren_ParentHeight; customInfoTopToBottom.Padding = new BorderDouble(5, 10, 5, 0); - if (ActiveTheme.Instance.IsTouchScreen) + if (UserSettings.Instance.IsTouchScreen) { customInfoTopToBottom.AddChild(new UpdateControlView()); } diff --git a/AboutPage/ContactForm.cs b/AboutPage/ContactForm.cs index 341260726..582c96c19 100644 --- a/AboutPage/ContactForm.cs +++ b/AboutPage/ContactForm.cs @@ -341,7 +341,7 @@ namespace MatterHackers.MatterControl.ContactForm private void AddHandlers() { - ActiveTheme.Instance.ThemeChanged.RegisterEvent(ThemeChanged, ref unregisterEvents); + ActiveTheme.ThemeChanged.RegisterEvent(ThemeChanged, ref unregisterEvents); contactFormWidget.Closed += (sender, e) => { Close(); }; } diff --git a/ActionBar/ActionBarPlus.cs b/ActionBar/ActionBarPlus.cs index 05e979b43..2fa9426aa 100644 --- a/ActionBar/ActionBarPlus.cs +++ b/ActionBar/ActionBarPlus.cs @@ -55,7 +55,7 @@ namespace MatterHackers.MatterControl this.BackgroundColor = ActiveTheme.Instance.PrimaryAccentColor; // Add Child Elements - if (ActiveTheme.Instance.DisplayMode == ActiveTheme.ApplicationDisplayType.Responsive) + if (UserSettings.Instance.DisplayMode == ApplicationDisplayType.Responsive) { this.AddChild(new ActionBar.PrinterActionRow()); } @@ -63,7 +63,7 @@ namespace MatterHackers.MatterControl this.Padding = new BorderDouble(bottom: 6); // Add Handlers - ActiveTheme.Instance.ThemeChanged.RegisterEvent(ThemeChanged, ref unregisterEvents); + ActiveTheme.ThemeChanged.RegisterEvent(ThemeChanged, ref unregisterEvents); } public void ThemeChanged(object sender, EventArgs e) diff --git a/ActionBar/PrintActionRow.cs b/ActionBar/PrintActionRow.cs index 63715c2ff..5b6d243a0 100644 --- a/ActionBar/PrintActionRow.cs +++ b/ActionBar/PrintActionRow.cs @@ -225,7 +225,7 @@ namespace MatterHackers.MatterControl.ActionBar cancelConnectButton.Click += (sender, e) => { UiThread.RunOnIdle(CancelPrinting); }; reprintButton.Click += onReprintButton_Click; doneWithCurrentPartButton.Click += onDoneWithCurrentPartButton_Click; - ActiveTheme.Instance.ThemeChanged.RegisterEvent(ThemeChanged, ref unregisterEvents); + ActiveTheme.ThemeChanged.RegisterEvent(ThemeChanged, ref unregisterEvents); } protected void DisableActiveButtons() @@ -274,7 +274,7 @@ namespace MatterHackers.MatterControl.ActionBar if (!PrinterConnectionAndCommunication.Instance.PrinterIsConnected && PrinterConnectionAndCommunication.Instance.CommunicationState != PrinterConnectionAndCommunication.CommunicationStates.AttemptingToConnect) { - if (ActiveTheme.Instance.IsTouchScreen) + if (UserSettings.Instance.IsTouchScreen) { this.activePrintButtons.Add(connectButton); } @@ -335,7 +335,7 @@ namespace MatterHackers.MatterControl.ActionBar this.activePrintButtons.Add(pauseButton); this.activePrintButtons.Add(cancelButton); } - else if (ActiveTheme.Instance.IsTouchScreen) + else if (UserSettings.Instance.IsTouchScreen) { this.activePrintButtons.Add(resetConnectionButton); } @@ -363,7 +363,7 @@ namespace MatterHackers.MatterControl.ActionBar if (PrinterConnectionAndCommunication.Instance.PrinterIsConnected && ActiveSliceSettings.Instance.ShowResetConnection() - && ActiveTheme.Instance.IsTouchScreen) + && UserSettings.Instance.IsTouchScreen) { this.activePrintButtons.Add(resetConnectionButton); ShowActiveButtons(); diff --git a/ActionBar/PrintStatusRow.cs b/ActionBar/PrintStatusRow.cs index 74395f355..dae271272 100644 --- a/ActionBar/PrintStatusRow.cs +++ b/ActionBar/PrintStatusRow.cs @@ -65,7 +65,7 @@ namespace MatterHackers.MatterControl.ActionBar public static GuiWidget Create(QueueDataView queueDataView) { - if (ActiveTheme.Instance.IsTouchScreen) + if (UserSettings.Instance.IsTouchScreen) { return new TouchScreenPrintStatusRow(queueDataView); } diff --git a/ActionBar/TemperatureWidgetBase.cs b/ActionBar/TemperatureWidgetBase.cs index 5f05b00e5..376c124b8 100644 --- a/ActionBar/TemperatureWidgetBase.cs +++ b/ActionBar/TemperatureWidgetBase.cs @@ -103,7 +103,7 @@ namespace MatterHackers.MatterControl.ActionBar this.AddChild(currentTempIndicator); this.AddChild(buttonContainer); - ActiveTheme.Instance.ThemeChanged.RegisterEvent(ThemeChanged, ref unregisterEvents); + ActiveTheme.ThemeChanged.RegisterEvent(ThemeChanged, ref unregisterEvents); this.MouseEnterBounds += onEnterBounds; this.MouseLeaveBounds += onLeaveBounds; diff --git a/ApplicationView/MainApplicationWidget.cs b/ApplicationView/MainApplicationWidget.cs index 2c5631e68..571f949a6 100644 --- a/ApplicationView/MainApplicationWidget.cs +++ b/ApplicationView/MainApplicationWidget.cs @@ -183,7 +183,7 @@ namespace MatterHackers.MatterControl public ApplicationController() { //Name = "MainSlidePanel"; - ActiveTheme.Instance.ThemeChanged.RegisterEvent(ThemeChanged, ref unregisterEvents); + ActiveTheme.ThemeChanged.RegisterEvent(ThemeChanged, ref unregisterEvents); } public void ThemeChanged(object sender, EventArgs e) @@ -246,7 +246,7 @@ namespace MatterHackers.MatterControl //using (new PerformanceTimer("Startup", "AppController Instance")) { globalInstance = new ApplicationController(); - if (ActiveTheme.Instance.DisplayMode == ActiveTheme.ApplicationDisplayType.Touchscreen) + if (UserSettings.Instance.DisplayMode == ApplicationDisplayType.Touchscreen) { globalInstance.MainView = new TouchscreenView(); } diff --git a/ConfigurationPage/ApplicationSettings/ApplicationSettingsView.cs b/ConfigurationPage/ApplicationSettings/ApplicationSettingsView.cs index 7ec6e8b0c..9c9a44ef0 100644 --- a/ConfigurationPage/ApplicationSettings/ApplicationSettingsView.cs +++ b/ConfigurationPage/ApplicationSettings/ApplicationSettingsView.cs @@ -60,7 +60,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage mainContainer.AddChild(new HorizontalLine(separatorLineColor)); #endif - if (ActiveTheme.Instance.IsTouchScreen) + if (UserSettings.Instance.IsTouchScreen) { mainContainer.AddChild(GetUpdateControl()); mainContainer.AddChild(new HorizontalLine(separatorLineColor)); @@ -85,7 +85,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage mainContainer.AddChild(new HorizontalLine(separatorLineColor)); #endif - if (ActiveTheme.Instance.IsTouchScreen) + if (UserSettings.Instance.IsTouchScreen) { mainContainer.AddChild(GetModeControl()); mainContainer.AddChild(new HorizontalLine(separatorLineColor)); @@ -541,7 +541,6 @@ namespace MatterHackers.MatterControl.ConfigurationPage { UserSettings.Instance.Fields.IsSimpleMode = false; } - ActiveTheme.Instance.ReloadThemeSettings(); } private void ReleaseOptionsDropList_SelectionChanged(object sender, EventArgs e) diff --git a/ConfigurationPage/PrintLeveling/InstructionsPage.cs b/ConfigurationPage/PrintLeveling/InstructionsPage.cs index ddf3881c4..6ff3c0de4 100644 --- a/ConfigurationPage/PrintLeveling/InstructionsPage.cs +++ b/ConfigurationPage/PrintLeveling/InstructionsPage.cs @@ -43,7 +43,7 @@ namespace MatterHackers.MatterControl public InstructionsPage(string pageDescription, string instructionsText) : base(pageDescription) { - if (ActiveTheme.Instance.IsTouchScreen) + if (UserSettings.Instance.IsTouchScreen) { extraTextScaling = 1.33333; } diff --git a/ControlElements/StyledMessageBoxWindow.cs b/ControlElements/StyledMessageBoxWindow.cs index 28f9a8b09..e67239c60 100644 --- a/ControlElements/StyledMessageBoxWindow.cs +++ b/ControlElements/StyledMessageBoxWindow.cs @@ -33,7 +33,7 @@ namespace MatterHackers.MatterControl public StyledMessageBox(Action callback, String message, string windowTitle, MessageType messageType, GuiWidget[] extraWidgetsToAdd, double width, double height, string yesOk, string no) : base(width, height) { - if (ActiveTheme.Instance.IsTouchScreen) + if (UserSettings.Instance.IsTouchScreen) { extraTextScaling = 1.33333; } @@ -59,7 +59,7 @@ namespace MatterHackers.MatterControl unwrappedMessage = message; FlowLayoutWidget topToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom); topToBottom.AnchorAll(); - if (ActiveTheme.Instance.IsTouchScreen) + if (UserSettings.Instance.IsTouchScreen) { topToBottom.Padding = new BorderDouble(12, 12, 13, 8); } diff --git a/ControlElements/ThemeFactory.cs b/ControlElements/ThemeFactory.cs deleted file mode 100644 index 3de85cb21..000000000 --- a/ControlElements/ThemeFactory.cs +++ /dev/null @@ -1,385 +0,0 @@ -using MatterHackers.Agg; -using MatterHackers.Agg.UI; -using MatterHackers.MatterControl.SettingsManagement; -using MatterHackers.MatterControl.SlicerConfiguration; -/* -Copyright (c) 2014, Kevin Pope -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, this -list of conditions and the following disclaimer. -2. Redistributions in binary form must reproduce the above copyright notice, -this list of conditions and the following disclaimer in the documentation -and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -The views and conclusions contained in the software and documentation are those -of the authors and should not be interpreted as representing official policies, -either expressed or implied, of the FreeBSD Project. -*/ - -using System; -using System.Collections.Generic; -using System.Diagnostics; - -namespace MatterHackers.MatterControl -{ - public class ActiveTheme - { - private static ActiveTheme globalInstance; - private Theme loadedTheme; - private List availableThemes; - private int defaultThemeIndex = 1; - private int activeThemeIndex = -1; - - public RootedObjectEventHandler ThemeChanged = new RootedObjectEventHandler(); - - public enum ApplicationDisplayType { Responsive, Touchscreen } ; - - public ApplicationDisplayType DisplayMode - { - get - { - string displayMode = UserSettings.Instance.get("ApplicationDisplayMode"); - if (displayMode == "touchscreen") - { - return ApplicationDisplayType.Touchscreen; - } - else - { - return ApplicationDisplayType.Responsive; - } - } - } - - public List AvailableThemes - { - get - { - if (this.availableThemes == null) - { - this.availableThemes = GetAvailableThemes(); - } - return availableThemes; - } - } - - public bool IsDarkTheme - { - get - { - return loadedTheme.DarkTheme; - } - } - - public RGBA_Bytes Transparent - { - get - { - return new RGBA_Bytes(0, 0, 0, 0); - } - } - - public RGBA_Bytes TransparentDarkOverlay - { - get - { - return new RGBA_Bytes(0, 0, 0, 50); - } - } - - public RGBA_Bytes TransparentLightOverlay - { - get - { - return new RGBA_Bytes(255, 255, 255, 50); - } - } - - public RGBA_Bytes TabLabelSelected - { - get - { - return loadedTheme.tabLabelSelectedColor; - } - } - - public RGBA_Bytes TabLabelUnselected - { - get - { - return loadedTheme.tabLabelUnselectedColor; - } - } - - public RGBA_Bytes SecondaryTextColor - { - get - { - return loadedTheme.secondaryTextColor; - } - } - - public RGBA_Bytes PrimaryBackgroundColor - { - get - { - return loadedTheme.primaryBackgroundColor; - } - } - - public RGBA_Bytes SecondaryBackgroundColor - { - get - { - return loadedTheme.secondaryBackgroundColor; - } - } - - public RGBA_Bytes TertiaryBackgroundColor - { - get - { - return loadedTheme.tertiaryBackgroundColor; - } - } - - public RGBA_Bytes PrimaryTextColor - { - get - { - return loadedTheme.primaryTextColor; - } - } - - public RGBA_Bytes PrimaryAccentColor - { - get - { - return loadedTheme.primaryAccentColor; - } - } - - public RGBA_Bytes SecondaryAccentColor - { - get - { - return loadedTheme.secondaryAccentColor; - } - } - - private void OnThemeChanged(EventArgs e) - { - ThemeChanged.CallEvents(this, e); - } - - public ActiveTheme() - { - - //Load the default theme by index - if (string.IsNullOrEmpty(ActiveSliceSettings.Instance.ActiveValue("MatterControl.ActiveThemeIndex"))) - { - bool foundOemColor = false; - for (int i = 0; i < AvailableThemes.Count; i++) - { - Theme current = AvailableThemes[i]; - if (current.Name == OemSettings.Instance.ThemeColor) - { - ActiveSliceSettings.Instance.SetActiveValue("MatterControl.ActiveThemeIndex", i.ToString()); - foundOemColor = true; - break; - } - } - - if (!foundOemColor) - { - ActiveSliceSettings.Instance.SetActiveValue("MatterControl.ActiveThemeIndex", defaultThemeIndex.ToString()); - } - } - - int themeIndex; - try - { - themeIndex = Convert.ToInt32(ActiveSliceSettings.Instance.ActiveValue("MatterControl.ActiveThemeIndex")); - } - catch - { - GuiWidget.BreakInDebugger(); - themeIndex = defaultThemeIndex; - } - - LoadThemeSettings(themeIndex); - } - - public static ActiveTheme Instance - { - get - { - if (globalInstance == null) - { - globalInstance = new ActiveTheme(); - } - return globalInstance; - } - } - - public void ReloadThemeSettings() - { - //Reload the current theme - OnThemeChanged(null); - } - - public void LoadThemeSettings(int index, bool supressReloadEvent = false) - { - //Validate new theme selection and change theme - if (index > -1 && index < AvailableThemes.Count) - { - if (activeThemeIndex != index) - { - this.loadedTheme = this.AvailableThemes[index]; - this.activeThemeIndex = index; - - if (!supressReloadEvent) - { - OnThemeChanged(null); - } - } - } - else - { - throw new Exception("Invalid theme selection"); - } - } - - /// - /// Switches to the ActivePrinter theme without firing the ThemeChanged event. This is useful when changing printers and - /// allows the theme state to be updated before the ActivePrinterChanged event fires, resulting in a single ReloadAll - /// occurring rather than two - /// - public void SwitchToPrinterThemeWithoutReloadEvent() - { - string activeThemeIndex = ActiveSliceSettings.Instance.ActiveValue("MatterControl.ActiveThemeIndex"); - - int themeIndex; - if (string.IsNullOrEmpty(activeThemeIndex) || !int.TryParse(activeThemeIndex, out themeIndex)) - { - // Fall back to default theme if user settings are missing or invalid - themeIndex = defaultThemeIndex; - } - - LoadThemeSettings(themeIndex, supressReloadEvent: true); - } - - private List GetAvailableThemes() - { - //Generate a list of available theme definitions - List themeList = new List(); - - //Dark themes - themeList.Add(new Theme("Blue - Dark", new RGBA_Bytes(0, 75, 139), new RGBA_Bytes(0, 103, 190))); - themeList.Add(new Theme("Teal - Dark", new RGBA_Bytes(0, 130, 153), new RGBA_Bytes(0, 173, 204))); - themeList.Add(new Theme("Green - Dark", new RGBA_Bytes(0, 138, 23), new RGBA_Bytes(0, 189, 32))); - themeList.Add(new Theme("Light Blue - Dark", new RGBA_Bytes(93, 178, 255), new RGBA_Bytes(144, 202, 255))); - themeList.Add(new Theme("Orange - Dark", new RGBA_Bytes(255, 129, 25), new RGBA_Bytes(255, 157, 76))); - themeList.Add(new Theme("Purple - Dark", new RGBA_Bytes(70, 23, 180), new RGBA_Bytes(104, 51, 229))); - themeList.Add(new Theme("Red - Dark", new RGBA_Bytes(172, 25, 61), new RGBA_Bytes(217, 31, 77))); - themeList.Add(new Theme("Pink - Dark", new RGBA_Bytes(220, 79, 173), new RGBA_Bytes(233, 143, 203))); - themeList.Add(new Theme("Grey - Dark", new RGBA_Bytes(88, 88, 88), new RGBA_Bytes(114, 114, 114))); - themeList.Add(new Theme("Pink - Dark", new RGBA_Bytes(140, 0, 149), new RGBA_Bytes(188, 0, 200))); - - //Light themes - themeList.Add(new Theme("Blue - Light", new RGBA_Bytes(0, 75, 139), new RGBA_Bytes(0, 103, 190), false)); - themeList.Add(new Theme("Teal - Light", new RGBA_Bytes(0, 130, 153), new RGBA_Bytes(0, 173, 204), false)); - themeList.Add(new Theme("Green - Light", new RGBA_Bytes(0, 138, 23), new RGBA_Bytes(0, 189, 32), false)); - themeList.Add(new Theme("Light Blue - Light", new RGBA_Bytes(93, 178, 255), new RGBA_Bytes(144, 202, 255), false)); - themeList.Add(new Theme("Orange - Light", new RGBA_Bytes(255, 129, 25), new RGBA_Bytes(255, 157, 76), false)); - themeList.Add(new Theme("Purple - Light", new RGBA_Bytes(70, 23, 180), new RGBA_Bytes(104, 51, 229), false)); - themeList.Add(new Theme("Red - Light", new RGBA_Bytes(172, 25, 61), new RGBA_Bytes(217, 31, 77), false)); - themeList.Add(new Theme("Pink - Light", new RGBA_Bytes(220, 79, 173), new RGBA_Bytes(233, 143, 203), false)); - themeList.Add(new Theme("Grey - Light", new RGBA_Bytes(88, 88, 88), new RGBA_Bytes(114, 114, 114), false)); - themeList.Add(new Theme("Pink - Light", new RGBA_Bytes(140, 0, 149), new RGBA_Bytes(188, 0, 200), false)); - - return themeList; - } - - public bool IsTouchScreen - { - get - { - return UserSettings.Instance.get("ApplicationDisplayMode") == "touchscreen"; - } - } - } - - public class Theme - { - public RGBA_Bytes primaryAccentColor; - public RGBA_Bytes secondaryAccentColor; - public RGBA_Bytes primaryTextColor; - public RGBA_Bytes secondaryTextColor; - public RGBA_Bytes primaryBackgroundColor; - public RGBA_Bytes secondaryBackgroundColor; - public RGBA_Bytes tabLabelSelectedColor; - public RGBA_Bytes tabLabelUnselectedColor; - - public RGBA_Bytes tertiaryBackgroundColor; - public RGBA_Bytes tertiaryBackgroundColorDisabled; - - private string name; - - public string Name { get { return name; } } - - private bool darkTheme; - - public bool DarkTheme { get { return darkTheme; } } - - public Theme(string name, RGBA_Bytes primary, RGBA_Bytes secondary, bool darkTheme = true) - { - this.darkTheme = darkTheme; - this.name = name; - - if (darkTheme) - { - this.primaryAccentColor = primary; - this.secondaryAccentColor = secondary; - - this.primaryBackgroundColor = new RGBA_Bytes(68, 68, 68); - this.secondaryBackgroundColor = new RGBA_Bytes(51, 51, 51); - - this.tabLabelSelectedColor = new RGBA_Bytes(255, 255, 255); - this.tabLabelUnselectedColor = new RGBA_Bytes(180, 180, 180); - this.primaryTextColor = new RGBA_Bytes(255, 255, 255); - this.secondaryTextColor = new RGBA_Bytes(200, 200, 200); - - this.tertiaryBackgroundColor = new RGBA_Bytes(62, 62, 62); - } - else - { - this.primaryAccentColor = secondary; - this.secondaryAccentColor = primary; - - this.primaryBackgroundColor = new RGBA_Bytes(208, 208, 208); - this.secondaryBackgroundColor = new RGBA_Bytes(185, 185, 185); - this.tabLabelSelectedColor = new RGBA_Bytes(51, 51, 51); - this.tabLabelUnselectedColor = new RGBA_Bytes(102, 102, 102); - this.primaryTextColor = new RGBA_Bytes(34, 34, 34); - this.secondaryTextColor = new RGBA_Bytes(51, 51, 51); - - this.tertiaryBackgroundColor = new RGBA_Bytes(190, 190, 190); - } - } - } -} \ No newline at end of file diff --git a/CustomWidgets/LibrarySelector/FolderBreadCrumbWidget.cs b/CustomWidgets/LibrarySelector/FolderBreadCrumbWidget.cs index d7bb4400b..844ee76e1 100644 --- a/CustomWidgets/LibrarySelector/FolderBreadCrumbWidget.cs +++ b/CustomWidgets/LibrarySelector/FolderBreadCrumbWidget.cs @@ -119,7 +119,7 @@ namespace MatterHackers.MatterControl.CustomWidgets.LibrarySelector this.AddChild(separator); Button searchResultsButton = null; - if (ActiveTheme.Instance.IsTouchScreen) + if (UserSettings.Instance.IsTouchScreen) { searchResultsButton = navigationButtonFactory.Generate("Search Results".Localize(), "icon_search_32x32.png"); } diff --git a/CustomWidgets/LibrarySelector/LibrarySelectorWidget.cs b/CustomWidgets/LibrarySelector/LibrarySelectorWidget.cs index cf8c15bbc..644127446 100644 --- a/CustomWidgets/LibrarySelector/LibrarySelectorWidget.cs +++ b/CustomWidgets/LibrarySelector/LibrarySelectorWidget.cs @@ -333,7 +333,7 @@ namespace MatterHackers.MatterControl.CustomWidgets.LibrarySelector PrintItemCollection localPrintItemCollection = printItemCollection; clickThumbnail.Click += (sender, e) => { - if (ActiveTheme.Instance.IsTouchScreen) + if (UserSettings.Instance.IsTouchScreen) { if (parentProvider == null) { diff --git a/CustomWidgets/PartThumbnailWidget.cs b/CustomWidgets/PartThumbnailWidget.cs index 4de44fd80..1737a8bcc 100644 --- a/CustomWidgets/PartThumbnailWidget.cs +++ b/CustomWidgets/PartThumbnailWidget.cs @@ -126,7 +126,7 @@ namespace MatterHackers.MatterControl this.Click += DoOnMouseClick; this.MouseEnterBounds += onEnter; this.MouseLeaveBounds += onExit; - ActiveTheme.Instance.ThemeChanged.RegisterEvent(ThemeChanged, ref unregisterEvents); + ActiveTheme.ThemeChanged.RegisterEvent(ThemeChanged, ref unregisterEvents); } private void DoOnMouseClick(object sender, EventArgs e) diff --git a/CustomWidgets/PluginChooserWindow.cs b/CustomWidgets/PluginChooserWindow.cs index 53068959c..2cbea822b 100644 --- a/CustomWidgets/PluginChooserWindow.cs +++ b/CustomWidgets/PluginChooserWindow.cs @@ -69,7 +69,7 @@ namespace MatterHackers.MatterControl.CreatorPlugins protected void AddHandlers() { - ActiveTheme.Instance.ThemeChanged.RegisterEvent(ThemeChanged, ref unregisterEvents); + ActiveTheme.ThemeChanged.RegisterEvent(ThemeChanged, ref unregisterEvents); } public void ThemeChanged(object sender, EventArgs e) diff --git a/CustomWidgets/PrintProgressBarWidget.cs b/CustomWidgets/PrintProgressBarWidget.cs index e9495133d..f6716ee30 100644 --- a/CustomWidgets/PrintProgressBarWidget.cs +++ b/CustomWidgets/PrintProgressBarWidget.cs @@ -100,7 +100,7 @@ namespace MatterHackers.MatterControl AddChild(container); - if (ActiveTheme.Instance.IsTouchScreen) + if (UserSettings.Instance.IsTouchScreen) { upImageBuffer = StaticData.Instance.LoadIcon("TouchScreen/arrow_up_32x24.png"); downImageBuffer = StaticData.Instance.LoadIcon("TouchScreen/arrow_down_32x24.png"); @@ -133,7 +133,7 @@ namespace MatterHackers.MatterControl PrinterConnectionAndCommunication.Instance.ActivePrintItemChanged.RegisterEvent(Instance_PrintItemChanged, ref unregisterEvents); PrinterConnectionAndCommunication.Instance.CommunicationStateChanged.RegisterEvent(Instance_PrintItemChanged, ref unregisterEvents); - ActiveTheme.Instance.ThemeChanged.RegisterEvent(ThemeChanged, ref unregisterEvents); + ActiveTheme.ThemeChanged.RegisterEvent(ThemeChanged, ref unregisterEvents); SetThemedColors(); UpdatePrintStatus(); diff --git a/CustomWidgets/ThemeColorSelectorWidget.cs b/CustomWidgets/ThemeColorSelectorWidget.cs index 0fb027ceb..5a658173b 100644 --- a/CustomWidgets/ThemeColorSelectorWidget.cs +++ b/CustomWidgets/ThemeColorSelectorWidget.cs @@ -43,65 +43,61 @@ namespace MatterHackers.MatterControl { this.Padding = new BorderDouble(2, 0); this.colorToChangeTo = colorToChangeTo; - int themeCount = ActiveTheme.Instance.AvailableThemes.Count; + int themeCount = ActiveTheme.AvailableThemes.Count; + + var allThemes = ActiveTheme.AvailableThemes; int index = 0; for (int x = 0; x < themeCount / 2; x++) { - FlowLayoutWidget columnContainer = new FlowLayoutWidget(Agg.UI.FlowDirection.TopToBottom); - columnContainer.Width = containerHeight; + var columnContainer = new FlowLayoutWidget(Agg.UI.FlowDirection.TopToBottom) + { + Width = containerHeight + }; + columnContainer.AddChild(CreateThemeButton(allThemes[index], index)); - Button buttonOne = getThemeButton(index); - Button buttonTwo = getThemeButton(index + themeCount / 2); - - columnContainer.AddChild(buttonTwo); - columnContainer.AddChild(buttonOne); + int secondRowIndex = index + themeCount / 2; + columnContainer.AddChild(CreateThemeButton(allThemes[secondRowIndex], secondRowIndex)); this.AddChild(columnContainer); + index++; } this.BackgroundColor = RGBA_Bytes.White; this.Width = containerHeight * (themeCount / 2); } - public Button getThemeButton(int index) + public Button CreateThemeButton(IThemeColors theme, int index) { - GuiWidget normal = new GuiWidget(colorSelectSize, colorSelectSize); - normal.BackgroundColor = ActiveTheme.Instance.AvailableThemes[index].primaryAccentColor; - GuiWidget hover = new GuiWidget(colorSelectSize, colorSelectSize); - hover.BackgroundColor = ActiveTheme.Instance.AvailableThemes[index].secondaryAccentColor; - GuiWidget pressed = new GuiWidget(colorSelectSize, colorSelectSize); - pressed.BackgroundColor = ActiveTheme.Instance.AvailableThemes[index].secondaryAccentColor; - GuiWidget disabled = new GuiWidget(colorSelectSize, colorSelectSize); + var normal = new GuiWidget(colorSelectSize, colorSelectSize); + normal.BackgroundColor = theme.PrimaryAccentColor; - Button colorButton = new Button(0, 0, new ButtonViewStates(normal, hover, pressed, disabled)); - colorButton.Name = index.ToString(); - colorButton.Click += (sender, mouseEvent) => + var hover = new GuiWidget(colorSelectSize, colorSelectSize); + hover.BackgroundColor = theme.SecondaryAccentColor; + + var pressed = new GuiWidget(colorSelectSize, colorSelectSize); + pressed.BackgroundColor = theme.SecondaryAccentColor; + + var disabled = new GuiWidget(colorSelectSize, colorSelectSize); + + var colorButton = new Button(0, 0, new ButtonViewStates(normal, hover, pressed, disabled)); + colorButton.Click += (s, e) => { - string themeIndex = ((GuiWidget)sender).Name; - ActiveSliceSettings.Instance.SetActiveValue("MatterControl.ActiveThemeIndex", themeIndex); - ActiveTheme.Instance.LoadThemeSettings(int.Parse(themeIndex)); + UserSettings.Instance.set("ActiveThemeIndex", index.ToString()); + ActiveTheme.Instance = theme; }; - colorButton.MouseEnterBounds += (sender, mouseEvent) => + colorButton.MouseEnterBounds += (s, e) => { - colorToChangeTo.BackgroundColor = ActiveTheme.Instance.AvailableThemes[index].primaryAccentColor; + colorToChangeTo.BackgroundColor = theme.PrimaryAccentColor; }; - colorButton.MouseLeaveBounds += (sender, mouseEvent) => + colorButton.MouseLeaveBounds += (s, e) => { colorToChangeTo.BackgroundColor = ActiveTheme.Instance.PrimaryAccentColor; }; return colorButton; } - - public override void OnDraw(Graphics2D graphics2D) - { - base.OnDraw(graphics2D); - RectangleDouble border = LocalBounds; - border.Deflate(new BorderDouble(1)); - //graphics2D.Rectangle(border, ActiveTheme.Instance.SecondaryBackgroundColor, 4); - } } } \ No newline at end of file diff --git a/CustomWidgets/WizardControl.cs b/CustomWidgets/WizardControl.cs index 5f045b9de..3e0f1db92 100644 --- a/CustomWidgets/WizardControl.cs +++ b/CustomWidgets/WizardControl.cs @@ -50,7 +50,7 @@ namespace MatterHackers.MatterControl public WizardControl() { - if (ActiveTheme.Instance.IsTouchScreen) + if (UserSettings.Instance.IsTouchScreen) { extraTextScaling = 1.33333; } @@ -59,7 +59,7 @@ namespace MatterHackers.MatterControl FlowLayoutWidget topToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom); topToBottom.AnchorAll(); - if (ActiveTheme.Instance.IsTouchScreen) + if (UserSettings.Instance.IsTouchScreen) { topToBottom.Padding = new BorderDouble(12); } diff --git a/History/PrintHistoryListItem.cs b/History/PrintHistoryListItem.cs index cdc6f404b..9841bc712 100644 --- a/History/PrintHistoryListItem.cs +++ b/History/PrintHistoryListItem.cs @@ -304,7 +304,7 @@ namespace MatterHackers.MatterControl.PrintHistory private void AddHandlers() { - ActiveTheme.Instance.ThemeChanged.RegisterEvent(ThemeChanged, ref unregisterEvents); + ActiveTheme.ThemeChanged.RegisterEvent(ThemeChanged, ref unregisterEvents); MouseEnterBounds += new EventHandler(HistoryItem_MouseEnterBounds); MouseLeaveBounds += new EventHandler(HistoryItem_MouseLeaveBounds); } diff --git a/Library/LibraryDataView.cs b/Library/LibraryDataView.cs index dc23ec11f..bbd38073a 100644 --- a/Library/LibraryDataView.cs +++ b/Library/LibraryDataView.cs @@ -324,7 +324,7 @@ namespace MatterHackers.MatterControl.PrintLibrary clickThumbnail.Click += (sender, e) => { - if (ActiveTheme.Instance.IsTouchScreen) + if (UserSettings.Instance.IsTouchScreen) { if (parentProvider == null) { diff --git a/Library/LibraryRowItem.cs b/Library/LibraryRowItem.cs index 02db218c8..eca7600b1 100644 --- a/Library/LibraryRowItem.cs +++ b/Library/LibraryRowItem.cs @@ -333,7 +333,7 @@ namespace MatterHackers.MatterControl.PrintLibrary private void AddHandlers() { - //ActiveTheme.Instance.ThemeChanged.RegisterEvent(onThemeChanged, ref unregisterEvents); + //ActiveTheme.ThemeChanged.RegisterEvent(onThemeChanged, ref unregisterEvents); GestureFling += (object sender, FlingEventArgs eventArgs) => { if (!this.libraryDataView.EditMode) @@ -373,7 +373,7 @@ namespace MatterHackers.MatterControl.PrintLibrary { //this.VAnchor = Agg.UI.VAnchor.FitToChildren; this.HAnchor = Agg.UI.HAnchor.ParentLeftRight; - if (ActiveTheme.Instance.DisplayMode == ActiveTheme.ApplicationDisplayType.Touchscreen) + if (UserSettings.Instance.DisplayMode == ApplicationDisplayType.Touchscreen) { this.Height = 65; } diff --git a/Library/LibraryRowItemPart.cs b/Library/LibraryRowItemPart.cs index 5792c4755..62d314d3c 100644 --- a/Library/LibraryRowItemPart.cs +++ b/Library/LibraryRowItemPart.cs @@ -469,7 +469,7 @@ namespace MatterHackers.MatterControl.PrintLibrary { //this.VAnchor = Agg.UI.VAnchor.FitToChildren; this.HAnchor = Agg.UI.HAnchor.ParentLeftRight; - if (ActiveTheme.Instance.DisplayMode == ActiveTheme.ApplicationDisplayType.Touchscreen) + if (UserSettings.Instance.DisplayMode == ApplicationDisplayType.Touchscreen) { this.Height = 65; } diff --git a/MatterControl.csproj b/MatterControl.csproj index 5fc201c27..49fec4e8f 100644 --- a/MatterControl.csproj +++ b/MatterControl.csproj @@ -309,7 +309,6 @@ - diff --git a/MatterControlApplication.cs b/MatterControlApplication.cs index c5f120225..470617cbd 100644 --- a/MatterControlApplication.cs +++ b/MatterControlApplication.cs @@ -256,7 +256,7 @@ namespace MatterHackers.MatterControl GuiWidget.DefaultEnforceIntegerBounds = true; - if (ActiveTheme.Instance.DisplayMode == ActiveTheme.ApplicationDisplayType.Touchscreen) + if (UserSettings.Instance.DisplayMode == ApplicationDisplayType.Touchscreen) { GuiWidget.DeviceScale = 1.3; } @@ -394,6 +394,7 @@ namespace MatterHackers.MatterControl { if (instance == null) { + LoadUITheme(); instance = CreateInstance(); instance.ShowAsSystemWindow(); } @@ -402,6 +403,36 @@ namespace MatterHackers.MatterControl } } + public static void LoadUITheme() + { + //Load the default theme by index + if (string.IsNullOrEmpty(UserSettings.Instance.get("ActiveThemeIndex"))) + { + for (int i = 0; i < ActiveTheme.AvailableThemes.Count; i++) + { + IThemeColors current = ActiveTheme.AvailableThemes[i]; + if (current.Name == OemSettings.Instance.ThemeColor) + { + UserSettings.Instance.set("ActiveThemeIndex", i.ToString()); + break; + } + } + } + + int themeIndex; + if (int.TryParse(UserSettings.Instance.get("ActiveThemeIndex"), out themeIndex) && themeIndex < ActiveTheme.AvailableThemes.Count) + { + try + { + ActiveTheme.Instance = ActiveTheme.AvailableThemes[themeIndex]; + } + catch + { + GuiWidget.BreakInDebugger(); + } + } + } + public static MatterControlApplication CreateInstance() { // try and open our window matching the last size that we had for it. diff --git a/PartPreviewWindow/BaseClasses/PartPreview3DWidget.cs b/PartPreviewWindow/BaseClasses/PartPreview3DWidget.cs index fa3acfd68..2c9a5f98f 100644 --- a/PartPreviewWindow/BaseClasses/PartPreview3DWidget.cs +++ b/PartPreviewWindow/BaseClasses/PartPreview3DWidget.cs @@ -142,7 +142,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow protected static SolidSlider InsertUiForSlider(FlowLayoutWidget wordOptionContainer, string header, double min = 0, double max = .5) { double scrollBarWidth = 10; - if (ActiveTheme.Instance.DisplayMode == ActiveTheme.ApplicationDisplayType.Touchscreen) + if (UserSettings.Instance.DisplayMode == ApplicationDisplayType.Touchscreen) { scrollBarWidth = 20; } diff --git a/PartPreviewWindow/BaseClasses/PartPreviewWidget.cs b/PartPreviewWindow/BaseClasses/PartPreviewWidget.cs index be2d19aec..4d82001ae 100644 --- a/PartPreviewWindow/BaseClasses/PartPreviewWidget.cs +++ b/PartPreviewWindow/BaseClasses/PartPreviewWidget.cs @@ -49,7 +49,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow public PartPreviewWidget() { - if (ActiveTheme.Instance.DisplayMode == ActiveTheme.ApplicationDisplayType.Touchscreen) + if (UserSettings.Instance.DisplayMode == ApplicationDisplayType.Touchscreen) { SideBarButtonWidth = 180; ShortButtonHeight = 40; diff --git a/PartPreviewWindow/PartPreviewContent.cs b/PartPreviewWindow/PartPreviewContent.cs index 3e9df876d..e90c6d114 100644 --- a/PartPreviewWindow/PartPreviewContent.cs +++ b/PartPreviewWindow/PartPreviewContent.cs @@ -84,7 +84,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow tabControl.TabBar.Padding = new BorderDouble(top: 6); RGBA_Bytes selectedTabColor; - if (ActiveTheme.Instance.DisplayMode == ActiveTheme.ApplicationDisplayType.Responsive) + if (UserSettings.Instance.DisplayMode == ApplicationDisplayType.Responsive) { tabControl.TabBar.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor; selectedTabColor = ActiveTheme.Instance.TabLabelSelected; diff --git a/PartPreviewWindow/PartPreviewMainWindow.cs b/PartPreviewWindow/PartPreviewMainWindow.cs index 3b166ec9f..ac7e9a962 100644 --- a/PartPreviewWindow/PartPreviewMainWindow.cs +++ b/PartPreviewWindow/PartPreviewMainWindow.cs @@ -76,7 +76,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow private void AddHandlers() { - ActiveTheme.Instance.ThemeChanged.RegisterEvent(ThemeChanged, ref unregisterEvents); + ActiveTheme.ThemeChanged.RegisterEvent(ThemeChanged, ref unregisterEvents); } public void ThemeChanged(object sender, EventArgs e) diff --git a/PartPreviewWindow/SaveAsWindow.cs b/PartPreviewWindow/SaveAsWindow.cs index 2b120cbc1..b39f267ba 100644 --- a/PartPreviewWindow/SaveAsWindow.cs +++ b/PartPreviewWindow/SaveAsWindow.cs @@ -166,7 +166,7 @@ namespace MatterHackers.MatterControl if (firstDraw) { if (textToAddWidget != null - && !ActiveTheme.Instance.IsTouchScreen) + && !UserSettings.Instance.IsTouchScreen) { UiThread.RunOnIdle(textToAddWidget.Focus); } diff --git a/PartPreviewWindow/View3D/View3DWidget.cs b/PartPreviewWindow/View3D/View3DWidget.cs index 5bdbafc4b..15c95cc46 100644 --- a/PartPreviewWindow/View3D/View3DWidget.cs +++ b/PartPreviewWindow/View3D/View3DWidget.cs @@ -435,7 +435,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow } } - ActiveTheme.Instance.ThemeChanged.RegisterEvent(ThemeChanged, ref unregisterEvents); + ActiveTheme.ThemeChanged.RegisterEvent(ThemeChanged, ref unregisterEvents); meshViewerWidget.interactionVolumes.Add(new UpArrow3D(this)); meshViewerWidget.interactionVolumes.Add(new SelectionShadow(this)); @@ -1344,7 +1344,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow string renderTypeString = UserSettings.Instance.get("defaultRenderSetting"); if (renderTypeString == null) { - if (ActiveTheme.Instance.DisplayMode == ActiveTheme.ApplicationDisplayType.Touchscreen) + if (UserSettings.Instance.DisplayMode == ApplicationDisplayType.Touchscreen) { renderTypeString = "Shaded"; } @@ -1512,7 +1512,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow viewOptionContainer.AddChild(showBuildVolumeCheckBox); } - if (ActiveTheme.Instance.IsTouchScreen) + if (UserSettings.Instance.IsTouchScreen) { UserSettings.Instance.set("defaultRenderSetting", RenderTypes.Shaded.ToString()); } diff --git a/PartPreviewWindow/ViewControls2D.cs b/PartPreviewWindow/ViewControls2D.cs index b0c4ecfe7..17394b0a4 100644 --- a/PartPreviewWindow/ViewControls2D.cs +++ b/PartPreviewWindow/ViewControls2D.cs @@ -43,7 +43,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow public ViewControlsBase() { - if (ActiveTheme.Instance.DisplayMode == ActiveTheme.ApplicationDisplayType.Touchscreen) + if (UserSettings.Instance.DisplayMode == ApplicationDisplayType.Touchscreen) { buttonHeight = 40; } @@ -65,7 +65,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow public ViewControls2D() { - if (ActiveTheme.Instance.DisplayMode == ActiveTheme.ApplicationDisplayType.Touchscreen) + if (UserSettings.Instance.DisplayMode == ApplicationDisplayType.Touchscreen) { buttonHeight = 40; } @@ -137,7 +137,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow threeDimensionButton = iconTextImageButtonFactory.GenerateRadioButton("", select3dIconPath); threeDimensionButton.Margin = new BorderDouble(3); - if (ActiveTheme.Instance.DisplayMode != ActiveTheme.ApplicationDisplayType.Touchscreen) + if (UserSettings.Instance.DisplayMode != ApplicationDisplayType.Touchscreen) { AddChild(threeDimensionButton); diff --git a/PartPreviewWindow/ViewControls3D.cs b/PartPreviewWindow/ViewControls3D.cs index b7eed0017..dfb846bf8 100644 --- a/PartPreviewWindow/ViewControls3D.cs +++ b/PartPreviewWindow/ViewControls3D.cs @@ -113,7 +113,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow public ViewControls3D(MeshViewerWidget meshViewerWidget) { - if (ActiveTheme.Instance.DisplayMode == ActiveTheme.ApplicationDisplayType.Touchscreen) + if (UserSettings.Instance.DisplayMode == ApplicationDisplayType.Touchscreen) { buttonHeight = 40; } @@ -198,7 +198,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow SetMeshViewerDisplayTheme(); partSelectButton.CheckedStateChanged += SetMeshViewerDisplayTheme; - ActiveTheme.Instance.ThemeChanged.RegisterEvent(ThemeChanged, ref unregisterEvents); + ActiveTheme.ThemeChanged.RegisterEvent(ThemeChanged, ref unregisterEvents); } private event EventHandler unregisterEvents; diff --git a/PartPreviewWindow/ViewGcodeBasic.cs b/PartPreviewWindow/ViewGcodeBasic.cs index f0b8f222d..192980f27 100644 --- a/PartPreviewWindow/ViewGcodeBasic.cs +++ b/PartPreviewWindow/ViewGcodeBasic.cs @@ -98,7 +98,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow this.windowMode = windowMode; this.printItem = printItem; - if (ActiveTheme.Instance.DisplayMode == ActiveTheme.ApplicationDisplayType.Touchscreen) + if (UserSettings.Instance.DisplayMode == ApplicationDisplayType.Touchscreen) { sliderWidth = 20; } diff --git a/PrinterControls/ControlWidgets/AdjustmentControls.cs b/PrinterControls/ControlWidgets/AdjustmentControls.cs index 418b5a593..2d6417abc 100644 --- a/PrinterControls/ControlWidgets/AdjustmentControls.cs +++ b/PrinterControls/ControlWidgets/AdjustmentControls.cs @@ -72,7 +72,7 @@ namespace MatterHackers.MatterControl.PrinterControls double sliderWidth = 300 * GuiWidget.DeviceScale; double sliderThumbWidth = 10 * GuiWidget.DeviceScale; - if (ActiveTheme.Instance.DisplayMode == ActiveTheme.ApplicationDisplayType.Touchscreen) + if (UserSettings.Instance.DisplayMode == ApplicationDisplayType.Touchscreen) { sliderThumbWidth = 15 * GuiWidget.DeviceScale; } diff --git a/Queue/QueueDataWidget.cs b/Queue/QueueDataWidget.cs index dff7b73b1..ec722056d 100644 --- a/Queue/QueueDataWidget.cs +++ b/Queue/QueueDataWidget.cs @@ -196,7 +196,7 @@ namespace MatterHackers.MatterControl.PrintQueue }; } - bool touchScreenMode = ActiveTheme.Instance.IsTouchScreen; + bool touchScreenMode = UserSettings.Instance.IsTouchScreen; if (OemSettings.Instance.ShowShopButton) { @@ -704,7 +704,7 @@ namespace MatterHackers.MatterControl.PrintQueue { menuItems = new List(); - if (ActiveTheme.Instance.IsTouchScreen) + if (UserSettings.Instance.IsTouchScreen) { menuItems.Add(new PrintItemAction() { diff --git a/Queue/QueueRowItem.cs b/Queue/QueueRowItem.cs index 34679e170..ce94c86ac 100644 --- a/Queue/QueueRowItem.cs +++ b/Queue/QueueRowItem.cs @@ -389,7 +389,7 @@ namespace MatterHackers.MatterControl.PrintQueue private void AddHandlers() { - ActiveTheme.Instance.ThemeChanged.RegisterEvent(ThemeChanged, ref unregisterEvents); + ActiveTheme.ThemeChanged.RegisterEvent(ThemeChanged, ref unregisterEvents); PrintItemWrapper.SlicingOutputMessage += PrintItem_SlicingOutputMessage; } diff --git a/SettingsManagement/UserSettings.cs b/SettingsManagement/UserSettings.cs index c90ac2162..3d38c4c95 100644 --- a/SettingsManagement/UserSettings.cs +++ b/SettingsManagement/UserSettings.cs @@ -4,6 +4,8 @@ using System.Linq; namespace MatterHackers.MatterControl { + public enum ApplicationDisplayType { Responsive, Touchscreen }; + public class UserSettings { private static UserSettings globalInstance = null; @@ -89,5 +91,22 @@ namespace MatterHackers.MatterControl setting.Value = value; setting.Commit(); } + + public ApplicationDisplayType DisplayMode + { + get + { + if (this.get("ApplicationDisplayMode") == "touchscreen") + { + return ApplicationDisplayType.Touchscreen; + } + else + { + return ApplicationDisplayType.Responsive; + } + } + } + + public bool IsTouchScreen => this.get("ApplicationDisplayMode") == "touchscreen"; } } \ No newline at end of file diff --git a/SetupWizard/SetupWizardHome.cs b/SetupWizard/SetupWizardHome.cs index 8743366e9..33a0cd964 100644 --- a/SetupWizard/SetupWizardHome.cs +++ b/SetupWizard/SetupWizardHome.cs @@ -77,7 +77,7 @@ namespace MatterHackers.MatterControl mainContainer.AddChild(buttonContainer); - if (ActiveTheme.Instance.IsTouchScreen) + if (UserSettings.Instance.IsTouchScreen) { // the redeem design code button { diff --git a/SetupWizard/WizardPanel.cs b/SetupWizard/WizardPanel.cs index 0c9c13ccf..c131452ba 100644 --- a/SetupWizard/WizardPanel.cs +++ b/SetupWizard/WizardPanel.cs @@ -63,7 +63,7 @@ namespace MatterHackers.MatterControl this.AnchorAll(); - ActiveTheme.Instance.ThemeChanged.RegisterEvent(ThemeChanged, ref unregisterEvents); + ActiveTheme.ThemeChanged.RegisterEvent(ThemeChanged, ref unregisterEvents); cancelButton = textImageButtonFactory.Generate(unlocalizedTextForCancelButton.Localize()); cancelButton.Name = unlocalizedTextForCancelButton; diff --git a/SlicerConfiguration/Settings/ActiveSliceSettings.cs b/SlicerConfiguration/Settings/ActiveSliceSettings.cs index 467cdd58b..b4f97df69 100644 --- a/SlicerConfiguration/Settings/ActiveSliceSettings.cs +++ b/SlicerConfiguration/Settings/ActiveSliceSettings.cs @@ -75,7 +75,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration BedSettings.SetMakeAndModel(activeInstance.Make, activeInstance.Model); } - ActiveTheme.Instance.SwitchToPrinterThemeWithoutReloadEvent(); + SwitchToPrinterThemeWithoutReloadEvent(); if (!MatterControlApplication.IsLoading) { @@ -85,6 +85,29 @@ namespace MatterHackers.MatterControl.SlicerConfiguration } } + /// + /// Switches to the ActivePrinter theme without firing the ThemeChanged event. This is useful when changing printers and + /// allows the theme state to be updated before the ActivePrinterChanged event fires, resulting in a single ReloadAll + /// occurring rather than two + /// + public static void SwitchToPrinterThemeWithoutReloadEvent() + { + if (ActiveSliceSettings.Instance != null) + { + try + { + int themeIndex = Convert.ToInt32(ActiveSliceSettings.Instance.ActiveValue("MatterControl.ActiveThemeIndex")); + + ActiveTheme.SuspendEvents(); + ActiveTheme.Instance = ActiveTheme.AvailableThemes[themeIndex]; + ActiveTheme.ResumeEvents(); + } + catch + { + } + } + } + static ActiveSliceSettings() { // Ensure the profiles directory exists diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index 935cac90b..48146f626 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit 935cac90bbc3c426e4ddcdcb693c193284bca1de +Subproject commit 48146f6266d90835c98a10df1533650e78cf47c5