Set solid color when clicked

put in gray colors
This commit is contained in:
Lars Brubaker 2017-07-28 17:02:39 -07:00
parent 2f6c47f71e
commit 318c14c5f9
2 changed files with 32 additions and 19 deletions

View file

@ -40,42 +40,50 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
public class CollorSwatchSelector : FlowLayoutWidget
{
private TextImageButtonFactory menuButtonFactory;
int colorSize = 32;
public CollorSwatchSelector(IObject3D item, View3DWidget view3DWidget, TextImageButtonFactory menuButtonFactory)
: base(FlowDirection.TopToBottom)
{
this.menuButtonFactory = menuButtonFactory;
var colorSize = 32;
var colorCount = 9;
double[] lightness = new double[] { .7, .5, .3 };
for (int lightnessIndex = 0; lightnessIndex < lightness.Length; lightnessIndex++)
RGBA_Bytes[] grayLevel = new RGBA_Bytes[] { RGBA_Bytes.White, new RGBA_Bytes(180, 180, 180), RGBA_Bytes.Gray };
for (int rowIndex = 0; rowIndex < lightness.Length; rowIndex++)
{
var colorRow = new FlowLayoutWidget();
AddChild(colorRow);
for (int colorIndex = 0; colorIndex < colorCount; colorIndex++)
{
Button button;
GuiWidget colorWidget;
colorRow.AddChild(button = new Button(colorWidget = new GuiWidget()
{
BackgroundColor = RGBA_Floats.FromHSL(colorIndex / (double)colorCount,
1, lightness[lightnessIndex]).GetAsRGBA_Bytes(),
Width = colorSize,
Height = colorSize,
}));
button.Click += (s, e) =>
{
item.Color = colorWidget.BackgroundColor;
item.OutputType = PrintOutputTypes.Solid;
view3DWidget.Invalidate();
};
var color = RGBA_Floats.FromHSL(colorIndex / (double)colorCount, 1, lightness[rowIndex]).GetAsRGBA_Bytes();
colorRow.AddChild(MakeColorButton(item, view3DWidget, color));
}
// put in white and black buttons
colorRow.AddChild(MakeColorButton(item, view3DWidget, grayLevel[rowIndex]));
}
}
private Button MakeColorButton(IObject3D item, View3DWidget view3DWidget, RGBA_Bytes color)
{
GuiWidget colorWidget;
var button = new Button(colorWidget = new GuiWidget()
{
BackgroundColor = color,
Width = colorSize,
Height = colorSize,
});
button.Click += (s, e) =>
{
item.Color = colorWidget.BackgroundColor;
item.OutputType = PrintOutputTypes.Solid;
view3DWidget.Invalidate();
};
return button;
}
}
public class PartColorSettings : PopupButton
@ -95,6 +103,11 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
VAnchor = VAnchor.FitToChildren,
BackgroundColor = RGBA_Bytes.White
};
Click += (s, e) =>
{
item.OutputType = PrintOutputTypes.Solid;
};
}
}