From 989634661067cb2cde00aee59dc91eb143a4e887 Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Fri, 9 Dec 2016 10:40:01 -0800 Subject: [PATCH] Get the starting color set correctly Made the android printer select window fix its colors on change --- ActionBar/PrinterSelector.cs | 1 - ApplicationView/MainApplicationWidget.cs | 40 +++++++++------- CustomWidgets/AltGroupBox.cs | 48 ++++++++++++------- SetupWizard/AndroidSetupOptionsPage.cs | 10 +++- SetupWizard/WizardWindow.cs | 22 ++++++++- .../Settings/ActiveSliceSettings.cs | 4 ++ StaticData/Translations/Master.txt | 3 ++ 7 files changed, 92 insertions(+), 36 deletions(-) diff --git a/ActionBar/PrinterSelector.cs b/ActionBar/PrinterSelector.cs index 3877750bd..e39a37a64 100644 --- a/ActionBar/PrinterSelector.cs +++ b/ActionBar/PrinterSelector.cs @@ -87,7 +87,6 @@ namespace MatterHackers.MatterControl // Rebuild the droplist any time the Profiles list changes ProfileManager.ProfilesListChanged.RegisterEvent((s, e) => Rebuild(), ref unregisterEvents); - ApplicationController.Instance.ReloadAllRequested.RegisterEvent((s, e) => Rebuild(), ref unregisterEvents); } public void Rebuild() diff --git a/ApplicationView/MainApplicationWidget.cs b/ApplicationView/MainApplicationWidget.cs index 009dc0599..cf5d72c94 100644 --- a/ApplicationView/MainApplicationWidget.cs +++ b/ApplicationView/MainApplicationWidget.cs @@ -68,7 +68,7 @@ namespace MatterHackers.MatterControl public abstract class ApplicationView : GuiWidget { - public abstract void AddElements(); + public abstract void CreateAndAddChildren(); } public class TouchscreenView : ApplicationView @@ -82,7 +82,7 @@ namespace MatterHackers.MatterControl public TouchscreenView() { - AddElements(); + CreateAndAddChildren(); this.AnchorAll(); } @@ -96,7 +96,7 @@ namespace MatterHackers.MatterControl this.TopContainer.Visible = !this.TopContainer.Visible; } - public override void AddElements() + public override void CreateAndAddChildren() { topIsHidden = false; this.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor; @@ -141,11 +141,11 @@ namespace MatterHackers.MatterControl public DesktopView() { - AddElements(); + CreateAndAddChildren(); this.AnchorAll(); } - public override void AddElements() + public override void CreateAndAddChildren() { this.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor; @@ -185,7 +185,6 @@ namespace MatterHackers.MatterControl private static ApplicationController globalInstance; public RootedObjectEventHandler AdvancedControlsPanelReloading = new RootedObjectEventHandler(); public RootedObjectEventHandler CloudSyncStatusChanged = new RootedObjectEventHandler(); - public RootedObjectEventHandler ReloadAllRequested = new RootedObjectEventHandler(); public RootedObjectEventHandler DoneReloadingAll = new RootedObjectEventHandler(); public RootedObjectEventHandler PluginsLoaded = new RootedObjectEventHandler(); @@ -400,17 +399,14 @@ namespace MatterHackers.MatterControl && MainView != null) { pendingReloadRequest = true; - MainView.AfterDraw += DoReloadAll; - MainView.Invalidate(); + DoReloadAll(); } - - ReloadAllRequested?.CallEvents(null, null); } static int reloadCount = 0; - private void DoReloadAll(GuiWidget drawingWidget, DrawEventArgs e) + private void DoReloadAll() { - UiThread.RunOnIdle(() => + UiThread.RunOnIdle((Action)(() => { if (MainView != null) { @@ -422,16 +418,15 @@ namespace MatterHackers.MatterControl MainView?.CloseAllChildren(); using (new QuickTimer("ReloadAll_AddElements")) { - MainView?.AddElements(); + MainView?.CreateAndAddChildren(); } PopOutManager.SaveIfClosed = true; - DoneReloadingAll?.CallEvents(null, null); + this.DoneReloadingAll?.CallEvents((object)null, (EventArgs)null); } - MainView.AfterDraw -= DoReloadAll; pendingReloadRequest = false; } - }); + })); } public void OnApplicationClosed() @@ -441,6 +436,19 @@ namespace MatterHackers.MatterControl static void LoadUITheme() { + // if the user setting has a theme color assume it is correct and use it right away + if (UserSettings.Instance != null) + { + var themeName = UserSettings.Instance.get(UserSettingsKey.ActiveThemeName); + if (!string.IsNullOrEmpty(themeName)) + { + ActiveTheme.Instance = ActiveTheme.GetThemeColors(themeName); + return; + } + } + + // if not check for the oem color and use it if set + // else default to "Blue - Light" string oemColor = OemSettings.Instance.ThemeColor; if (string.IsNullOrEmpty(oemColor)) { diff --git a/CustomWidgets/AltGroupBox.cs b/CustomWidgets/AltGroupBox.cs index 07bf728ff..a9ac6945f 100644 --- a/CustomWidgets/AltGroupBox.cs +++ b/CustomWidgets/AltGroupBox.cs @@ -1,5 +1,35 @@ -using MatterHackers.Agg; +/* +Copyright (c) 2016, Lars Brubaker +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 MatterHackers.Agg; using MatterHackers.Agg.UI; +using MatterHackers.MatterControl.CustomWidgets; namespace MatterHackers.MatterControl { @@ -104,21 +134,5 @@ namespace MatterHackers.MatterControl } } } - - public override void OnDraw(Graphics2D graphics2D) - { - RectangleDouble localBounds = LocalBounds; - //// bottom - //graphics2D.Line(localBounds.Left + lineInset, localBounds.Bottom + lineInset, localBounds.Left + Width - lineInset, localBounds.Bottom + lineInset, this.borderColor); - //// left - //graphics2D.Line(localBounds.Left + lineInset, localBounds.Bottom + lineInset, localBounds.Left + lineInset, localBounds.Bottom + Height - lineInset, this.borderColor); - //// right - //graphics2D.Line(localBounds.Left + Width - lineInset, localBounds.Bottom + lineInset, localBounds.Left + Width - lineInset, localBounds.Bottom + Height - lineInset, this.borderColor); - //// top - //graphics2D.Line(localBounds.Left + lineInset, localBounds.Bottom + Height - lineInset, groupBoxLabel.BoundsRelativeToParent.Left - 2, localBounds.Bottom + Height - lineInset, this.borderColor); - //graphics2D.Line(groupBoxLabel.BoundsRelativeToParent.Right + 2, localBounds.Bottom + Height - lineInset, localBounds.Left + Width - lineInset, localBounds.Bottom + Height - lineInset, this.borderColor); - - base.OnDraw(graphics2D); - } } } \ No newline at end of file diff --git a/SetupWizard/AndroidSetupOptionsPage.cs b/SetupWizard/AndroidSetupOptionsPage.cs index 4f35575d0..a68c5497c 100644 --- a/SetupWizard/AndroidSetupOptionsPage.cs +++ b/SetupWizard/AndroidSetupOptionsPage.cs @@ -39,6 +39,8 @@ namespace MatterHackers.MatterControl { public class SetupOptionsPage : WizardPage { + private event EventHandler unregisterEvents; + public SetupOptionsPage() : base("Done") { @@ -127,6 +129,12 @@ namespace MatterHackers.MatterControl this.Invalidate(); } + + public override void OnClosed(EventArgs e) + { + unregisterEvents?.Invoke(this, null); + base.OnClosed(e); + } } public class SetupAccountView : SetupViewBase @@ -248,7 +256,7 @@ namespace MatterHackers.MatterControl mainContainer.AddChild(buttonContainer); - ApplicationController.Instance.ReloadAllRequested.RegisterEvent(RemoveAndNewControl, ref unregisterEvents); + ApplicationController.Instance.DoneReloadingAll.RegisterEvent(RemoveAndNewControl, ref unregisterEvents); } private void RemoveAndNewControl(object sender, EventArgs e) diff --git a/SetupWizard/WizardWindow.cs b/SetupWizard/WizardWindow.cs index 631407e98..388c1e41b 100644 --- a/SetupWizard/WizardWindow.cs +++ b/SetupWizard/WizardWindow.cs @@ -14,6 +14,7 @@ namespace MatterHackers.MatterControl { public class WizardWindow : SystemWindow { + private event EventHandler unregisterEvents; public static Func ShouldShowAuthPanel { get; set; } public static Action ShowAuthDialog; public static Action ChangeToAccountCreate; @@ -114,6 +115,7 @@ namespace MatterHackers.MatterControl public override void OnClosed(EventArgs e) { + unregisterEvents?.Invoke(this, null); base.OnClosed(e); } @@ -173,7 +175,25 @@ namespace MatterHackers.MatterControl internal void ChangeToPage() where PanelType : WizardPage, new() { - ChangeToPage(new PanelType()); + PanelType panel = new PanelType(); + ChangeToPage(panel); + + // in the event of a reload all make sure we rebuild the contents correctly + ApplicationController.Instance.DoneReloadingAll.RegisterEvent((s,e) => + { + // fix the main window background color if needed + BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor; + + // find out where the contents we put in last time are + int thisIndex = GetChildIndex(panel); + RemoveChild(panel); + // make new content with the possibly changed theme + PanelType newPanel = new PanelType(); + AddChild(newPanel, thisIndex); + panel.CloseOnIdle(); + // remember the new content + panel = newPanel; + }, ref unregisterEvents); } } } \ No newline at end of file diff --git a/SlicerConfiguration/Settings/ActiveSliceSettings.cs b/SlicerConfiguration/Settings/ActiveSliceSettings.cs index e408317e9..2992ea226 100644 --- a/SlicerConfiguration/Settings/ActiveSliceSettings.cs +++ b/SlicerConfiguration/Settings/ActiveSliceSettings.cs @@ -143,6 +143,10 @@ namespace MatterHackers.MatterControl.SlicerConfiguration ActiveTheme.SuspendEvents(); } ActiveTheme.Instance = ActiveTheme.GetThemeColors(activeThemeName); + + // Save the theme so we can load it first thing on startup before a profile is loaded. + UserSettings.Instance.set(UserSettingsKey.ActiveThemeName, ActiveTheme.Instance.Name); + ActiveTheme.ResumeEvents(); } } diff --git a/StaticData/Translations/Master.txt b/StaticData/Translations/Master.txt index 63f91f2ae..339d0fbdc 100644 --- a/StaticData/Translations/Master.txt +++ b/StaticData/Translations/Master.txt @@ -5650,3 +5650,6 @@ Translated:Actions English:Show In Action Menu Translated:Show In Action Menu +English:Unable to Connect +Translated:Unable to Connect +