2015-08-15 16:38:07 -07:00
|
|
|
|
/*
|
|
|
|
|
|
Copyright (c) 2014, Lars Brubaker
|
|
|
|
|
|
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;
|
2014-05-25 11:11:11 -07:00
|
|
|
|
using MatterHackers.Agg.UI;
|
|
|
|
|
|
using MatterHackers.MeshVisualizer;
|
|
|
|
|
|
using MatterHackers.VectorMath;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.IO;
|
2015-08-15 16:38:07 -07:00
|
|
|
|
using MatterHackers.Localizations;
|
2014-05-25 11:11:11 -07:00
|
|
|
|
|
|
|
|
|
|
namespace MatterHackers.MatterControl.PartPreviewWindow
|
|
|
|
|
|
{
|
2015-04-08 15:20:10 -07:00
|
|
|
|
public class ViewControls3D : FlowLayoutWidget
|
|
|
|
|
|
{
|
|
|
|
|
|
private GuiWidget partSelectSeparator;
|
|
|
|
|
|
private MeshViewerWidget meshViewerWidget;
|
|
|
|
|
|
|
|
|
|
|
|
public RadioButton translateButton;
|
|
|
|
|
|
public RadioButton rotateButton;
|
|
|
|
|
|
public RadioButton scaleButton;
|
|
|
|
|
|
public RadioButton partSelectButton;
|
|
|
|
|
|
private int buttonHeight;
|
|
|
|
|
|
|
|
|
|
|
|
public bool PartSelectVisible
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return partSelectSeparator.Visible; }
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
partSelectSeparator.Visible = value;
|
|
|
|
|
|
partSelectButton.Visible = value;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public ViewControls3D(MeshViewerWidget meshViewerWidget)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (ActiveTheme.Instance.DisplayMode == ActiveTheme.ApplicationDisplayType.Touchscreen)
|
|
|
|
|
|
{
|
|
|
|
|
|
buttonHeight = 40;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
buttonHeight = 20;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.meshViewerWidget = meshViewerWidget;
|
|
|
|
|
|
TextImageButtonFactory textImageButtonFactory = new TextImageButtonFactory();
|
|
|
|
|
|
|
|
|
|
|
|
textImageButtonFactory.normalTextColor = ActiveTheme.Instance.PrimaryTextColor;
|
|
|
|
|
|
textImageButtonFactory.hoverTextColor = ActiveTheme.Instance.PrimaryTextColor;
|
|
|
|
|
|
textImageButtonFactory.disabledTextColor = ActiveTheme.Instance.PrimaryTextColor;
|
|
|
|
|
|
textImageButtonFactory.pressedTextColor = ActiveTheme.Instance.PrimaryTextColor;
|
|
|
|
|
|
|
|
|
|
|
|
BackgroundColor = new RGBA_Bytes(0, 0, 0, 120);
|
|
|
|
|
|
textImageButtonFactory.FixedHeight = buttonHeight;
|
|
|
|
|
|
textImageButtonFactory.FixedWidth = buttonHeight;
|
|
|
|
|
|
textImageButtonFactory.AllowThemeToAdjustImage = false;
|
|
|
|
|
|
textImageButtonFactory.checkedBorderColor = RGBA_Bytes.White;
|
|
|
|
|
|
|
|
|
|
|
|
string rotateIconPath = Path.Combine("ViewTransformControls", "rotate.png");
|
|
|
|
|
|
rotateButton = textImageButtonFactory.GenerateRadioButton("", rotateIconPath);
|
2015-08-17 09:33:31 -07:00
|
|
|
|
rotateButton.ToolTipText = "Rotate (Alt + L. Mouse)".Localize();
|
2015-08-15 16:38:07 -07:00
|
|
|
|
rotateButton.Margin = new BorderDouble(3);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
AddChild(rotateButton);
|
|
|
|
|
|
rotateButton.Click += (sender, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
meshViewerWidget.TrackballTumbleWidget.TransformState = TrackBallController.MouseDownType.Rotation;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
string translateIconPath = Path.Combine("ViewTransformControls", "translate.png");
|
|
|
|
|
|
translateButton = textImageButtonFactory.GenerateRadioButton("", translateIconPath);
|
2015-08-15 16:38:07 -07:00
|
|
|
|
translateButton.ToolTipText = "Move (Shift + L. Mouse)".Localize();
|
|
|
|
|
|
translateButton.Margin = new BorderDouble(3);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
AddChild(translateButton);
|
|
|
|
|
|
translateButton.Click += (sender, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
meshViewerWidget.TrackballTumbleWidget.TransformState = TrackBallController.MouseDownType.Translation;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
string scaleIconPath = Path.Combine("ViewTransformControls", "scale.png");
|
|
|
|
|
|
scaleButton = textImageButtonFactory.GenerateRadioButton("", scaleIconPath);
|
2015-08-17 09:33:31 -07:00
|
|
|
|
scaleButton.ToolTipText = "Zoom (Ctrl + L. Mouse)".Localize();
|
2015-08-15 16:38:07 -07:00
|
|
|
|
scaleButton.Margin = new BorderDouble(3);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
AddChild(scaleButton);
|
|
|
|
|
|
scaleButton.Click += (sender, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
meshViewerWidget.TrackballTumbleWidget.TransformState = TrackBallController.MouseDownType.Scale;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
partSelectSeparator = new GuiWidget(2, 32);
|
|
|
|
|
|
partSelectSeparator.BackgroundColor = RGBA_Bytes.White;
|
|
|
|
|
|
partSelectSeparator.Margin = new BorderDouble(3);
|
|
|
|
|
|
AddChild(partSelectSeparator);
|
|
|
|
|
|
|
|
|
|
|
|
string partSelectIconPath = Path.Combine("ViewTransformControls", "partSelect.png");
|
|
|
|
|
|
partSelectButton = textImageButtonFactory.GenerateRadioButton("", partSelectIconPath);
|
2015-08-15 16:38:07 -07:00
|
|
|
|
partSelectButton.ToolTipText = "Select Part".Localize();
|
|
|
|
|
|
partSelectButton.Margin = new BorderDouble(3);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
AddChild(partSelectButton);
|
|
|
|
|
|
partSelectButton.Click += (sender, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
meshViewerWidget.TrackballTumbleWidget.TransformState = TrackBallController.MouseDownType.None;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Margin = new BorderDouble(5);
|
|
|
|
|
|
HAnchor |= Agg.UI.HAnchor.ParentLeft;
|
|
|
|
|
|
VAnchor = Agg.UI.VAnchor.ParentTop;
|
|
|
|
|
|
rotateButton.Checked = true;
|
|
|
|
|
|
|
|
|
|
|
|
SetMeshViewerDisplayTheme();
|
|
|
|
|
|
partSelectButton.CheckedStateChanged += SetMeshViewerDisplayTheme;
|
|
|
|
|
|
|
|
|
|
|
|
ActiveTheme.Instance.ThemeChanged.RegisterEvent(ThemeChanged, ref unregisterEvents);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private event EventHandler unregisterEvents;
|
|
|
|
|
|
|
|
|
|
|
|
public override void OnClosed(EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (unregisterEvents != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
unregisterEvents(this, null);
|
|
|
|
|
|
}
|
|
|
|
|
|
base.OnClosed(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void ThemeChanged(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
SetMeshViewerDisplayTheme(null, null);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected void SetMeshViewerDisplayTheme(object sender = null, EventArgs e = null)
|
|
|
|
|
|
{
|
|
|
|
|
|
meshViewerWidget.TrackballTumbleWidget.RotationHelperCircleColor = ActiveTheme.Instance.PrimaryBackgroundColor;
|
|
|
|
|
|
|
|
|
|
|
|
//meshViewerWidget.MaterialColor = RGBA_Bytes.White;
|
|
|
|
|
|
//meshViewerWidget.SelectedMaterialColor = ActiveTheme.Instance.PrimaryAccentColor;
|
|
|
|
|
|
meshViewerWidget.BuildVolumeColor = new RGBA_Bytes(ActiveTheme.Instance.PrimaryAccentColor.Red0To255, ActiveTheme.Instance.PrimaryAccentColor.Green0To255, ActiveTheme.Instance.PrimaryAccentColor.Blue0To255, 50);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|