Theme InteractionVolumes

This commit is contained in:
jlewin 2019-04-26 18:51:45 -07:00
parent 7ff2a32d68
commit d2e63ec814
9 changed files with 82 additions and 70 deletions

View file

@ -1,5 +1,5 @@
/*
Copyright (c) 2017, Lars Brubaker, John Lewin
Copyright (c) 2019, Lars Brubaker, John Lewin
All rights reserved.
Redistribution and use in source and binary forms, with or without
@ -37,15 +37,19 @@ namespace MatterHackers.MatterControl.CustomWidgets
public class InlineEditControl : GuiWidget
{
private TextWidget numberDisplay;
private NumberEdit numberEdit;
private MHNumberEdit numberEdit;
private Func<double, string> _getDisplayString = (value) => "{0:0.0}".FormatWith(value);
private RunningInterval runningInterval;
private ThemeConfig theme;
public InlineEditControl(string defaultSizeString = "-0000.00", Agg.Font.Justification justification = Agg.Font.Justification.Left)
{
theme = AppContext.Theme;
base.Visible = false;
double pointSize = 12;
numberDisplay = new TextWidget(defaultSizeString, 0, 0, pointSize, justification: justification)
numberDisplay = new TextWidget(defaultSizeString, 0, 0, pointSize, justification: justification, textColor: theme.TextColor)
{
Visible = false,
VAnchor = VAnchor.Bottom,
@ -54,21 +58,21 @@ namespace MatterHackers.MatterControl.CustomWidgets
};
AddChild(numberDisplay);
numberEdit = new NumberEdit(0, 50, 50, pointSize, pixelWidth: numberDisplay.Width, allowNegatives: true, allowDecimals: true)
numberEdit = new MHNumberEdit(0, theme, pixelWidth: numberDisplay.Width, allowNegatives: true, allowDecimals: true)
{
Visible = false,
VAnchor = VAnchor.Bottom,
HAnchor = HAnchor.Left,
SelectAllOnFocus = true,
};
numberEdit.InternalNumberEdit.TextChanged += (s, e) =>
numberEdit.ActuallNumberEdit.InternalNumberEdit.TextChanged += (s, e) =>
{
numberDisplay.Text = GetDisplayString == null ? "None" : GetDisplayString.Invoke(Value);
base.OnTextChanged(e);
};
numberEdit.InternalNumberEdit.MaxDecimalsPlaces = 2;
numberEdit.ActuallNumberEdit.InternalNumberEdit.MaxDecimalsPlaces = 2;
numberEdit.EditComplete += (s, e) =>
numberEdit.ActuallNumberEdit.EditComplete += (s, e) =>
{
EditComplete?.Invoke(this, e);
timeSinceMouseUp.Restart();
@ -84,8 +88,6 @@ namespace MatterHackers.MatterControl.CustomWidgets
runningInterval = UiThread.SetInterval(HideIfApplicable, .1);
}
public Color TextColor { get; set; } = Color.Black;
public event EventHandler EditComplete;
public bool Editing
@ -98,9 +100,6 @@ namespace MatterHackers.MatterControl.CustomWidgets
public Func<bool> ForceHide { get; set; }
private Func<double, string> _getDisplayString = (value) => "{0:0.0}".FormatWith(value);
private RunningInterval runningInterval;
public Func<double, string> GetDisplayString
{
get => _getDisplayString;
@ -154,26 +153,13 @@ namespace MatterHackers.MatterControl.CustomWidgets
{
numberEdit.Visible = false;
numberDisplay.Visible = true;
Invalidate();
}
protected double SecondsToShowNumberEdit { get; private set; } = 4;
protected Stopwatch timeSinceMouseUp { get; private set; } = new Stopwatch();
public override void OnDraw(Graphics2D graphics2D)
{
if (UnderMouseState == UnderMouseState.UnderMouseNotFirst
|| UnderMouseState == UnderMouseState.FirstUnderMouse)
{
numberDisplay.TextColor = Color.Red;
}
else
{
numberDisplay.TextColor = this.TextColor;
}
base.OnDraw(graphics2D);
}
public override void OnMouseDown(MouseEventArgs mouseEvent)
{
if (mouseEvent.Button == MouseButtons.Left
@ -188,6 +174,27 @@ namespace MatterHackers.MatterControl.CustomWidgets
base.OnMouseDown(mouseEvent);
}
public override void OnMouseMove(MouseEventArgs mouseEvent)
{
if (UnderMouseState == UnderMouseState.UnderMouseNotFirst
|| UnderMouseState == UnderMouseState.FirstUnderMouse)
{
if (numberDisplay.TextColor != theme.PrimaryAccentColor)
{
numberDisplay.TextColor = theme.PrimaryAccentColor;
}
}
else
{
if (numberDisplay.TextColor != theme.TextColor)
{
numberDisplay.TextColor = theme.TextColor;
}
}
base.OnMouseMove(mouseEvent);
}
public override void OnClosed(EventArgs e)
{
// Unregister listeners

View file

@ -54,7 +54,7 @@ namespace MatterHackers.Plugins.EditorTools
private readonly double arrowsOffset = 15;
private readonly double ringWidth = 20;
private ThemeConfig theme;
private InlineEditControl angleTextControl;
private double lastSnappedRotation = 0;
@ -68,6 +68,8 @@ namespace MatterHackers.Plugins.EditorTools
public RotateCornerControl(IInteractionVolumeContext context, int axisIndex)
: base(context)
{
theme = MatterControl.AppContext.Theme;
angleTextControl = new InlineEditControl()
{
ForceHide = ForceHideAngle,
@ -124,6 +126,7 @@ namespace MatterHackers.Plugins.EditorTools
{
rotationImageWhite = new ImageBuffer(64, 64, 32, new BlenderBGRA());
}
VertexSourceApplyTransform arrows2 = new VertexSourceApplyTransform(arrows, Affine.NewTranslation(-bounds.Center)
* Affine.NewScaling(rotationImageWhite.Width / bounds.Width, rotationImageWhite.Height / bounds.Height)
* Affine.NewTranslation(rotationImageWhite.Width / 2, rotationImageWhite.Height / 2));
@ -179,7 +182,7 @@ namespace MatterHackers.Plugins.EditorTools
// We only draw the rotation arrows when the user has not selected any interaction volumes (they are not actively scaling or rotating anything).
if (InteractionContext.SelectedInteractionVolume == null)
{
var color = MouseOver ? Color.Red : Color.Black;
var color = MouseOver ? theme.PrimaryAccentColor : theme.TextColor;
GLHelper.Render(rotationHandle, new Color(color, 254), TotalTransform, RenderTypes.Shaded);
}
@ -565,7 +568,7 @@ namespace MatterHackers.Plugins.EditorTools
{
IVertexSource blueRing = new JoinPaths(new Arc(0, 0, outerRadius, outerRadius, startBlue, endBlue, Arc.Direction.CounterClockWise),
new Arc(0, 0, innerRadius, innerRadius, startBlue, endBlue, Arc.Direction.ClockWise));
graphics2DOpenGL.RenderTransformedPath(rotationCenterTransform, blueRing, new Color(Color.Blue, (int)(50 * alphaValue)), drawEventArgs.ZBuffered);
graphics2DOpenGL.RenderTransformedPath(rotationCenterTransform, blueRing, new Color(theme.PrimaryAccentColor, (int)(50 * alphaValue)), drawEventArgs.ZBuffered);
// tick 60 marks
DrawTickMarks(drawEventArgs, alphaValue, rotationCenterTransform, innerRadius, outerRadius, 60);
}
@ -584,7 +587,7 @@ namespace MatterHackers.Plugins.EditorTools
IVertexSource redAngle = new JoinPaths(new Arc(0, 0, 0, 0, startRed, endRed, Arc.Direction.CounterClockWise),
new Arc(0, 0, innerRadius, innerRadius, startRed, endRed, Arc.Direction.ClockWise));
graphics2DOpenGL.RenderTransformedPath(rotationCenterTransform, redAngle, new Color(Color.Red, (int)(70 * alphaValue)), drawEventArgs.ZBuffered);
graphics2DOpenGL.RenderTransformedPath(rotationCenterTransform, redAngle, new Color(theme.PrimaryAccentColor, (int)(70 * alphaValue)), drawEventArgs.ZBuffered);
// draw a line to the mouse on the rotation circle
if (mouseMoveInfo != null && MouseDownOnControl)
@ -594,7 +597,7 @@ namespace MatterHackers.Plugins.EditorTools
var center = Vector3Ex.Transform(Vector3.Zero, rotationCenterTransform);
if ((mouseMoveInfo.HitPosition - center).Length > rotationTransformScale * innerRadius)
{
InteractionContext.World.Render3DLine(startPosition, mouseMoveInfo.HitPosition, Color.Red, drawEventArgs.ZBuffered);
InteractionContext.World.Render3DLine(startPosition, mouseMoveInfo.HitPosition, theme.PrimaryAccentColor, drawEventArgs.ZBuffered);
}
DrawSnappingMarks(drawEventArgs, mouseAngle, alphaValue, rotationCenterTransform, snappingMarkRadius, 5, numSnapPoints, GetSnapIndex(selectedItem, numSnapPoints));
@ -622,10 +625,10 @@ namespace MatterHackers.Plugins.EditorTools
var transformed = new VertexSourceApplyTransform(snapShape, Affine.NewTranslation(distanceFromCenter, 0) * Affine.NewRotation(startAngle));
// new Ellipse(startPosition.x, startPosition.y, dotRadius, dotRadius);
var color = Color.Black;
var color = theme.TextColor;
if (i == markToSnapTo)
{
color = Color.Red;
color = theme.PrimaryAccentColor;
}
graphics2DOpenGL.RenderTransformedPath(rotationCenterTransform, transformed, new Color(color, (int)(254 * alphaValue)), drawEventArgs.ZBuffered);
@ -644,7 +647,7 @@ namespace MatterHackers.Plugins.EditorTools
Vector3 startPosition = Vector3Ex.Transform(unitPosition * innerRadius, rotationCenterTransform);
Vector3 endPosition = Vector3Ex.Transform(unitPosition * outerRadius, rotationCenterTransform);
InteractionContext.World.Render3DLine(clippingFrustum, startPosition, endPosition, new Color(Color.Black, (int)(254 * alphaValue)), drawEventArgs.ZBuffered);
InteractionContext.World.Render3DLine(clippingFrustum, startPosition, endPosition, new Color(theme.TextColor, (int)(254 * alphaValue)), drawEventArgs.ZBuffered);
}
}

View file

@ -30,7 +30,6 @@ either expressed or implied, of the FreeBSD Project.
using System;
using System.Collections.Generic;
using MatterHackers.Agg;
using MatterHackers.Agg.Image;
using MatterHackers.Agg.UI;
using MatterHackers.DataConverters3D;
using MatterHackers.MatterControl;
@ -60,6 +59,7 @@ namespace MatterHackers.Plugins.EditorTools
private Vector3 originalPointToMove;
private int quadrantIndex;
private double selectCubeSize = 7 * GuiWidget.DeviceScale;
private ThemeConfig theme;
private InlineEditControl xValueDisplayInfo;
private InlineEditControl yValueDisplayInfo;
private bool HadClickOnControl;
@ -67,6 +67,8 @@ namespace MatterHackers.Plugins.EditorTools
public ScaleCornerControl(IInteractionVolumeContext context, int cornerIndex)
: base(context)
{
theme = MatterControl.AppContext.Theme;
xValueDisplayInfo = new InlineEditControl()
{
ForceHide = ForceHideScale,
@ -176,11 +178,11 @@ namespace MatterHackers.Plugins.EditorTools
// don't draw if any other control is dragging
if (MouseOver)
{
GLHelper.Render(minXminYMesh, Color.Red, TotalTransform, RenderTypes.Shaded);
GLHelper.Render(minXminYMesh, theme.PrimaryAccentColor, TotalTransform, RenderTypes.Shaded);
}
else
{
GLHelper.Render(minXminYMesh, Color.Black, TotalTransform, RenderTypes.Shaded);
GLHelper.Render(minXminYMesh, theme.TextColor, TotalTransform, RenderTypes.Shaded);
}
}
@ -196,20 +198,20 @@ namespace MatterHackers.Plugins.EditorTools
{
if (e.ZBuffered)
{
InteractionContext.World.Render3DLine(clippingFrustum, startPosition, endPosition, Color.Black);
InteractionContext.World.Render3DLine(clippingFrustum, startPosition, endPosition, theme.TextColor);
}
else
{
// render on top of everything very lightly
InteractionContext.World.Render3DLine(clippingFrustum, startPosition, endPosition, new Color(Color.Black, 20), false);
InteractionContext.World.Render3DLine(clippingFrustum, startPosition, endPosition, new Color(theme.TextColor, 20), false);
}
}
//Vector3 startScreenSpace = InteractionContext.World.GetScreenSpace(startPosition);
//e.graphics2D.Circle(startScreenSpace.x, startScreenSpace.y, 5, Color.Red);
//e.graphics2D.Circle(startScreenSpace.x, startScreenSpace.y, 5, theme.PrimaryAccentColor);
//Vector2 startScreenPosition = InteractionContext.World.GetScreenPosition(startPosition);
//e.graphics2D.Circle(startScreenPosition.x, startScreenPosition.y, 5, Color.Red);
//e.graphics2D.Circle(startScreenPosition.x, startScreenPosition.y, 5, theme.PrimaryAccentColor);
}
}
@ -508,12 +510,12 @@ namespace MatterHackers.Plugins.EditorTools
for (int i = 0; i < lines.Count; i += 2)
{
// draw the line that is on the ground
drawEvent.Graphics2D.Line(lines[i], lines[i + 1], Color.Black);
drawEvent.Graphics2D.Line(lines[i], lines[i + 1], theme.TextColor);
}
for (int i = 0; i < lines.Count; i += 4)
{
DrawMeasureLine(drawEvent.Graphics2D, (lines[i] + lines[i + 1]) / 2, (lines[i + 2] + lines[i + 3]) / 2, Color.Black, LineArrows.Both);
DrawMeasureLine(drawEvent.Graphics2D, (lines[i] + lines[i + 1]) / 2, (lines[i + 2] + lines[i + 3]) / 2, LineArrows.Both, theme);
}
int j = 4;

View file

@ -58,12 +58,15 @@ namespace MatterHackers.Plugins.EditorTools
private List<Vector2> lines = new List<Vector2>();
private Vector3 originalPointToMove;
private double selectCubeSize = 7 * GuiWidget.DeviceScale;
private ThemeConfig theme;
private InlineEditControl zValueDisplayInfo;
private bool HadClickOnControl;
public ScaleTopControl(IInteractionVolumeContext context)
: base(context)
{
theme = MatterControl.AppContext.Theme;
zValueDisplayInfo = new InlineEditControl()
{
ForceHide = () =>
@ -159,11 +162,11 @@ namespace MatterHackers.Plugins.EditorTools
// don't draw if any other control is dragging
if (MouseOver)
{
GLHelper.Render(topScaleMesh, Color.Red, TotalTransform, RenderTypes.Shaded);
GLHelper.Render(topScaleMesh, theme.PrimaryAccentColor, TotalTransform, RenderTypes.Shaded);
}
else
{
GLHelper.Render(topScaleMesh, Color.Black, TotalTransform, RenderTypes.Shaded);
GLHelper.Render(topScaleMesh, theme.TextColor, TotalTransform, RenderTypes.Shaded);
}
}
@ -188,12 +191,12 @@ namespace MatterHackers.Plugins.EditorTools
if (e.ZBuffered)
{
InteractionContext.World.Render3DLine(clippingFrustum, bottomPosition, topPosition, Color.Black);
InteractionContext.World.Render3DLine(clippingFrustum, bottomPosition, topPosition, theme.TextColor);
}
else
{
// render on top of everything very lightly
InteractionContext.World.Render3DLine(clippingFrustum, bottomPosition, topPosition, new Color(Color.Black, 20), false);
InteractionContext.World.Render3DLine(clippingFrustum, bottomPosition, topPosition, new Color(theme.TextColor, 20), false);
}
}
}
@ -350,12 +353,12 @@ namespace MatterHackers.Plugins.EditorTools
for (int i = 0; i < lines.Count; i += 2)
{
// draw the measure line
drawEvent.Graphics2D.Line(lines[i], lines[i + 1], Color.Black);
drawEvent.Graphics2D.Line(lines[i], lines[i + 1], theme.TextColor);
}
for (int i = 0; i < lines.Count; i += 4)
{
DrawMeasureLine(drawEvent.Graphics2D, (lines[i] + lines[i + 1]) / 2, (lines[i + 2] + lines[i + 3]) / 2, Color.Black, LineArrows.Both);
DrawMeasureLine(drawEvent.Graphics2D, (lines[i] + lines[i + 1]) / 2, (lines[i + 2] + lines[i + 3]) / 2, LineArrows.Both, theme);
}
int j = 0;

View file

@ -72,7 +72,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
currentLayerInfo = new InlineEditControl("1000")
{
Name = "currentLayerInfo",
TextColor = theme.TextColor,
GetDisplayString = (value) => $"{value}",
HAnchor = HAnchor.Right | HAnchor.Fit,
VAnchor = VAnchor.Absolute | VAnchor.Fit,

View file

@ -59,10 +59,12 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
private double upArrowSize = 7 * GuiWidget.DeviceScale;
private InlineEditControl zHeightDisplayInfo;
private bool HadClickOnControl;
private ThemeConfig theme;
public MoveInZControl(IInteractionVolumeContext context)
: base(context)
{
theme = AppContext.Theme;
Name = "MoveInZControl";
zHeightDisplayInfo = new InlineEditControl()
{
@ -162,11 +164,11 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
// don't draw if any other control is dragging
if (MouseOver)
{
GLHelper.Render(upArrowMesh, Color.Red, TotalTransform, RenderTypes.Shaded);
GLHelper.Render(upArrowMesh, theme.PrimaryAccentColor, TotalTransform, RenderTypes.Shaded);
}
else
{
GLHelper.Render(upArrowMesh, Color.Black, TotalTransform, RenderTypes.Shaded);
GLHelper.Render(upArrowMesh, theme.TextColor, TotalTransform, RenderTypes.Shaded);
}
}
}
@ -316,12 +318,12 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
for (int i = 0; i < lines.Count; i += 2)
{
// draw the measure line
drawEvent.Graphics2D.Line(lines[i], lines[i + 1], Color.Black);
drawEvent.Graphics2D.Line(lines[i], lines[i + 1], theme.TextColor);
}
for (int i = 0; i < lines.Count; i += 4)
{
DrawMeasureLine(drawEvent.Graphics2D, (lines[i] + lines[i + 1]) / 2, (lines[i + 2] + lines[i + 3]) / 2, Color.Black, LineArrows.Both);
DrawMeasureLine(drawEvent.Graphics2D, (lines[i] + lines[i + 1]) / 2, (lines[i + 2] + lines[i + 3]) / 2, LineArrows.Both, theme);
}
AxisAlignedBoundingBox selectedBounds = selectedItem.GetAxisAlignedBoundingBox(Matrix4X4.Identity);

View file

@ -28,32 +28,27 @@ either expressed or implied, of the FreeBSD Project.
*/
using MatterHackers.Agg;
using MatterHackers.Agg.Font;
using MatterHackers.Agg.Image;
using MatterHackers.Agg.Transform;
using MatterHackers.Agg.UI;
using MatterHackers.Agg.VertexSource;
using MatterHackers.DataConverters3D;
using MatterHackers.Localizations;
using MatterHackers.MeshVisualizer;
using MatterHackers.PolygonMesh;
using MatterHackers.RenderOpenGl;
using MatterHackers.RenderOpenGl.OpenGl;
using MatterHackers.VectorMath;
using System;
namespace MatterHackers.MatterControl.PartPreviewWindow
{
public class SelectionShadow : InteractionVolume
{
static Mesh normalShadowMesh;
static Color shadowColor = new Color(22, 80, 220);
readonly int shadowAlpha = 40;
private Color shadowColor;
private ThemeConfig theme;
public SelectionShadow(IInteractionVolumeContext context)
: base(context)
{
theme = AppContext.Theme;
shadowColor = theme.ResolveColor(theme.BackgroundColor, Color.Black.WithAlpha(80)).WithAlpha(110);
}
public override void SetPosition(IObject3D selectedItem)
@ -84,7 +79,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
AxisAlignedBoundingBox selectedBounds = selectedItem.GetAxisAlignedBoundingBox(Matrix4X4.Identity);
var withScale = Matrix4X4.CreateScale(selectedBounds.XSize, selectedBounds.YSize, 1) * TotalTransform;
GLHelper.Render(GetNormalShadowMesh(), new Color(shadowColor, shadowAlpha), withScale, RenderTypes.Shaded);
GLHelper.Render(GetNormalShadowMesh(), shadowColor, withScale, RenderTypes.Shaded);
}
base.DrawGlContent(e);

View file

@ -35,6 +35,7 @@ using MatterHackers.Agg.Transform;
using MatterHackers.Agg.UI;
using MatterHackers.Agg.VertexSource;
using MatterHackers.DataConverters3D;
using MatterHackers.MatterControl;
using MatterHackers.MatterControl.Extensibility;
using MatterHackers.RayTracer;
using MatterHackers.VectorMath;
@ -93,9 +94,9 @@ namespace MatterHackers.MeshVisualizer
}
}
public static void DrawMeasureLine(Graphics2D graphics2D, Vector2 lineStart, Vector2 lineEnd, Color color, LineArrows arrows)
public static void DrawMeasureLine(Graphics2D graphics2D, Vector2 lineStart, Vector2 lineEnd, LineArrows arrows, ThemeConfig theme)
{
graphics2D.Line(lineStart, lineEnd, Color.Black);
graphics2D.Line(lineStart, lineEnd, theme.TextColor);
Vector2 direction = lineEnd - lineStart;
if (direction.LengthSquared > 0
@ -110,14 +111,14 @@ namespace MatterHackers.MeshVisualizer
double rotation = Math.Atan2(direction.Y, direction.X);
IVertexSource correctRotation = new VertexSourceApplyTransform(arrow, Affine.NewRotation(rotation - MathHelper.Tau / 4));
IVertexSource inPosition = new VertexSourceApplyTransform(correctRotation, Affine.NewTranslation(lineEnd));
graphics2D.Render(inPosition, Color.Black);
graphics2D.Render(inPosition, theme.TextColor);
}
if (arrows.HasFlag(LineArrows.Start))
{
double rotation = Math.Atan2(direction.Y, direction.X) + MathHelper.Tau / 2;
IVertexSource correctRotation = new VertexSourceApplyTransform(arrow, Affine.NewRotation(rotation - MathHelper.Tau / 4));
IVertexSource inPosition = new VertexSourceApplyTransform(correctRotation, Affine.NewTranslation(lineStart));
graphics2D.Render(inPosition, Color.Black);
graphics2D.Render(inPosition, theme.TextColor);
}
}
}

@ -1 +1 @@
Subproject commit 3d00b5b3e4460807afee42114303f7e7fd65bddb
Subproject commit 4761011c1dabc91b747e4b15e1f31f0b65ac44b5