diff --git a/ActionBar/PrinterConnectAndSelectControl.cs b/ActionBar/PrinterConnectAndSelectControl.cs index 9eb5a815f..1ef7041c2 100644 --- a/ActionBar/PrinterConnectAndSelectControl.cs +++ b/ActionBar/PrinterConnectAndSelectControl.cs @@ -70,102 +70,6 @@ namespace MatterHackers.MatterControl.ActionBar } } - public class SimpleButton : FlowLayoutWidget - { - public ImageBuffer Image { get; set; } - public BorderDouble ImageMargin { get; set; } - public BorderDouble ImagePadding { get; set; } - public double FontSize { get; set; } = 12; - - public int BorderWidth { get; set; } - - public RGBA_Bytes BorderColor { get; set; } = RGBA_Bytes.Transparent; - - private int borderRadius = 0; - - public SimpleButton(string text, ImageBuffer image = null) - { - this.HAnchor = HAnchor.Left | HAnchor.Fit; - this.VAnchor = VAnchor.Top | VAnchor.Fit; - - this.Text = text; - this.Image = image; - - this.AddChild(new GuiWidget() { BackgroundColor = RGBA_Bytes.Green, Height = 10, Width = 20 }); - - UiThread.RunOnIdle(() => - { - if (this.Image != null) - { - this.AddChild( - new ImageWidget(this.Image) - { - Margin = ImageMargin, - Padding = ImagePadding, - VAnchor = VAnchor.Stretch, - }); - } - - if (!string.IsNullOrEmpty(this.Text)) - { - this.AddChild(new TextWidget(this.Text, pointSize: this.FontSize)); - } - - this.AddChild(new GuiWidget() { BackgroundColor = RGBA_Bytes.Red, Height = 10, Width = 20 }); - }); - } - - public override void OnLayout(LayoutEventArgs layoutEventArgs) - { - base.OnLayout(layoutEventArgs); - } - - /* - public override void OnLoad(EventArgs args) - { - if (this.Image != null) - { - this.AddChild(new ImageWidget(this.Image) - { - Margin = ImageMargin - }); - } - - if (!string.IsNullOrEmpty(this.Text)) - { - this.AddChild(new TextWidget(this.Text, pointSize: this.FontSize)); - } - - base.OnLoad(args); - }*/ - - public override void OnDraw(Graphics2D graphics2D) - { - if (this.BorderColor.Alpha0To255 > 0) - { - RectangleDouble borderRectangle = LocalBounds; - - if (BorderWidth > 0) - { - if (BorderWidth == 1) - { - graphics2D.Rectangle(borderRectangle, this.BorderColor); - } - else - { - graphics2D.Render( - new Stroke( - new RoundedRect(borderRectangle, this.borderRadius), - BorderWidth), - this.BorderColor); - } - } - } - - base.OnDraw(graphics2D); - } - } - public class PrinterConnectButton : GuiWidget { private readonly string disconnectAndCancelTitle = "Disconnect and stop the current print?".Localize(); diff --git a/ApplicationView/ThemeConfig.cs b/ApplicationView/ThemeConfig.cs index dada5e208..cc34fec2f 100644 --- a/ApplicationView/ThemeConfig.cs +++ b/ApplicationView/ThemeConfig.cs @@ -112,6 +112,7 @@ namespace MatterHackers.MatterControl public TextImageButtonFactory NoMarginWhite { get; private set; } public BorderDouble ToolbarPadding { get; set; } = 3; public RGBA_Bytes PrimaryTabFillColor { get; internal set; } + public double ButtonHeight { get; internal set; } = 28; private EventHandler unregisterEvents; diff --git a/ApplicationView/WidescreenPanel.cs b/ApplicationView/WidescreenPanel.cs index 4553fc6b4..9c428cfa1 100644 --- a/ApplicationView/WidescreenPanel.cs +++ b/ApplicationView/WidescreenPanel.cs @@ -70,7 +70,7 @@ namespace MatterHackers.MatterControl leftNav.AddChild(new BrandMenuButton() { - MinimumSize = new VectorMath.Vector2(0, 40), + MinimumSize = new VectorMath.Vector2(0, 32), HAnchor = HAnchor.Stretch, VAnchor = VAnchor.Fit }); @@ -98,7 +98,7 @@ namespace MatterHackers.MatterControl { HAnchor = HAnchor.Stretch, VAnchor = VAnchor.Fit, - Margin = 6 + Margin = new BorderDouble(6, 0) }; var icon = AggContext.StaticData.LoadImage(Path.Combine("Images", "mh-app-logo.png")); diff --git a/ControlElements/TextImageButtonFactory.cs b/ControlElements/TextImageButtonFactory.cs index fdf327e19..d5512bd06 100644 --- a/ControlElements/TextImageButtonFactory.cs +++ b/ControlElements/TextImageButtonFactory.cs @@ -34,6 +34,7 @@ using MatterHackers.Agg.Platform; using MatterHackers.Agg.UI; using MatterHackers.ImageProcessing; using System; +using MatterHackers.MatterControl.CustomWidgets; namespace MatterHackers.MatterControl { @@ -104,12 +105,7 @@ namespace MatterHackers.MatterControl icon.InvertLightness(); } - return new Button(0, 0, - new ButtonViewThreeImage( - icon.AjustAlpha(.7), - icon.AjustAlpha(.9), - icon.AjustAlpha(1), - icon.AjustAlpha(.2))); + return new IconButton(icon); } public CheckBox GenerateCheckBoxButton(string label, ImageBuffer normalImage, ImageBuffer normalToPressedImage = null, ImageBuffer pressedImage = null, ImageBuffer pressedToNormalImage = null, string pressedLabel = null) diff --git a/CustomWidgets/DockingTabControl.cs b/CustomWidgets/DockingTabControl.cs index f699d2f06..8a65f66c3 100644 --- a/CustomWidgets/DockingTabControl.cs +++ b/CustomWidgets/DockingTabControl.cs @@ -100,14 +100,14 @@ namespace MatterHackers.MatterControl.CustomWidgets AddChild(topToBottom); } - private ImageWidget CreatePinButton() + private GuiWidget CreatePinButton() { var icon = AggContext.StaticData.LoadIcon(this.ControlIsPinned ? "Pushpin_16x.png" : "PushpinUnpin_16x.png", 16, 16).InvertLightness(); - var imageWidget = new ImageWidget(icon) + + var imageWidget = new IconButton(icon) { Name = "Pin Settings Button", - Margin = new BorderDouble(right: 25, top: 6), - MinimumSize = new Vector2(16, 16) + Margin = new BorderDouble(right: 2), }; imageWidget.Click += (s, e) => { @@ -272,7 +272,7 @@ namespace MatterHackers.MatterControl.CustomWidgets tabControl.TabBar.AddChild(new HorizontalSpacer()); var pinButton = this.CreatePinButton(); - pinButton.Margin = new BorderDouble(right: 18, bottom: 7); + //pinButton.Margin = new BorderDouble(right: 18, bottom: 7); tabControl.TabBar.AddChild(pinButton); if (printer.ViewState.SliceSettingsTabIndex < tabControl.TabCount) diff --git a/CustomWidgets/LibrarySelector/FolderBreadCrumbWidget.cs b/CustomWidgets/LibrarySelector/FolderBreadCrumbWidget.cs index c5f509f64..8691fd1b6 100644 --- a/CustomWidgets/LibrarySelector/FolderBreadCrumbWidget.cs +++ b/CustomWidgets/LibrarySelector/FolderBreadCrumbWidget.cs @@ -28,9 +28,13 @@ either expressed or implied, of the FreeBSD Project. */ using System.Collections.Generic; +using System.IO; using System.Linq; using MatterHackers.Agg; +using MatterHackers.Agg.Image; +using MatterHackers.Agg.Platform; using MatterHackers.Agg.UI; +using MatterHackers.ImageProcessing; using MatterHackers.Localizations; using MatterHackers.MatterControl.Library; @@ -45,7 +49,10 @@ namespace MatterHackers.MatterControl.CustomWidgets this.listView = listView; this.Name = "FolderBreadCrumbWidget"; UiThread.RunOnIdle(() => SetBreadCrumbs(listView.ActiveContainer)); - HAnchor = HAnchor.Stretch; + + this.HAnchor = HAnchor.Stretch; + this.VAnchor = VAnchor.Fit | VAnchor.Center; + this.Padding = new BorderDouble(left: 2); } public static IEnumerable ItemAndParents(ILibraryContainer item) @@ -68,12 +75,13 @@ namespace MatterHackers.MatterControl.CustomWidgets bool haveFilterRunning = !string.IsNullOrEmpty(currentContainer.KeywordFilter); - var icon = LibraryProviderHelpers.LoadInvertIcon("FileDialog", "up_folder_20.png"); - //icon = LibraryProviderHelpers.ResizeImage(icon, 20, 20); + var theme = ApplicationController.Instance.Theme; - Button upbutton = buttonFactory.Generate("", icon); - upbutton.Name = "Library Up Button"; - upbutton.Margin = 0; + var upbutton = new IconButton(AggContext.StaticData.LoadIcon(Path.Combine("FileDialog", "up_folder_20.png"))) + { + Name = "Library Up Button", + Margin = new BorderDouble(right: 2) + }; upbutton.Click += (s, e) => { if (listView.ActiveContainer.Parent != null) diff --git a/CustomWidgets/SimpleButton.cs b/CustomWidgets/SimpleButton.cs new file mode 100644 index 000000000..3a319afae --- /dev/null +++ b/CustomWidgets/SimpleButton.cs @@ -0,0 +1,179 @@ +/* +Copyright (c) 2017, 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; +using MatterHackers.Agg.Image; +using MatterHackers.Agg.UI; +using MatterHackers.ImageProcessing; + +namespace MatterHackers.MatterControl.CustomWidgets +{ + public class SimpleButton : Button + { + private bool mouseInBounds = false; + + public RGBA_Bytes HoverColor { get; set; } = RGBA_Bytes.Transparent; + + public RGBA_Bytes MouseDownColor { get; set; } = RGBA_Bytes.Transparent; + + 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(); + } + + public override void OnMouseDown(MouseEventArgs mouseEvent) + { + base.OnMouseDown(mouseEvent); + this.Invalidate(); + } + + public override void OnMouseUp(MouseEventArgs mouseEvent) + { + base.OnMouseUp(mouseEvent); + this.Invalidate(); + } + + public override RGBA_Bytes BackgroundColor + { + get + { + if (this.MouseCaptured + && mouseInBounds + && this.Enabled) + { + return this.MouseDownColor; + } + else if (this.mouseInBounds + && this.Enabled) + { + return this.HoverColor; + } + else + { + return base.BackgroundColor; + } + } + set => base.BackgroundColor = value; + } + } + + public class IconButton : SimpleButton + { + private ImageWidget imageWidget; + + private ImageBuffer image; + + public IconButton(ImageBuffer icon) + { + var theme = ApplicationController.Instance.Theme; + + this.image = icon; + this.HoverColor = theme.SlightShade; + this.MouseDownColor = theme.MinimalShade; + this.HAnchor = HAnchor.Absolute; + this.VAnchor = VAnchor.Absolute | VAnchor.Center; + this.Height = theme.ButtonHeight; + this.Width = theme.ButtonHeight; + this.Margin = 0; + + imageWidget = new ImageWidget(icon) + { + HAnchor = HAnchor.Center, + VAnchor = VAnchor.Center, + Selectable = false + }; + + this.AddChild(imageWidget); + } + + public override bool Enabled + { + get => base.Enabled; + set + { + base.Enabled = value; + imageWidget.Image = (value) ? image : this.DisabledImage; + } + } + + private ImageBuffer _disabledImage; + public ImageBuffer DisabledImage + { + get + { + // Lazy construct on first access + if (_disabledImage == null) + { + _disabledImage = image.AjustAlpha(0.2); + } + + return _disabledImage; + } + } + } + + public class TextButton : SimpleButton + { + private TextWidget textWidget; + + public TextButton(ThemeConfig theme) + { + this.textWidget = new TextWidget("", pointSize: theme.ButtonFactory.fontSize); + } + + public override string Text + { + get => base.Text; + set + { + this.textWidget.Text = value; + base.Text = value; + } + } + + public override bool Enabled + { + get => base.Enabled; + set + { + base.Enabled = value; + } + } + } + +} \ No newline at end of file diff --git a/Library/Widgets/PrintLibraryWidget.cs b/Library/Widgets/PrintLibraryWidget.cs index f9a9f136c..8a29d27f8 100644 --- a/Library/Widgets/PrintLibraryWidget.cs +++ b/Library/Widgets/PrintLibraryWidget.cs @@ -105,9 +105,8 @@ namespace MatterHackers.MatterControl.PrintLibrary breadCrumbWidget = new FolderBreadCrumbWidget(libraryView); navBar.AddChild(breadCrumbWidget); - var icon = AggContext.StaticData.LoadIcon("icon_search_24x24.png", 16, 16); - - var buttonFactory = ApplicationController.Instance.Theme.SmallMarginButtonFactory; + var theme = ApplicationController.Instance.Theme; + var buttonFactory = theme.SmallMarginButtonFactory; var searchPanel = new SearchInputBox() { @@ -133,10 +132,11 @@ namespace MatterHackers.MatterControl.PrintLibrary navBar.AddChild(searchPanel); - Button searchButton = buttonFactory.Generate("", icon); - searchButton.ToolTipText = "Search".Localize(); - searchButton.Name = "Search Library Button"; - searchButton.Margin = 0; + var searchButton = new IconButton(AggContext.StaticData.LoadIcon("icon_search_24x24.png", 16, 16)) + { + Name = "Search Library Button", + ToolTipText = "Search".Localize() + }; searchButton.Click += (s, e) => { if (searchPanel.Visible) diff --git a/MatterControl.csproj b/MatterControl.csproj index 8b33acea8..3821263f0 100644 --- a/MatterControl.csproj +++ b/MatterControl.csproj @@ -139,6 +139,7 @@ + diff --git a/PartPreviewWindow/OverflowDropdown.cs b/PartPreviewWindow/OverflowDropdown.cs index 9826bbe99..f8abf982f 100644 --- a/PartPreviewWindow/OverflowDropdown.cs +++ b/PartPreviewWindow/OverflowDropdown.cs @@ -34,7 +34,6 @@ using MatterHackers.Agg.ImageProcessing; using MatterHackers.Agg.Platform; using MatterHackers.Agg.UI; using MatterHackers.Localizations; -using MatterHackers.VectorMath; namespace MatterHackers.MatterControl.PartPreviewWindow { @@ -112,7 +111,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow public PopupButton() { } - + public PopupButton(GuiWidget buttonView) { this.Margin = 3; @@ -144,7 +143,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow { // HACK: Child controls seem to be interfering with this.MouseCaptured - this short term workaround ensure we get clicks but likely mean mouse down outside of the control will fire the popup bool mouseUpInBounds = this.PositionWithinLocalBounds(mouseEvent.X, mouseEvent.Y); - + // Only show the popup if the menu was hidden as the mouse events started if ((mouseUpInBounds || buttonView?.MouseCaptured == true) && !menuVisibileAtMouseDown)