From ab7a5c5292ff9e5ea43ff22b8ec723ad0dc50aac Mon Sep 17 00:00:00 2001 From: John Lewin Date: Sat, 29 Sep 2018 15:03:54 -0700 Subject: [PATCH 1/9] Move MatterControl settings to dedicated DialogPage --- MatterControlLib/AboutPage/AboutPage.cs | 8 - .../ApplicationSettingsView.cs | 236 +--------- .../ApplicationSettingsPage.cs | 405 ++++++++++++++++++ 3 files changed, 407 insertions(+), 242 deletions(-) create mode 100644 MatterControlLib/SettingsManagement/ApplicationSettingsPage.cs diff --git a/MatterControlLib/AboutPage/AboutPage.cs b/MatterControlLib/AboutPage/AboutPage.cs index 1f8294a2d..6cd544845 100644 --- a/MatterControlLib/AboutPage/AboutPage.cs +++ b/MatterControlLib/AboutPage/AboutPage.cs @@ -190,14 +190,6 @@ namespace MatterHackers.MatterControl ApplicationController.Instance.LaunchBrowser("http://www.matterhackers.com"); }); contentRow.AddChild(siteLink); - - var clearCacheLink = theme.CreateDialogButton("Clear Cache".Localize()); - clearCacheLink.Click += (s, e) => UiThread.RunOnIdle(() => - { - CacheDirectory.DeleteCacheData(); - }); - - this.AddPageAction(clearCacheLink, highlightFirstAction: false); } private class LazyLicenseText : GuiWidget diff --git a/MatterControlLib/ConfigurationPage/ApplicationSettings/ApplicationSettingsView.cs b/MatterControlLib/ConfigurationPage/ApplicationSettings/ApplicationSettingsView.cs index 8f34d8fde..2c4153231 100644 --- a/MatterControlLib/ConfigurationPage/ApplicationSettings/ApplicationSettingsView.cs +++ b/MatterControlLib/ConfigurationPage/ApplicationSettings/ApplicationSettingsView.cs @@ -43,7 +43,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage { public class ApplicationSettingsWidget : FlowLayoutWidget, IIgnoredPopupChild { - public static Action OpenPrintNotification = null; + public static Action OpenPrintNotification = null; private ThemeConfig theme; @@ -55,246 +55,14 @@ namespace MatterHackers.MatterControl.ConfigurationPage this.BackgroundColor = theme.Colors.PrimaryBackgroundColor; this.theme = theme; - var configureIcon = AggContext.StaticData.LoadIcon("fa-cog_16.png", 16, 16, theme.InvertIcons); - -#if __ANDROID__ - // Camera Monitoring - bool hasCamera = true || ApplicationSettings.Instance.get(ApplicationSettingsKey.HardwareHasCamera) == "true"; - - var previewButton = new IconButton(configureIcon, theme) - { - ToolTipText = "Configure Camera View".Localize() - }; - previewButton.Click += (s, e) => - { - AppContext.Platform.OpenCameraPreview(); - }; - - this.AddSettingsRow( - new SettingsItem( - "Camera Monitoring".Localize(), - theme, - new SettingsItem.ToggleSwitchConfig() - { - Checked = ActiveSliceSettings.Instance.GetValue(SettingsKey.publish_bed_image), - ToggleAction = (itemChecked) => - { - ActiveSliceSettings.Instance.SetValue(SettingsKey.publish_bed_image, itemChecked ? "1" : "0"); - } - }, - previewButton, - AggContext.StaticData.LoadIcon("camera-24x24.png", 24, 24)) - ); -#endif - - // Print Notifications - var configureNotificationsButton = new IconButton(configureIcon, theme) - { - Name = "Configure Notification Settings Button", - ToolTipText = "Configure Notifications".Localize(), - Margin = new BorderDouble(left: 6), - VAnchor = VAnchor.Center - }; - configureNotificationsButton.Click += (s, e) => - { - if (OpenPrintNotification != null) - { - UiThread.RunOnIdle(OpenPrintNotification); - } - }; - AddMenuItem("Help".Localize(), ApplicationController.Instance.ShowApplicationHelp); - this.AddSettingsRow( - new SettingsItem( - "Notifications".Localize(), - theme, - new SettingsItem.ToggleSwitchConfig() - { - Checked = UserSettings.Instance.get(UserSettingsKey.PrintNotificationsEnabled) == "true", - ToggleAction = (itemChecked) => - { - UserSettings.Instance.set(UserSettingsKey.PrintNotificationsEnabled, itemChecked ? "true" : "false"); - } - }, - configureNotificationsButton, - AggContext.StaticData.LoadIcon("notify-24x24.png"))); - - // Touch Screen Mode - this.AddSettingsRow( - new SettingsItem( - "Touch Screen Mode".Localize(), - theme, - new SettingsItem.ToggleSwitchConfig() - { - Checked = UserSettings.Instance.get(UserSettingsKey.ApplicationDisplayMode) == "touchscreen", - ToggleAction = (itemChecked) => - { - string displayMode = itemChecked ? "touchscreen" : "responsive"; - if (displayMode != UserSettings.Instance.get(UserSettingsKey.ApplicationDisplayMode)) - { - UserSettings.Instance.set(UserSettingsKey.ApplicationDisplayMode, displayMode); - ApplicationController.Instance.ReloadAll(); - } - } - })); - - // LanguageControl - var languageSelector = new LanguageSelector(theme); - languageSelector.SelectionChanged += (s, e) => - { - UiThread.RunOnIdle(() => - { - string languageCode = languageSelector.SelectedValue; - if (languageCode != UserSettings.Instance.get(UserSettingsKey.Language)) - { - UserSettings.Instance.set(UserSettingsKey.Language, languageCode); - - if (languageCode == "L10N") - { -#if DEBUG - AppContext.Platform.GenerateLocalizationValidationFile(); -#endif - } - - ApplicationController.Instance.ResetTranslationMap(); - ApplicationController.Instance.ReloadAll(); - } - }); - }; - - this.AddSettingsRow(new SettingsItem("Language".Localize(), languageSelector, theme)); - -#if !__ANDROID__ - // ThumbnailRendering - var thumbnailsModeDropList = new DropDownList("", theme.Colors.PrimaryTextColor, maxHeight: 200, pointSize: theme.DefaultFontSize) - { - BorderColor = theme.GetBorderColor(75) - }; - thumbnailsModeDropList.AddItem("Flat".Localize(), "orthographic"); - thumbnailsModeDropList.AddItem("3D".Localize(), "raytraced"); - - thumbnailsModeDropList.SelectedValue = UserSettings.Instance.ThumbnailRenderingMode; - thumbnailsModeDropList.SelectionChanged += (s, e) => - { - string thumbnailRenderingMode = thumbnailsModeDropList.SelectedValue; - if (thumbnailRenderingMode != UserSettings.Instance.ThumbnailRenderingMode) - { - UserSettings.Instance.ThumbnailRenderingMode = thumbnailRenderingMode; - - UiThread.RunOnIdle(() => - { - // Ask if the user they would like to rebuild their thumbnails - StyledMessageBox.ShowMessageBox( - (bool rebuildThumbnails) => - { - if (rebuildThumbnails) - { - string[] thumbnails = new string[] - { - ApplicationController.CacheablePath( - Path.Combine("Thumbnails", "Content"), ""), - ApplicationController.CacheablePath( - Path.Combine("Thumbnails", "Library"), "") - }; - foreach (var directoryToRemove in thumbnails) - { - try - { - if (Directory.Exists(directoryToRemove)) - { - Directory.Delete(directoryToRemove, true); - } - } - catch (Exception) - { - GuiWidget.BreakInDebugger(); - } - - Directory.CreateDirectory(directoryToRemove); - } - - ApplicationController.Instance.Library.NotifyContainerChanged(); - } - }, - "You are switching to a different thumbnail rendering mode. If you want, your current thumbnails can be removed and recreated in the new style. You can switch back and forth at any time. There will be some processing overhead while the new thumbnails are created.\n\nDo you want to rebuild your existing thumbnails now?".Localize(), - "Rebuild Thumbnails Now".Localize(), - StyledMessageBox.MessageType.YES_NO, - "Rebuild".Localize()); - }); - } - }; - - this.AddSettingsRow( - new SettingsItem( - "Thumbnails".Localize(), - thumbnailsModeDropList, - theme)); -#endif - - // TextSize - if (!double.TryParse(UserSettings.Instance.get(UserSettingsKey.ApplicationTextSize), out double currentTextSize)) - { - currentTextSize = 1.0; - } - - double sliderThumbWidth = 10 * GuiWidget.DeviceScale; - double sliderWidth = 100 * GuiWidget.DeviceScale; - var textSizeSlider = new SolidSlider(new Vector2(), sliderThumbWidth, .7, 1.4) - { - Name = "Text Size Slider", - Margin = new BorderDouble(5, 0), - Value = currentTextSize, - HAnchor = HAnchor.Stretch, - VAnchor = VAnchor.Center, - TotalWidthInPixels = sliderWidth, - }; - - var optionalContainer = new FlowLayoutWidget() - { - VAnchor = VAnchor.Center | VAnchor.Fit, - HAnchor = HAnchor.Fit - }; - - TextWidget sectionLabel = null; - - var textSizeApplyButton = new TextButton("Apply".Localize(), theme) - { - VAnchor = VAnchor.Center, - BackgroundColor = theme.SlightShade, - Visible = false, - Margin = new BorderDouble(right: 6) - }; - textSizeApplyButton.Click += (s, e) => - { - GuiWidget.DeviceScale = textSizeSlider.Value; - ApplicationController.Instance.ReloadAll(); - }; - optionalContainer.AddChild(textSizeApplyButton); - - textSizeSlider.ValueChanged += (s, e) => - { - double textSizeNew = textSizeSlider.Value; - UserSettings.Instance.set(UserSettingsKey.ApplicationTextSize, textSizeNew.ToString("0.0")); - sectionLabel.Text = "Text Size".Localize() + $" : {textSizeNew:0.0}"; - textSizeApplyButton.Visible = textSizeNew != currentTextSize; - }; - - var section = new SettingsItem( - "Text Size".Localize() + $" : {currentTextSize:0.0}", - textSizeSlider, - theme, - optionalContainer); - - sectionLabel = section.Children().FirstOrDefault(); - - this.AddSettingsRow(section); - AddMenuItem("Forums".Localize(), () => ApplicationController.Instance.LaunchBrowser("https://forums.matterhackers.com/category/20/mattercontrol")); AddMenuItem("Wiki".Localize(), () => ApplicationController.Instance.LaunchBrowser("http://wiki.mattercontrol.com")); AddMenuItem("Guides and Articles".Localize(), () => ApplicationController.Instance.LaunchBrowser("http://www.matterhackers.com/topic/mattercontrol")); AddMenuItem("Release Notes".Localize(), () => ApplicationController.Instance.LaunchBrowser("http://wiki.mattercontrol.com/Release_Notes")); AddMenuItem("Report a Bug".Localize(), () => ApplicationController.Instance.LaunchBrowser("https://github.com/MatterHackers/MatterControl/issues")); + AddMenuItem("Settings".Localize(), () => DialogWindow.Show()); var updateMatterControl = new SettingsItem("Check For Update".Localize(), theme); updateMatterControl.Click += (s, e) => diff --git a/MatterControlLib/SettingsManagement/ApplicationSettingsPage.cs b/MatterControlLib/SettingsManagement/ApplicationSettingsPage.cs new file mode 100644 index 000000000..f293bc5c0 --- /dev/null +++ b/MatterControlLib/SettingsManagement/ApplicationSettingsPage.cs @@ -0,0 +1,405 @@ +/* +Copyright (c) 2018, John Lewin +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; +using System.IO; +using System.Linq; +using MatterHackers.Agg; +using MatterHackers.Agg.Image; +using MatterHackers.Agg.Platform; +using MatterHackers.Agg.UI; +using MatterHackers.Localizations; +using MatterHackers.MatterControl.ConfigurationPage; +using MatterHackers.MatterControl.CustomWidgets; +using MatterHackers.MatterControl.DataStorage; +using MatterHackers.MatterControl.SlicerConfiguration; +using MatterHackers.VectorMath; + +namespace MatterHackers.MatterControl +{ + public partial class ApplicationSettingsPage : DialogPage + { + public ApplicationSettingsPage() + { + this.AlwaysOnTopOfMain = true; + this.WindowTitle = this.HeaderText = "MatterControl " + "Settings".Localize(); + this.WindowSize = new Vector2(500 * GuiWidget.DeviceScale, 500 * GuiWidget.DeviceScale); + + contentRow.Padding = contentRow.Padding.Clone(top: 0); + + var generalPanel = new FlowLayoutWidget(FlowDirection.TopToBottom) + { + HAnchor = HAnchor.Stretch, + VAnchor = VAnchor.Fit, + }; + contentRow.AddChild(generalPanel); + + var configureIcon = AggContext.StaticData.LoadIcon("fa-cog_16.png", 16, 16, theme.InvertIcons); + +#if __ANDROID__ + // Camera Monitoring + bool hasCamera = true || ApplicationSettings.Instance.get(ApplicationSettingsKey.HardwareHasCamera) == "true"; + + var previewButton = new IconButton(configureIcon, theme) + { + ToolTipText = "Configure Camera View".Localize() + }; + previewButton.Click += (s, e) => + { + AppContext.Platform.OpenCameraPreview(); + }; + + this.AddSettingsRow( + new SettingsItem( + "Camera Monitoring".Localize(), + theme, + new SettingsItem.ToggleSwitchConfig() + { + Checked = ActiveSliceSettings.Instance.GetValue(SettingsKey.publish_bed_image), + ToggleAction = (itemChecked) => + { + ActiveSliceSettings.Instance.SetValue(SettingsKey.publish_bed_image, itemChecked ? "1" : "0"); + } + }, + previewButton, + AggContext.StaticData.LoadIcon("camera-24x24.png", 24, 24)) + ); +#endif + // Print Notifications + var configureNotificationsButton = new IconButton(configureIcon, theme) + { + Name = "Configure Notification Settings Button", + ToolTipText = "Configure Notifications".Localize(), + Margin = new BorderDouble(left: 6), + VAnchor = VAnchor.Center + }; + configureNotificationsButton.Click += (s, e) => + { + if (ApplicationSettingsWidget.OpenPrintNotification != null) + { + UiThread.RunOnIdle(() => + { + ApplicationSettingsWidget.OpenPrintNotification(this.DialogWindow); + }); + } + }; + + this.AddSettingsRow( + new SettingsItem( + "Notifications".Localize(), + theme, + new SettingsItem.ToggleSwitchConfig() + { + Checked = UserSettings.Instance.get(UserSettingsKey.PrintNotificationsEnabled) == "true", + ToggleAction = (itemChecked) => + { + UserSettings.Instance.set(UserSettingsKey.PrintNotificationsEnabled, itemChecked ? "true" : "false"); + } + }, + configureNotificationsButton, + AggContext.StaticData.LoadIcon("notify-24x24.png")), + generalPanel); + + // LanguageControl + var languageSelector = new LanguageSelector(theme); + languageSelector.SelectionChanged += (s, e) => + { + UiThread.RunOnIdle(() => + { + string languageCode = languageSelector.SelectedValue; + if (languageCode != UserSettings.Instance.get(UserSettingsKey.Language)) + { + UserSettings.Instance.set(UserSettingsKey.Language, languageCode); + + if (languageCode == "L10N") + { +#if DEBUG + AppContext.Platform.GenerateLocalizationValidationFile(); +#endif + } + + ApplicationController.Instance.ResetTranslationMap(); + ApplicationController.Instance.ReloadAll(); + } + }); + }; + + this.AddSettingsRow(new SettingsItem("Language".Localize(), languageSelector, theme), generalPanel); + +#if !__ANDROID__ + // ThumbnailRendering + var thumbnailsModeDropList = new DropDownList("", theme.Colors.PrimaryTextColor, maxHeight: 200, pointSize: theme.DefaultFontSize) + { + BorderColor = theme.GetBorderColor(75) + }; + thumbnailsModeDropList.AddItem("Flat".Localize(), "orthographic"); + thumbnailsModeDropList.AddItem("3D".Localize(), "raytraced"); + + thumbnailsModeDropList.SelectedValue = UserSettings.Instance.ThumbnailRenderingMode; + thumbnailsModeDropList.SelectionChanged += (s, e) => + { + string thumbnailRenderingMode = thumbnailsModeDropList.SelectedValue; + if (thumbnailRenderingMode != UserSettings.Instance.ThumbnailRenderingMode) + { + UserSettings.Instance.ThumbnailRenderingMode = thumbnailRenderingMode; + + UiThread.RunOnIdle(() => + { + // Ask if the user they would like to rebuild their thumbnails + StyledMessageBox.ShowMessageBox( + (bool rebuildThumbnails) => + { + if (rebuildThumbnails) + { + string[] thumbnails = new string[] + { + ApplicationController.CacheablePath( + Path.Combine("Thumbnails", "Content"), ""), + ApplicationController.CacheablePath( + Path.Combine("Thumbnails", "Library"), "") + }; + foreach (var directoryToRemove in thumbnails) + { + try + { + if (Directory.Exists(directoryToRemove)) + { + Directory.Delete(directoryToRemove, true); + } + } + catch (Exception) + { + GuiWidget.BreakInDebugger(); + } + + Directory.CreateDirectory(directoryToRemove); + } + + ApplicationController.Instance.Library.NotifyContainerChanged(); + } + }, + "You are switching to a different thumbnail rendering mode. If you want, your current thumbnails can be removed and recreated in the new style. You can switch back and forth at any time. There will be some processing overhead while the new thumbnails are created.\n\nDo you want to rebuild your existing thumbnails now?".Localize(), + "Rebuild Thumbnails Now".Localize(), + StyledMessageBox.MessageType.YES_NO, + "Rebuild".Localize()); + }); + } + }; + + this.AddSettingsRow( + new SettingsItem( + "Thumbnails".Localize(), + thumbnailsModeDropList, + theme), + generalPanel); +#endif + + // TextSize + if (!double.TryParse(UserSettings.Instance.get(UserSettingsKey.ApplicationTextSize), out double currentTextSize)) + { + currentTextSize = 1.0; + } + + double sliderThumbWidth = 10 * GuiWidget.DeviceScale; + double sliderWidth = 100 * GuiWidget.DeviceScale; + var textSizeSlider = new SolidSlider(new Vector2(), sliderThumbWidth, .7, 1.4) + { + Name = "Text Size Slider", + Margin = new BorderDouble(5, 0), + Value = currentTextSize, + HAnchor = HAnchor.Stretch, + VAnchor = VAnchor.Center, + TotalWidthInPixels = sliderWidth, + }; + + var optionalContainer = new FlowLayoutWidget() + { + VAnchor = VAnchor.Center | VAnchor.Fit, + HAnchor = HAnchor.Fit + }; + + TextWidget sectionLabel = null; + + var textSizeApplyButton = new TextButton("Apply".Localize(), theme) + { + VAnchor = VAnchor.Center, + BackgroundColor = theme.SlightShade, + Visible = false, + Margin = new BorderDouble(right: 6) + }; + textSizeApplyButton.Click += (s, e) => + { + GuiWidget.DeviceScale = textSizeSlider.Value; + ApplicationController.Instance.ReloadAll(); + }; + optionalContainer.AddChild(textSizeApplyButton); + + textSizeSlider.ValueChanged += (s, e) => + { + double textSizeNew = textSizeSlider.Value; + UserSettings.Instance.set(UserSettingsKey.ApplicationTextSize, textSizeNew.ToString("0.0")); + sectionLabel.Text = "Text Size".Localize() + $" : {textSizeNew:0.0}"; + textSizeApplyButton.Visible = textSizeNew != currentTextSize; + }; + + var section = new SettingsItem( + "Text Size".Localize() + $" : {currentTextSize:0.0}", + textSizeSlider, + theme, + optionalContainer); + + sectionLabel = section.Children().FirstOrDefault(); + + this.AddSettingsRow(section, generalPanel); + + var advancedPanel = new FlowLayoutWidget(FlowDirection.TopToBottom) + { + Margin = new BorderDouble(2, 0) + }; + + var sectionWidget = new SectionWidget("Advanced", advancedPanel, theme, serializationKey: "ApplicationSettings-Advanced", expanded: false) + { + Name = "Advanced Section", + HAnchor = HAnchor.Stretch, + VAnchor = VAnchor.Fit, + Margin = 0 + }; + contentRow.AddChild(sectionWidget); + + theme.ApplyBoxStyle(sectionWidget); + + sectionWidget.Margin = new BorderDouble(0, 10); + + // Touch Screen Mode + this.AddSettingsRow( + new SettingsItem( + "Touch Screen Mode".Localize(), + theme, + new SettingsItem.ToggleSwitchConfig() + { + Checked = UserSettings.Instance.get(UserSettingsKey.ApplicationDisplayMode) == "touchscreen", + ToggleAction = (itemChecked) => + { + string displayMode = itemChecked ? "touchscreen" : "responsive"; + if (displayMode != UserSettings.Instance.get(UserSettingsKey.ApplicationDisplayMode)) + { + UserSettings.Instance.set(UserSettingsKey.ApplicationDisplayMode, displayMode); + ApplicationController.Instance.ReloadAll(); + } + } + }), + advancedPanel); + + var openCacheButton = new IconButton(AggContext.StaticData.LoadIcon("fa-link_16.png", 16, 16, theme.InvertIcons), theme) + { + ToolTipText = "Open Folder".Localize(), + }; + openCacheButton.Click += (s, e) => UiThread.RunOnIdle(() => + { + Process.Start(ApplicationDataStorage.ApplicationUserDataPath); + }); + + this.AddSettingsRow( + new SettingsItem( + "Application Storage".Localize(), + openCacheButton, + theme), + advancedPanel); + + var removeHoveredIcon = AggContext.StaticData.LoadIcon("remove.png", 16, 16, theme.InvertIcons); + var removeNormalIcon = new ImageBuffer(removeHoveredIcon); + + //removeNormalIcon.NewGraphics2D().Render(removeHoveredIcon.ToGrayscale(), 0, 0); + ToGrayscale(removeNormalIcon); + + var clearCacheButton = new IconButton(removeNormalIcon, removeHoveredIcon, theme) + { + ToolTipText = "Clear Cache".Localize(), + }; + clearCacheButton.Click += (s, e) => UiThread.RunOnIdle(() => + { + CacheDirectory.DeleteCacheData(); + }); + + this.AddSettingsRow( + new SettingsItem( + "Application Cache".Localize(), + clearCacheButton, + theme), + advancedPanel); + + advancedPanel.Children().First().Border = new BorderDouble(0, 1); + } + + private static void ToGrayscale(ImageBuffer sourceImage) + { + var buffer = sourceImage.GetBuffer(); + int destIndex = 0; + for (int y = 0; y < sourceImage.Height; y++) + { + for (int x = 0; x < sourceImage.Width; x++) + { + int b = buffer[destIndex + 0]; + int g = buffer[destIndex + 1]; + int r = buffer[destIndex + 2]; + + int c = (r * 77) + (g * 151) + (b * 28); + byte gray = (byte)(c >> 8); + + buffer[destIndex + 0] = gray; + buffer[destIndex + 1] = gray; + buffer[destIndex + 2] = gray; + + destIndex += 4; + } + } + } + + private void AddSettingsRow(GuiWidget widget, GuiWidget container) + { + container.AddChild(widget); + widget.Padding = widget.Padding.Clone(right: 10); + } + + private class IgnoredFlowLayout : FlowLayoutWidget, IIgnoredPopupChild + { + public IgnoredFlowLayout() + : base(FlowDirection.TopToBottom) + { + } + + public bool KeepMenuOpen() + { + return false; + } + } + } +} From aac33b70b80f084b0e79fc2cf9878685fd20a56e Mon Sep 17 00:00:00 2001 From: John Lewin Date: Sat, 29 Sep 2018 15:05:19 -0700 Subject: [PATCH 2/9] Add support for hoverable IconButton --- .../CustomWidgets/HoverImageWidget.cs | 67 +++++++++++++++++++ .../CustomWidgets/SimpleButton.cs | 27 +++++++- Submodules/agg-sharp | 2 +- 3 files changed, 93 insertions(+), 3 deletions(-) create mode 100644 MatterControlLib/CustomWidgets/HoverImageWidget.cs diff --git a/MatterControlLib/CustomWidgets/HoverImageWidget.cs b/MatterControlLib/CustomWidgets/HoverImageWidget.cs new file mode 100644 index 000000000..91c85cd9b --- /dev/null +++ b/MatterControlLib/CustomWidgets/HoverImageWidget.cs @@ -0,0 +1,67 @@ +/* +Copyright (c) 2018, John Lewin +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.Image; +using MatterHackers.Agg.UI; + +namespace MatterHackers.MatterControl +{ + public class HoverImageWidget : ImageWidget + { + private ImageBuffer hoverImage; + + private bool mouseInBounds = false; + + public HoverImageWidget(ImageBuffer normalImage, ImageBuffer hoverImage) + : base(normalImage) + { + this.hoverImage = hoverImage; + } + + public override ImageBuffer Image + { + get => (mouseInBounds) ? hoverImage : base.Image; + set => base.Image = value; + } + + public override void OnMouseEnterBounds(MouseEventArgs mouseEvent) + { + mouseInBounds = true; + base.OnMouseEnterBounds(mouseEvent); + this.Invalidate(); + } + + public override void OnMouseLeaveBounds(MouseEventArgs mouseEvent) + { + mouseInBounds = false; + base.OnMouseLeaveBounds(mouseEvent); + this.Invalidate(); + } + } +} diff --git a/MatterControlLib/CustomWidgets/SimpleButton.cs b/MatterControlLib/CustomWidgets/SimpleButton.cs index 0c326213b..45949c2e4 100644 --- a/MatterControlLib/CustomWidgets/SimpleButton.cs +++ b/MatterControlLib/CustomWidgets/SimpleButton.cs @@ -34,6 +34,7 @@ using MatterHackers.Agg; using MatterHackers.Agg.Image; using MatterHackers.Agg.UI; using MatterHackers.ImageProcessing; +using static MatterHackers.MatterControl.ApplicationSettingsPage; namespace MatterHackers.MatterControl.CustomWidgets { @@ -190,9 +191,31 @@ namespace MatterHackers.MatterControl.CustomWidgets public class IconButton : SimpleButton { private ImageWidget imageWidget; - private ImageBuffer image; + public IconButton(ImageBuffer icon, ImageBuffer hoverIcon, ThemeConfig theme) + : base(theme) + + { + this.image = icon; + this.HAnchor = HAnchor.Absolute; + this.VAnchor = VAnchor.Absolute | VAnchor.Center; + this.Height = theme.ButtonHeight; + this.Width = theme.ButtonHeight; + + imageWidget = new HoverImageWidget(icon, hoverIcon) + { + HAnchor = HAnchor.Center, + VAnchor = VAnchor.Center, + }; + imageWidget.Click += (s, e) => + { + this.OnClick(e); + }; + + this.AddChild(imageWidget); + } + public IconButton(ImageBuffer icon, ThemeConfig theme) : base(theme) { @@ -220,7 +243,7 @@ namespace MatterHackers.MatterControl.CustomWidgets /// internal void SetIcon(ImageBuffer icon) { - image = icon; + image = icon; imageWidget.Image = icon; } diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index f335ee526..97d23209a 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit f335ee5260d795ce95a1c7fb4de8a2acb0ec6af3 +Subproject commit 97d23209a09d00e9e5d0dc4428e5ccf74a5825b3 From 1d8771d14618bb5ce075445580851978422f736b Mon Sep 17 00:00:00 2001 From: John Lewin Date: Sat, 29 Sep 2018 15:06:57 -0700 Subject: [PATCH 3/9] Simplify product name in About menu --- .../ApplicationSettings/ApplicationSettingsView.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MatterControlLib/ConfigurationPage/ApplicationSettings/ApplicationSettingsView.cs b/MatterControlLib/ConfigurationPage/ApplicationSettings/ApplicationSettingsView.cs index 2c4153231..8bfb58b27 100644 --- a/MatterControlLib/ConfigurationPage/ApplicationSettings/ApplicationSettingsView.cs +++ b/MatterControlLib/ConfigurationPage/ApplicationSettings/ApplicationSettingsView.cs @@ -78,7 +78,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage this.AddChild(new SettingsItem("Theme".Localize(), new GuiWidget(), theme)); this.AddChild(this.GetThemeControl()); - var aboutMatterControl = new SettingsItem("About".Localize() + " " + ApplicationController.Instance.ProductName, theme); + var aboutMatterControl = new SettingsItem("About".Localize() + " MatterControl", theme); if (IntPtr.Size == 8) { // Push right From a27bbba014dc9f7bc27f96b38212f5ec8b265389 Mon Sep 17 00:00:00 2001 From: John Lewin Date: Sat, 29 Sep 2018 15:12:40 -0700 Subject: [PATCH 4/9] Remove "Parts" from start page --- .../StartPage/ExplorerBar.cs | 81 +------------------ .../StartPage/StartTabPage.cs | 5 -- 2 files changed, 1 insertion(+), 85 deletions(-) diff --git a/MatterControlLib/PartPreviewWindow/StartPage/ExplorerBar.cs b/MatterControlLib/PartPreviewWindow/StartPage/ExplorerBar.cs index 30bcc3d93..18f9f5e93 100644 --- a/MatterControlLib/PartPreviewWindow/StartPage/ExplorerBar.cs +++ b/MatterControlLib/PartPreviewWindow/StartPage/ExplorerBar.cs @@ -54,7 +54,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.PlusTab { this.HAnchor = HAnchor.Stretch; this.VAnchor = VAnchor.Fit; - this.Margin = new BorderDouble(30, 0, 30, 15); + this.Margin = new BorderDouble(30, 15); headingBar = new FlowLayoutWidget() { @@ -283,83 +283,4 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.PlusTab base.OnClosed(e); } } - - public class PartsBar : ExplorerBar - { - public PartsBar(PartPreviewContent partPreviewContent, ThemeConfig theme) - : base("Parts".Localize(), theme) - { - - var emptyPlateButton = new ImageWidget(AggContext.StaticData.LoadIcon("new-part.png", 70, 70)) - { - Margin = new BorderDouble(right: 5), - Selectable = true, - BackgroundColor = theme.MinimalShade, - Cursor = Cursors.Hand, - Name = "Create Part Button" - }; - emptyPlateButton.Click += (s, e) => - { - if (e.Button == MouseButtons.Left) - { - UiThread.RunOnIdle(async () => - { - var workspace = new BedConfig(); - await workspace.LoadContent( - new EditContext() - { - ContentStore = ApplicationController.Instance.Library.PartHistory, - SourceItem = BedConfig.NewPlatingItem(ApplicationController.Instance.Library.PartHistory) - }); - - ApplicationController.Instance.Workspaces.Add(workspace); - - partPreviewContent.CreatePartTab("New Part", workspace, theme); - }); - } - }; - toolbar.AddChild(emptyPlateButton); - - var recentParts = new DirectoryInfo(ApplicationDataStorage.Instance.PartHistoryDirectory).GetFiles("*.mcx").OrderByDescending(f => f.LastWriteTime); - - foreach (var item in recentParts.Where(f => f.Length > 500).Select(f => new SceneReplacementFileItem(f.FullName)).Take(10).ToList()) - { - var iconButton = new IconViewItem(new ListViewItem(item, ApplicationController.Instance.Library.PlatingHistory), 70, 70, theme) - { - Margin = new BorderDouble(right: 5), - Selectable = true, - }; - - iconButton.Click += async (s, e) => - { - // Activate selected item tab - if (partPreviewContent.TabControl.AllTabs.FirstOrDefault(t => t.Text == item.Name) is ChromeTab existingItemTab) - { - partPreviewContent.TabControl.ActiveTab = existingItemTab; - } - else - { - // Create tab for selected item - if (this.PositionWithinLocalBounds(e.X, e.Y) - && e.Button == MouseButtons.Left) - { - var workspace = new BedConfig(); - await workspace.LoadContent( - new EditContext() - { - ContentStore = ApplicationController.Instance.Library.PartHistory, - SourceItem = item - }); - - ApplicationController.Instance.Workspaces.Add(workspace); - - partPreviewContent.CreatePartTab(item.Name, workspace, theme); - } - } - }; - - toolbar.AddChild(iconButton); - } - } - } } \ No newline at end of file diff --git a/MatterControlLib/PartPreviewWindow/StartPage/StartTabPage.cs b/MatterControlLib/PartPreviewWindow/StartPage/StartTabPage.cs index 6d2201311..6729ae01e 100644 --- a/MatterControlLib/PartPreviewWindow/StartPage/StartTabPage.cs +++ b/MatterControlLib/PartPreviewWindow/StartPage/StartTabPage.cs @@ -66,11 +66,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.PlusTab topToBottom.AddChild( new PrinterBar(partPreviewContent, lastProfile, theme)); - topToBottom.AddChild(new PartsBar(partPreviewContent, theme) - { - Margin = new BorderDouble(30, 15) - }); - if (OemSettings.Instance.ShowShopButton) { // actual feed From be903ef55111c2b5454f26f9b4e367786b4d81f0 Mon Sep 17 00:00:00 2001 From: John Lewin Date: Sat, 29 Sep 2018 15:47:23 -0700 Subject: [PATCH 5/9] Make grayscale helper reusable --- .../ApplicationView/ApplicationController.cs | 24 +++++++++++++++++ .../CustomWidgets/SimpleButton.cs | 1 - .../ApplicationSettingsPage.cs | 26 +------------------ 3 files changed, 25 insertions(+), 26 deletions(-) diff --git a/MatterControlLib/ApplicationView/ApplicationController.cs b/MatterControlLib/ApplicationView/ApplicationController.cs index e91b250c0..8a9255536 100644 --- a/MatterControlLib/ApplicationView/ApplicationController.cs +++ b/MatterControlLib/ApplicationView/ApplicationController.cs @@ -357,6 +357,30 @@ namespace MatterHackers.MatterControl }*/ } + internal void MakeGrayscale(ImageBuffer sourceImage) + { + var buffer = sourceImage.GetBuffer(); + int destIndex = 0; + for (int y = 0; y < sourceImage.Height; y++) + { + for (int x = 0; x < sourceImage.Width; x++) + { + int b = buffer[destIndex + 0]; + int g = buffer[destIndex + 1]; + int r = buffer[destIndex + 2]; + + int c = (r * 77) + (g * 151) + (b * 28); + byte gray = (byte)(c >> 8); + + buffer[destIndex + 0] = gray; + buffer[destIndex + 1] = gray; + buffer[destIndex + 2] = gray; + + destIndex += 4; + } + } + } + public static Func> GetPrinterProfileAsync; public static Func, Task> SyncPrinterProfiles; public static Func> GetPublicProfileList; diff --git a/MatterControlLib/CustomWidgets/SimpleButton.cs b/MatterControlLib/CustomWidgets/SimpleButton.cs index 45949c2e4..93cfddc1c 100644 --- a/MatterControlLib/CustomWidgets/SimpleButton.cs +++ b/MatterControlLib/CustomWidgets/SimpleButton.cs @@ -195,7 +195,6 @@ namespace MatterHackers.MatterControl.CustomWidgets public IconButton(ImageBuffer icon, ImageBuffer hoverIcon, ThemeConfig theme) : base(theme) - { this.image = icon; this.HAnchor = HAnchor.Absolute; diff --git a/MatterControlLib/SettingsManagement/ApplicationSettingsPage.cs b/MatterControlLib/SettingsManagement/ApplicationSettingsPage.cs index f293bc5c0..7d2c75c50 100644 --- a/MatterControlLib/SettingsManagement/ApplicationSettingsPage.cs +++ b/MatterControlLib/SettingsManagement/ApplicationSettingsPage.cs @@ -338,7 +338,7 @@ namespace MatterHackers.MatterControl var removeNormalIcon = new ImageBuffer(removeHoveredIcon); //removeNormalIcon.NewGraphics2D().Render(removeHoveredIcon.ToGrayscale(), 0, 0); - ToGrayscale(removeNormalIcon); + ApplicationController.Instance.MakeGrayscale(removeNormalIcon); var clearCacheButton = new IconButton(removeNormalIcon, removeHoveredIcon, theme) { @@ -359,30 +359,6 @@ namespace MatterHackers.MatterControl advancedPanel.Children().First().Border = new BorderDouble(0, 1); } - private static void ToGrayscale(ImageBuffer sourceImage) - { - var buffer = sourceImage.GetBuffer(); - int destIndex = 0; - for (int y = 0; y < sourceImage.Height; y++) - { - for (int x = 0; x < sourceImage.Width; x++) - { - int b = buffer[destIndex + 0]; - int g = buffer[destIndex + 1]; - int r = buffer[destIndex + 2]; - - int c = (r * 77) + (g * 151) + (b * 28); - byte gray = (byte)(c >> 8); - - buffer[destIndex + 0] = gray; - buffer[destIndex + 1] = gray; - buffer[destIndex + 2] = gray; - - destIndex += 4; - } - } - } - private void AddSettingsRow(GuiWidget widget, GuiWidget container) { container.AddChild(widget); From 87ef7b61cb1c61f6fdc10a17b0923528f1aa99c8 Mon Sep 17 00:00:00 2001 From: John Lewin Date: Sat, 29 Sep 2018 15:48:41 -0700 Subject: [PATCH 6/9] Extract code for reuse, add actual async version --- .../ApplicationView/ApplicationController.cs | 92 ++++++++++++------- 1 file changed, 59 insertions(+), 33 deletions(-) diff --git a/MatterControlLib/ApplicationView/ApplicationController.cs b/MatterControlLib/ApplicationView/ApplicationController.cs index 8a9255536..ca6e92bc1 100644 --- a/MatterControlLib/ApplicationView/ApplicationController.cs +++ b/MatterControlLib/ApplicationView/ApplicationController.cs @@ -54,6 +54,7 @@ namespace MatterHackers.MatterControl using System.ComponentModel; using System.IO.Compression; using System.Net; + using System.Net.Http; using System.Reflection; using System.Text; using System.Threading; @@ -1829,44 +1830,14 @@ namespace MatterHackers.MatterControl /// public void DownloadToImageAsync(ImageBuffer imageToLoadInto, string uriToLoad, bool scaleToImageX, IRecieveBlenderByte scalingBlender = null) { - if (scalingBlender == null) - { - scalingBlender = new BlenderBGRA(); - } - WebClient client = new WebClient(); - client.DownloadDataCompleted += (object sender, DownloadDataCompletedEventArgs e) => + client.DownloadDataCompleted += (sender, e) => { try // if we get a bad result we can get a target invocation exception. In that case just don't show anything { - // scale the loaded image to the size of the target image - byte[] raw = e.Result; - Stream stream = new MemoryStream(raw); - ImageBuffer unScaledImage = new ImageBuffer(10, 10); - if (scaleToImageX) - { - AggContext.StaticData.LoadImageData(stream, unScaledImage); - // If the source image (the one we downloaded) is more than twice as big as our dest image. - while (unScaledImage.Width > imageToLoadInto.Width * 2) - { - // The image sampler we use is a 2x2 filter so we need to scale by a max of 1/2 if we want to get good results. - // So we scale as many times as we need to get the Image to be the right size. - // If this were going to be a non-uniform scale we could do the x and y separately to get better results. - ImageBuffer halfImage = new ImageBuffer(unScaledImage.Width / 2, unScaledImage.Height / 2, 32, scalingBlender); - halfImage.NewGraphics2D().Render(unScaledImage, 0, 0, 0, halfImage.Width / (double)unScaledImage.Width, halfImage.Height / (double)unScaledImage.Height); - unScaledImage = halfImage; - } + Stream stream = new MemoryStream(e.Result); - double finalScale = imageToLoadInto.Width / (double)unScaledImage.Width; - imageToLoadInto.Allocate(imageToLoadInto.Width, (int)(unScaledImage.Height * finalScale), imageToLoadInto.Width * (imageToLoadInto.BitDepth / 8), imageToLoadInto.BitDepth); - imageToLoadInto.NewGraphics2D().Render(unScaledImage, 0, 0, 0, finalScale, finalScale); - } - else - { - AggContext.StaticData.LoadImageData(stream, imageToLoadInto); - } - - imageToLoadInto.MarkImageChanged(); + this.LoadImageInto(imageToLoadInto, scaleToImageX, scalingBlender, stream); } catch { @@ -1882,6 +1853,61 @@ namespace MatterHackers.MatterControl } } + private HttpClient httpClient = new HttpClient(); + + public async Task LoadRemoteImage(ImageBuffer imageToLoadInto, string uriToLoad, bool scaleToImageX, IRecieveBlenderByte scalingBlender = null) + { + try + { + using (var stream = await httpClient.GetStreamAsync(uriToLoad)) + { + this.LoadImageInto(imageToLoadInto, scaleToImageX, scalingBlender, stream); + }; + } + catch (Exception ex) + { + Trace.WriteLine("Error loading image: " + uriToLoad); + Trace.WriteLine(ex.Message); + } + + } + + private void LoadImageInto(ImageBuffer imageToLoadInto, bool scaleToImageX, IRecieveBlenderByte scalingBlender, Stream stream) + { + if (scalingBlender == null) + { + scalingBlender = new BlenderBGRA(); + } + + ImageBuffer unScaledImage = new ImageBuffer(10, 10); + if (scaleToImageX) + { + // scale the loaded image to the size of the target image + AggContext.StaticData.LoadImageData(stream, unScaledImage); + + // If the source image (the one we downloaded) is more than twice as big as our dest image. + while (unScaledImage.Width > imageToLoadInto.Width * 2) + { + // The image sampler we use is a 2x2 filter so we need to scale by a max of 1/2 if we want to get good results. + // So we scale as many times as we need to get the Image to be the right size. + // If this were going to be a non-uniform scale we could do the x and y separately to get better results. + ImageBuffer halfImage = new ImageBuffer(unScaledImage.Width / 2, unScaledImage.Height / 2, 32, scalingBlender); + halfImage.NewGraphics2D().Render(unScaledImage, 0, 0, 0, halfImage.Width / (double)unScaledImage.Width, halfImage.Height / (double)unScaledImage.Height); + unScaledImage = halfImage; + } + + double finalScale = imageToLoadInto.Width / (double)unScaledImage.Width; + imageToLoadInto.Allocate(imageToLoadInto.Width, (int)(unScaledImage.Height * finalScale), imageToLoadInto.Width * (imageToLoadInto.BitDepth / 8), imageToLoadInto.BitDepth); + imageToLoadInto.NewGraphics2D().Render(unScaledImage, 0, 0, 0, finalScale, finalScale); + } + else + { + AggContext.StaticData.LoadImageData(stream, imageToLoadInto); + } + + imageToLoadInto.MarkImageChanged(); + } + /// /// Download an image from the web into the specified ImageSequence /// From 48efa5c575e897e83153e339ebedb300d8962911 Mon Sep 17 00:00:00 2001 From: John Lewin Date: Sat, 29 Sep 2018 15:48:54 -0700 Subject: [PATCH 7/9] Remove banner --- MatterControlLib/PartPreviewWindow/StartPage/StartTabPage.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/MatterControlLib/PartPreviewWindow/StartPage/StartTabPage.cs b/MatterControlLib/PartPreviewWindow/StartPage/StartTabPage.cs index 6729ae01e..bafa06423 100644 --- a/MatterControlLib/PartPreviewWindow/StartPage/StartTabPage.cs +++ b/MatterControlLib/PartPreviewWindow/StartPage/StartTabPage.cs @@ -55,11 +55,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.PlusTab }; this.AddChild(topToBottom); - if (OemSettings.Instance.ShowShopButton) - { - topToBottom.AddChild(new ExplorePanel(theme, "banners?sk=ii2gffs6e89c2cdd9er21v", "BannerFeed.json")); - } - var lastProfileID = ProfileManager.Instance.LastProfileID; var lastProfile = ProfileManager.Instance[lastProfileID]; From 6e4bd2b1872bb98db95ad094a883ecbc3d17aa98 Mon Sep 17 00:00:00 2001 From: John Lewin Date: Sat, 29 Sep 2018 15:49:45 -0700 Subject: [PATCH 8/9] Remove color from article icons until hover --- .../StartPage/ExploreItem.cs | 63 ++++++++++++++++--- 1 file changed, 54 insertions(+), 9 deletions(-) diff --git a/MatterControlLib/PartPreviewWindow/StartPage/ExploreItem.cs b/MatterControlLib/PartPreviewWindow/StartPage/ExploreItem.cs index 2c441aedf..f86a9deed 100644 --- a/MatterControlLib/PartPreviewWindow/StartPage/ExploreItem.cs +++ b/MatterControlLib/PartPreviewWindow/StartPage/ExploreItem.cs @@ -36,37 +36,50 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.PlusTab public class ExploreItem : FlowLayoutWidget { private FeedItemData item; + private ImageBuffer image; public static int IconSize => (int)(40 * GuiWidget.DeviceScale); public static int ItemSpacing { get; } = 10; + private ImageBuffer hoverImage = null; + private ImageWidget imageWidget; + public ExploreItem(FeedItemData item, ThemeConfig theme) { - this.HAnchor = HAnchor.Absolute; this.Width = 400 * GuiWidget.DeviceScale; //this.Border = spacing; this.Padding = ItemSpacing; this.item = item; + image = new ImageBuffer(IconSize, IconSize); + if (item.icon != null) { - ImageBuffer image = new ImageBuffer(IconSize, IconSize); - - var imageWidget = new ImageWidget(image) + imageWidget = new ImageWidget(image) { Selectable = false, VAnchor = VAnchor.Top, Margin = new BorderDouble(right: ItemSpacing) }; - imageWidget.Load += (s, e) => ApplicationController.Instance.DownloadToImageAsync(image, item.icon, true, new BlenderPreMultBGRA()); + imageWidget.Load += async (s, e) => + { + var loadInto = new ImageBuffer(IconSize, IconSize); + await ApplicationController.Instance.LoadRemoteImage(loadInto, item.icon, true, new BlenderPreMultBGRA()); + + var grayscale = new ImageBuffer(loadInto); + ApplicationController.Instance.MakeGrayscale(grayscale); + + image = grayscale; + imageWidget.Image = image; + + hoverImage = loadInto; + }; this.AddChild(imageWidget); } else if(item.widget_url != null) { - ImageBuffer image = new ImageBuffer(IconSize, IconSize); - var whiteBackground = new GuiWidget(IconSize, IconSize) { // these images expect to be on white so change the background to white @@ -75,13 +88,25 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.PlusTab }; this.AddChild(whiteBackground); - var imageWidget = new ImageWidget(image) + imageWidget = new ImageWidget(image) { Selectable = false, VAnchor = VAnchor.Center, }; - imageWidget.Load += (s, e) => ApplicationController.Instance.DownloadToImageAsync(image, item.widget_url, true, new BlenderPreMultBGRA()); + imageWidget.Load += async (s, e) => + { + var loadInto = new ImageBuffer(IconSize, IconSize); + await ApplicationController.Instance.LoadRemoteImage(loadInto, item.widget_url, true, new BlenderPreMultBGRA()); + + var grayscale = new ImageBuffer(loadInto); + ApplicationController.Instance.MakeGrayscale(grayscale); + + image = grayscale; + imageWidget.Image = image; + + hoverImage = loadInto; + }; whiteBackground.AddChild(imageWidget); } @@ -100,6 +125,26 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.PlusTab this.Cursor = Cursors.Hand; } + public override void OnMouseEnterBounds(MouseEventArgs mouseEvent) + { + if (hoverImage != null) + { + imageWidget.Image = hoverImage; + this.Invalidate(); + } + + base.OnMouseEnterBounds(mouseEvent); + + } + + public override void OnMouseLeaveBounds(MouseEventArgs mouseEvent) + { + imageWidget.Image = image; + base.OnMouseLeaveBounds(mouseEvent); + + this.Invalidate(); + } + public override void OnClick(MouseEventArgs mouseEvent) { if (mouseEvent.Button == MouseButtons.Left) From 1938a4c5425db6f26116e7e1b845d0fd5c9f0214 Mon Sep 17 00:00:00 2001 From: John Lewin Date: Sat, 29 Sep 2018 15:54:35 -0700 Subject: [PATCH 9/9] Use AccentMimimalOverlay on ExploreItem hover --- .../PartPreviewWindow/StartPage/ExploreItem.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/MatterControlLib/PartPreviewWindow/StartPage/ExploreItem.cs b/MatterControlLib/PartPreviewWindow/StartPage/ExploreItem.cs index f86a9deed..85fe20795 100644 --- a/MatterControlLib/PartPreviewWindow/StartPage/ExploreItem.cs +++ b/MatterControlLib/PartPreviewWindow/StartPage/ExploreItem.cs @@ -36,6 +36,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.PlusTab public class ExploreItem : FlowLayoutWidget { private FeedItemData item; + private ThemeConfig theme; private ImageBuffer image; public static int IconSize => (int)(40 * GuiWidget.DeviceScale); @@ -51,6 +52,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.PlusTab //this.Border = spacing; this.Padding = ItemSpacing; this.item = item; + this.theme = theme; image = new ImageBuffer(IconSize, IconSize); @@ -125,8 +127,18 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.PlusTab this.Cursor = Cursors.Hand; } + public override Color BackgroundColor + { + get => (mouseInBounds) ? theme.AccentMimimalOverlay : base.BackgroundColor; + set => base.BackgroundColor = value; + } + + private bool mouseInBounds = false; + public override void OnMouseEnterBounds(MouseEventArgs mouseEvent) { + mouseInBounds = true; + if (hoverImage != null) { imageWidget.Image = hoverImage; @@ -139,6 +151,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.PlusTab public override void OnMouseLeaveBounds(MouseEventArgs mouseEvent) { + mouseInBounds = false; + imageWidget.Image = image; base.OnMouseLeaveBounds(mouseEvent);