Migrate material SectionWidget to material button in toolbar
This commit is contained in:
parent
9876abfba5
commit
c96fc4c048
6 changed files with 164 additions and 24 deletions
|
|
@ -146,6 +146,8 @@ namespace MatterHackers.MatterControl
|
|||
public Color Shade { get; } = new Color(0, 0, 0, 120);
|
||||
public Color DarkShade { get; } = new Color(0, 0, 0, 190);
|
||||
|
||||
public Color MinimalHighlight { get; } = new Color(255, 255, 255, 15);
|
||||
|
||||
public Color ActiveTabColor { get; set; }
|
||||
public Color TabBarBackground { get; set; }
|
||||
public Color InactiveTabColor { get; set; }
|
||||
|
|
|
|||
|
|
@ -61,7 +61,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
Width = scaledButtonSize,
|
||||
Height = scaledButtonSize,
|
||||
HAnchor = HAnchor.Center,
|
||||
VAnchor = VAnchor.Center
|
||||
VAnchor = VAnchor.Center,
|
||||
DisabledColor = theme.MinimalShade
|
||||
};
|
||||
|
||||
this.AddChild(colorButton);
|
||||
|
|
|
|||
93
MatterControlLib/PartPreviewWindow/ItemMaterialButton.cs
Normal file
93
MatterControlLib/PartPreviewWindow/ItemMaterialButton.cs
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
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.Linq;
|
||||
using MatterHackers.Agg;
|
||||
using MatterHackers.Agg.Image;
|
||||
using MatterHackers.Agg.UI;
|
||||
using MatterHackers.DataConverters3D;
|
||||
using MatterHackers.Localizations;
|
||||
|
||||
namespace MatterHackers.MatterControl.PartPreviewWindow
|
||||
{
|
||||
public class ItemMaterialButton : PopupButton
|
||||
{
|
||||
private ColorButton materialColorButton;
|
||||
|
||||
public ItemMaterialButton(InteractiveScene scene, ThemeConfig theme)
|
||||
{
|
||||
this.ToolTipText = "Material".Localize();
|
||||
var scaledButtonSize = 14 * GuiWidget.DeviceScale;
|
||||
|
||||
this.DynamicPopupContent = () =>
|
||||
{
|
||||
//return new ColorSwatchSelector(scene, theme, buttonSize: 16, buttonSpacing: new BorderDouble(1, 1, 0, 0), colorNotifier: (newColor) => colorButton.BackgroundColor = newColor)
|
||||
|
||||
return new MaterialControls(scene, theme, colorNotifier: (newColor) => materialColorButton.BackgroundColor = newColor)
|
||||
{
|
||||
Padding = theme.DefaultContainerPadding,
|
||||
BackgroundColor = this.HoverColor,
|
||||
HAnchor = HAnchor.Fit,
|
||||
VAnchor = VAnchor.Fit
|
||||
};
|
||||
};
|
||||
|
||||
materialColorButton = new ColorButton(scene.SelectedItem?.Color ?? theme.SlightShade)
|
||||
{
|
||||
Width = scaledButtonSize,
|
||||
Height = scaledButtonSize,
|
||||
HAnchor = HAnchor.Center,
|
||||
VAnchor = VAnchor.Center,
|
||||
DrawGrid = true,
|
||||
DisabledColor = theme.MinimalShade
|
||||
};
|
||||
|
||||
this.AddChild(materialColorButton);
|
||||
}
|
||||
|
||||
public override void OnLoad(EventArgs args)
|
||||
{
|
||||
var firstBackgroundColor = this.Parents<GuiWidget>().Where(p => p.BackgroundColor.Alpha0To1 == 1).FirstOrDefault()?.BackgroundColor;
|
||||
if (firstBackgroundColor != null)
|
||||
{
|
||||
// Resolve alpha
|
||||
this.HoverColor = new BlenderRGBA().Blend(firstBackgroundColor.Value, this.HoverColor);
|
||||
}
|
||||
|
||||
base.OnLoad(args);
|
||||
}
|
||||
|
||||
public Color Color
|
||||
{
|
||||
get => materialColorButton.BackgroundColor;
|
||||
set => materialColorButton.BackgroundColor = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (c) 2017, Lars Brubaker, John Lewin
|
||||
Copyright (c) 2018, Lars Brubaker, John Lewin
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
|
|
@ -27,13 +27,13 @@ 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.ObjectModel;
|
||||
using MatterHackers.Agg;
|
||||
using MatterHackers.Agg.UI;
|
||||
using MatterHackers.DataConverters3D;
|
||||
using MatterHackers.Localizations;
|
||||
using MatterHackers.MeshVisualizer;
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace MatterHackers.MatterControl.PartPreviewWindow
|
||||
{
|
||||
|
|
@ -43,12 +43,12 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
private ThemeConfig theme;
|
||||
private InteractiveScene scene;
|
||||
|
||||
public MaterialControls(InteractiveScene scene, ThemeConfig theme)
|
||||
public MaterialControls(InteractiveScene scene, ThemeConfig theme, Action<Color> colorNotifier = null)
|
||||
: base(FlowDirection.TopToBottom)
|
||||
{
|
||||
this.theme = theme;
|
||||
this.scene = scene;
|
||||
this.HAnchor = HAnchor.Stretch;
|
||||
this.HAnchor = HAnchor.Fit;
|
||||
this.VAnchor = VAnchor.Fit;
|
||||
|
||||
materialButtons.Clear();
|
||||
|
|
@ -69,12 +69,14 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
|
||||
var scaledButtonSize = 16 * GuiWidget.DeviceScale;
|
||||
|
||||
buttonView.AddChild(new ColorButton(extruderIndex == -1 ? Color.Black : MaterialRendering.Color(extruderIndex))
|
||||
buttonView.AddChild(new ColorButton(MaterialRendering.Color(extruderIndex, theme.MinimalHighlight))
|
||||
{
|
||||
Margin = new BorderDouble(right: 5),
|
||||
Width = scaledButtonSize,
|
||||
Height = scaledButtonSize,
|
||||
VAnchor = VAnchor.Center,
|
||||
DrawGrid = true,
|
||||
//DoubleBuffer = true
|
||||
});
|
||||
|
||||
buttonView.AddChild(new TextWidget(name, pointSize: theme.DefaultFontSize, textColor: theme.Colors.PrimaryTextColor)
|
||||
|
|
@ -90,20 +92,24 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
|
||||
var radioButton = new RadioButton(radioButtonView)
|
||||
{
|
||||
HAnchor = HAnchor.Stretch,
|
||||
HAnchor = HAnchor.Fit,
|
||||
VAnchor = VAnchor.Fit,
|
||||
TextColor = theme.Colors.PrimaryTextColor
|
||||
TextColor = theme.Colors.PrimaryTextColor,
|
||||
Checked = extruderIndex == scene.SelectedItem.MaterialIndex
|
||||
};
|
||||
materialButtons.Add(radioButton);
|
||||
this.AddChild(radioButton);
|
||||
|
||||
int extruderIndexCanPassToClick = extruderIndex;
|
||||
int localExtruderIndex = extruderIndex;
|
||||
radioButton.Click += (sender, e) =>
|
||||
{
|
||||
var selectedItem = scene.SelectedItem;
|
||||
if (selectedItem != null)
|
||||
{
|
||||
selectedItem.MaterialIndex = extruderIndexCanPassToClick;
|
||||
selectedItem.MaterialIndex = localExtruderIndex;
|
||||
|
||||
colorNotifier?.Invoke(MaterialRendering.Color(localExtruderIndex, theme.MinimalHighlight));
|
||||
|
||||
scene.Invalidate(new InvalidateArgs(null, InvalidateType.Material));
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ using MatterHackers.Localizations;
|
|||
using MatterHackers.MatterControl.CustomWidgets;
|
||||
using MatterHackers.MatterControl.DesignTools;
|
||||
using MatterHackers.MatterControl.Library;
|
||||
using MatterHackers.MeshVisualizer;
|
||||
using MatterHackers.VectorMath;
|
||||
using static JsonPath.JsonPathContext.ReflectionValueSystem;
|
||||
|
||||
|
|
@ -103,6 +104,13 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
};
|
||||
toolbar.AddChild(itemColorButton);
|
||||
|
||||
var itemMaterialButton = new ItemMaterialButton(scene, theme)
|
||||
{
|
||||
Width = 30,
|
||||
Height = 30,
|
||||
};
|
||||
toolbar.AddChild(itemMaterialButton);
|
||||
|
||||
// put in a make permanent button
|
||||
var icon = AggContext.StaticData.LoadIcon("noun_766157.png", 16, 16, theme.InvertIcons).SetPreMultiply();
|
||||
var applyButton = new IconButton(icon, theme)
|
||||
|
|
@ -185,12 +193,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
|
||||
this.ContentPanel.AddChild(editorSectionWidget);
|
||||
|
||||
var materialsSection = new SectionWidget("Materials".Localize(), new MaterialControls(scene, theme), theme, serializationKey: UserSettingsKey.MaterialsPanelExpanded)
|
||||
{
|
||||
Name = "Materials Panel",
|
||||
};
|
||||
this.ContentPanel.AddChild(materialsSection);
|
||||
|
||||
// Enforce panel padding in sidebar
|
||||
foreach(var sectionWidget in this.ContentPanel.Children<SectionWidget>())
|
||||
{
|
||||
|
|
@ -210,7 +212,13 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
|
||||
scene.SelectionChanged += (s, e) =>
|
||||
{
|
||||
itemColorButton.Color = scene.SelectedItem?.Color ?? theme.MinimalShade;
|
||||
var selectedItem = scene.SelectedItem;
|
||||
if (selectedItem != null)
|
||||
{
|
||||
itemColorButton.Color = scene.SelectedItem.Color;
|
||||
itemMaterialButton.Color = MaterialRendering.Color(scene.SelectedItem.MaterialIndex, theme.MinimalHighlight);
|
||||
}
|
||||
|
||||
applyButton.Enabled = scene.SelectedItem?.CanApply == true;
|
||||
removeButton.Enabled = scene.SelectedItem != null;
|
||||
overflowButton.Enabled = scene.SelectedItem != null;
|
||||
|
|
|
|||
|
|
@ -119,20 +119,50 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
|
||||
public class ColorButton : GuiWidget
|
||||
{
|
||||
private Color grayScale;
|
||||
|
||||
public ColorButton(Color color)
|
||||
{
|
||||
this.BackgroundColor = color;
|
||||
|
||||
// Calculate and store grayscale of current color
|
||||
grayScale = color.ToGrayscale();
|
||||
// Default DisabledColor to the grayscale of current color
|
||||
this.DisabledColor = color.ToGrayscale();
|
||||
}
|
||||
|
||||
public bool DrawGrid { get; set; }
|
||||
|
||||
public override Color BackgroundColor
|
||||
{
|
||||
get => (this.Enabled) ? base.BackgroundColor : this.grayScale;
|
||||
set => base.BackgroundColor = value;
|
||||
get => (this.Enabled) ? base.BackgroundColor : this.DisabledColor;
|
||||
set
|
||||
{
|
||||
base.BackgroundColor = value;
|
||||
}
|
||||
}
|
||||
|
||||
public Color DisabledColor { get; set; }
|
||||
|
||||
public override void OnDraw(Graphics2D graphics2D)
|
||||
{
|
||||
if (this.DrawGrid)
|
||||
{
|
||||
var numberOfStripes = 3;
|
||||
|
||||
int ix = 20;
|
||||
|
||||
for (var i = 0; i < numberOfStripes * 2; i++)
|
||||
{
|
||||
var thickness = ix / numberOfStripes;
|
||||
|
||||
graphics2D.Line(
|
||||
i * thickness + thickness / 2 - ix,
|
||||
0,
|
||||
i * thickness + thickness / 2,
|
||||
ix,
|
||||
Color.Gray,
|
||||
0.05);
|
||||
}
|
||||
}
|
||||
|
||||
base.OnDraw(graphics2D);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue