Added a line for the color editing of all parts
Added a color editor to Public Property editor
This commit is contained in:
parent
60045410ce
commit
229931039b
5 changed files with 144 additions and 23 deletions
|
|
@ -101,6 +101,7 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
private static Type[] allowedTypes =
|
||||
{
|
||||
typeof(double), typeof(int), typeof(char), typeof(string), typeof(bool),
|
||||
typeof(Color),
|
||||
typeof(Vector2), typeof(Vector3),
|
||||
typeof(DirectionVector), typeof(DirectionAxis),
|
||||
typeof(ChildrenSelector),
|
||||
|
|
@ -187,7 +188,7 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
return row;
|
||||
}
|
||||
|
||||
private static FlowLayoutWidget CreateSettingsRow(string labelText, string toolTipText = null)
|
||||
public static FlowLayoutWidget CreateSettingsRow(string labelText, string toolTipText = null)
|
||||
{
|
||||
var rowContainer = new FlowLayoutWidget(FlowDirection.LeftToRight)
|
||||
{
|
||||
|
|
@ -299,6 +300,19 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
|
||||
rowContainer = CreateSettingsRow(property, field);
|
||||
}
|
||||
else if (propertyValue is Color color)
|
||||
{
|
||||
var field = new ColorField(theme, object3D.Color);
|
||||
field.Initialize(0);
|
||||
field.ValueChanged += (s, e) =>
|
||||
{
|
||||
property.SetValue(field.Color);
|
||||
object3D?.Invalidate(new InvalidateArgs(context.item, InvalidateType.Properties, undoBuffer));
|
||||
propertyGridModifier?.UpdateControls(new PublicPropertyChange(context, property.PropertyInfo.Name));
|
||||
};
|
||||
|
||||
rowContainer = CreateSettingsRow(property, field);
|
||||
}
|
||||
else if (propertyValue is Vector2 vector2)
|
||||
{
|
||||
var field = new Vector2Field();
|
||||
|
|
|
|||
|
|
@ -41,13 +41,18 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
{
|
||||
private ColorButton colorButton;
|
||||
|
||||
public ItemColorButton(InteractiveScene scene, ThemeConfig theme)
|
||||
public event EventHandler ColorChanged;
|
||||
|
||||
public ItemColorButton(ThemeConfig theme, Color selectedColor)
|
||||
{
|
||||
this.ToolTipText = "Color".Localize();
|
||||
|
||||
HAnchor = HAnchor.Fit;
|
||||
VAnchor = VAnchor.Fit;
|
||||
|
||||
this.DynamicPopupContent = () =>
|
||||
{
|
||||
return new ColorSwatchSelector(scene, theme, buttonSize: 16, buttonSpacing: new BorderDouble(1, 1, 0, 0), colorNotifier: (newColor) => colorButton.BackgroundColor = newColor)
|
||||
return new ColorSwatchSelector(theme, buttonSize: 16, buttonSpacing: new BorderDouble(1, 1, 0, 0), colorNotifier: (newColor) => colorButton.BackgroundColor = newColor)
|
||||
{
|
||||
Padding = theme.DefaultContainerPadding,
|
||||
BackgroundColor = this.HoverColor
|
||||
|
|
@ -56,7 +61,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
|
||||
var scaledButtonSize = 14 * GuiWidget.DeviceScale;
|
||||
|
||||
colorButton = new ColorButton(scene.SelectedItem?.Color ?? theme.SlightShade)
|
||||
colorButton = new ColorButton(selectedColor == Color.Transparent ? theme.SlightShade : selectedColor)
|
||||
{
|
||||
Width = scaledButtonSize,
|
||||
Height = scaledButtonSize,
|
||||
|
|
@ -67,6 +72,11 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
BorderColor = theme.GetBorderColor(75)
|
||||
};
|
||||
|
||||
colorButton.BackgroundColorChanged += (s, e) =>
|
||||
{
|
||||
ColorChanged?.Invoke(this, null);
|
||||
};
|
||||
|
||||
this.AddChild(colorButton);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ using MatterHackers.Localizations;
|
|||
using MatterHackers.MatterControl.CustomWidgets;
|
||||
using MatterHackers.MatterControl.DesignTools;
|
||||
using MatterHackers.MatterControl.Library;
|
||||
using MatterHackers.MatterControl.SlicerConfiguration;
|
||||
using MatterHackers.MeshVisualizer;
|
||||
using MatterHackers.VectorMath;
|
||||
using static JsonPath.JsonPathContext.ReflectionValueSystem;
|
||||
|
|
@ -79,13 +80,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
|
||||
var scene = sceneContext.Scene;
|
||||
|
||||
var itemColorButton = new ItemColorButton(scene, theme)
|
||||
{
|
||||
Width = 30,
|
||||
Height = 30,
|
||||
};
|
||||
toolbar.AddChild(itemColorButton);
|
||||
|
||||
var itemMaterialButton = new ItemMaterialButton(scene, theme)
|
||||
{
|
||||
Width = 30,
|
||||
|
|
@ -179,11 +173,9 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
var selectedItem = scene.SelectedItem;
|
||||
if (selectedItem != null)
|
||||
{
|
||||
itemColorButton.Color = (selectedItem.Color == Color.Transparent) ? theme.MinimalHighlight : selectedItem.Color;
|
||||
itemMaterialButton.Color = MaterialRendering.Color(selectedItem.MaterialIndex, theme.MinimalHighlight);
|
||||
}
|
||||
|
||||
itemColorButton.Enabled = selectedItem != null;
|
||||
itemMaterialButton.Enabled = selectedItem != null;
|
||||
flattenButton.Enabled = selectedItem?.CanFlatten == true;
|
||||
removeButton.Enabled = selectedItem != null;
|
||||
|
|
@ -260,6 +252,22 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
|
||||
bool allowOperations = true;
|
||||
|
||||
// put in a color edit field
|
||||
var field = new ColorField(theme, selectedItem.Color);
|
||||
field.Initialize(0);
|
||||
field.ValueChanged += (s, e) =>
|
||||
{
|
||||
if (selectedItem.Color != field.Color)
|
||||
{
|
||||
undoBuffer.AddAndDo(new ChangeColor(selectedItem, field.Color));
|
||||
}
|
||||
};
|
||||
|
||||
var row = PublicPropertyEditor.CreateSettingsRow("Color".Localize());
|
||||
row.AddChild(field.Content);
|
||||
editorPanel.AddChild(row);
|
||||
|
||||
// put in the normal editor
|
||||
if (selectedItem is ComponentObject3D componentObject
|
||||
&& componentObject.Finalized)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
{
|
||||
public class ColorSwatchSelector : FlowLayoutWidget
|
||||
{
|
||||
public ColorSwatchSelector(InteractiveScene scene, ThemeConfig theme, BorderDouble buttonSpacing, int buttonSize = 32, Action<Color> colorNotifier = null)
|
||||
public ColorSwatchSelector(ThemeConfig theme, BorderDouble buttonSpacing, int buttonSize = 32, Action<Color> colorNotifier = null)
|
||||
: base(FlowDirection.TopToBottom)
|
||||
{
|
||||
var scaledButtonSize = buttonSize * GuiWidget.DeviceScale;
|
||||
|
|
@ -61,11 +61,11 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
for (int colorIndex = 0; colorIndex < colorCount; colorIndex++)
|
||||
{
|
||||
var color = ColorF.FromHSL(colorIndex / (double)colorCount, 1, lightness[rowIndex]).ToColor();
|
||||
colorRow.AddChild(MakeColorButton(scene, color, scaledButtonSize, buttonSpacing, colorChanged));
|
||||
colorRow.AddChild(MakeColorButton(color, scaledButtonSize, buttonSpacing, colorChanged));
|
||||
}
|
||||
|
||||
// put in white and black buttons
|
||||
colorRow.AddChild(MakeColorButton(scene, grayLevel[rowIndex], scaledButtonSize, buttonSpacing, colorChanged));
|
||||
colorRow.AddChild(MakeColorButton(grayLevel[rowIndex], scaledButtonSize, buttonSpacing, colorChanged));
|
||||
|
||||
switch(rowIndex)
|
||||
{
|
||||
|
|
@ -79,26 +79,24 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
};
|
||||
resetButton.Click += (s, e) =>
|
||||
{
|
||||
scene.UndoBuffer.AddAndDo(new ChangeColor(scene.SelectedItem, Color.Transparent));
|
||||
|
||||
// The colorChanged action displays the given color - use .MinimalHighlight rather than no color
|
||||
colorChanged(theme.MinimalHighlight);
|
||||
colorChanged(Color.Transparent);
|
||||
};
|
||||
colorRow.AddChild(resetButton);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
colorRow.AddChild(MakeColorButton(scene, new Color("#555"), scaledButtonSize, buttonSpacing, colorChanged));
|
||||
colorRow.AddChild(MakeColorButton(new Color("#555"), scaledButtonSize, buttonSpacing, colorChanged));
|
||||
break;
|
||||
|
||||
case 2:
|
||||
colorRow.AddChild(MakeColorButton(scene, new Color("#222"), scaledButtonSize, buttonSpacing, colorChanged));
|
||||
colorRow.AddChild(MakeColorButton(new Color("#222"), scaledButtonSize, buttonSpacing, colorChanged));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private GuiWidget MakeColorButton(InteractiveScene scene, Color color, double buttonSize, BorderDouble buttonSpacing, Action<Color> colorChanged)
|
||||
private GuiWidget MakeColorButton(Color color, double buttonSize, BorderDouble buttonSpacing, Action<Color> colorChanged)
|
||||
{
|
||||
var button = new ColorButton(color)
|
||||
{
|
||||
|
|
@ -111,7 +109,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
{
|
||||
UiThread.RunOnIdle(() =>
|
||||
{
|
||||
scene.UndoBuffer.AddAndDo(new ChangeColor(scene.SelectedItem, button.BackgroundColor));
|
||||
colorChanged(button.BackgroundColor);
|
||||
});
|
||||
};
|
||||
|
|
|
|||
92
MatterControlLib/SlicerConfiguration/UIFields/ColorField.cs
Normal file
92
MatterControlLib/SlicerConfiguration/UIFields/ColorField.cs
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
Copyright (c) 2017, Lars Brubaker, 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.UI;
|
||||
using MatterHackers.MatterControl.PartPreviewWindow;
|
||||
using MatterHackers.VectorMath;
|
||||
|
||||
namespace MatterHackers.MatterControl.SlicerConfiguration
|
||||
{
|
||||
public class ColorField : UIField
|
||||
{
|
||||
public static readonly int VectorXYEditWidth = (int)(60 * GuiWidget.DeviceScale + .5);
|
||||
|
||||
private ItemColorButton colorWidget;
|
||||
private ThemeConfig theme;
|
||||
private Color initialColor;
|
||||
|
||||
public ColorField(ThemeConfig theme, Color initialColor)
|
||||
{
|
||||
this.theme = theme;
|
||||
this.initialColor = initialColor;
|
||||
}
|
||||
|
||||
public Color Color
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Color(colorWidget.Color);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
colorWidget.Color = value;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Initialize(int tabIndex)
|
||||
{
|
||||
var container = new FlowLayoutWidget();
|
||||
|
||||
colorWidget = new ItemColorButton(theme, initialColor);
|
||||
colorWidget.ColorChanged += (s, e) =>
|
||||
{
|
||||
base.OnValueChanged(new FieldChangedEventArgs(true));
|
||||
};
|
||||
|
||||
container.AddChild(colorWidget);
|
||||
|
||||
this.Content = container;
|
||||
}
|
||||
|
||||
protected override string ConvertValue(string newValue)
|
||||
{
|
||||
// Ensure we have a two value CSV or force to '0,0'
|
||||
return (newValue?.Split(',').Length == 2) ? newValue.Trim() : "0,0";
|
||||
}
|
||||
|
||||
protected override void OnValueChanged(FieldChangedEventArgs fieldChangedEventArgs)
|
||||
{
|
||||
colorWidget.Color = new Color(this.Value);
|
||||
|
||||
base.OnValueChanged(fieldChangedEventArgs);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue