2015-08-15 16:38:07 -07:00
|
|
|
|
/*
|
2017-05-26 00:59:47 -07:00
|
|
|
|
Copyright (c) 2017, Lars Brubaker, John Lewin
|
2015-08-15 16:38:07 -07:00
|
|
|
|
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.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.IO;
|
2017-05-24 19:11:51 -07:00
|
|
|
|
using System.Linq;
|
2017-05-26 00:59:47 -07:00
|
|
|
|
using MatterHackers.Agg;
|
|
|
|
|
|
using MatterHackers.Agg.ImageProcessing;
|
|
|
|
|
|
using MatterHackers.Agg.PlatformAbstract;
|
|
|
|
|
|
using MatterHackers.Agg.UI;
|
|
|
|
|
|
using MatterHackers.Localizations;
|
2014-05-25 11:11:11 -07:00
|
|
|
|
|
|
|
|
|
|
namespace MatterHackers.MatterControl.PartPreviewWindow
|
|
|
|
|
|
{
|
2015-05-29 15:13:56 -07:00
|
|
|
|
public enum ViewControls3DButtons
|
|
|
|
|
|
{
|
|
|
|
|
|
Rotate,
|
|
|
|
|
|
Scale,
|
|
|
|
|
|
Translate,
|
|
|
|
|
|
PartSelect
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-05-25 17:58:20 -07:00
|
|
|
|
public class TransformStateChangedEventArgs : EventArgs
|
|
|
|
|
|
{
|
|
|
|
|
|
public ViewControls3DButtons TransformMode { get; set; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-05-26 00:59:47 -07:00
|
|
|
|
public class ViewControls3D : ViewControlsBase
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2017-05-26 00:59:47 -07:00
|
|
|
|
public event EventHandler ResetView;
|
|
|
|
|
|
public event EventHandler<TransformStateChangedEventArgs> TransformStateChanged;
|
|
|
|
|
|
|
|
|
|
|
|
internal OverflowDropdown OverflowButton;
|
|
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
private GuiWidget partSelectSeparator;
|
2015-11-09 12:36:47 -08:00
|
|
|
|
private Button resetViewButton;
|
|
|
|
|
|
|
2015-05-29 15:13:56 -07:00
|
|
|
|
private RadioButton translateButton;
|
|
|
|
|
|
private RadioButton rotateButton;
|
|
|
|
|
|
private RadioButton scaleButton;
|
|
|
|
|
|
private RadioButton partSelectButton;
|
|
|
|
|
|
|
2017-03-15 16:17:06 -07:00
|
|
|
|
private EventHandler unregisterEvents;
|
|
|
|
|
|
|
2017-05-26 00:59:47 -07:00
|
|
|
|
private ViewControls3DButtons activeTransformState = ViewControls3DButtons.Rotate;
|
|
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
public bool PartSelectVisible
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return partSelectSeparator.Visible; }
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
2017-07-05 13:55:38 -07:00
|
|
|
|
partSelectSeparator.Visible = false;
|
|
|
|
|
|
partSelectButton.Visible = false;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-05-29 15:13:56 -07:00
|
|
|
|
public ViewControls3DButtons ActiveButton
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return activeTransformState;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
this.activeTransformState = value;
|
2017-05-25 17:58:20 -07:00
|
|
|
|
switch (this.activeTransformState)
|
2015-05-29 15:13:56 -07:00
|
|
|
|
{
|
2017-05-25 17:58:20 -07:00
|
|
|
|
case ViewControls3DButtons.Rotate:
|
2017-07-05 13:55:38 -07:00
|
|
|
|
if (rotateButton != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
rotateButton.Checked = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-05-25 17:58:20 -07:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case ViewControls3DButtons.Translate:
|
2017-07-05 13:55:38 -07:00
|
|
|
|
if (translateButton != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
translateButton.Checked = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-05-25 17:58:20 -07:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case ViewControls3DButtons.Scale:
|
2017-07-05 13:55:38 -07:00
|
|
|
|
if (scaleButton != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
scaleButton.Checked = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-05-25 17:58:20 -07:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case ViewControls3DButtons.PartSelect:
|
|
|
|
|
|
partSelectButton.Checked = true;
|
|
|
|
|
|
break;
|
2015-05-29 15:13:56 -07:00
|
|
|
|
}
|
2017-05-25 17:58:20 -07:00
|
|
|
|
|
|
|
|
|
|
TransformStateChanged?.Invoke(this, new TransformStateChangedEventArgs()
|
|
|
|
|
|
{
|
|
|
|
|
|
TransformMode = activeTransformState
|
|
|
|
|
|
});
|
2015-05-29 15:13:56 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-05-25 17:58:20 -07:00
|
|
|
|
public ViewControls3D(TextImageButtonFactory buttonFactory)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2017-05-26 00:59:47 -07:00
|
|
|
|
this.BackgroundColor = new RGBA_Bytes(0, 0, 0, overlayAlpha);
|
|
|
|
|
|
this.HAnchor |= HAnchor.ParentLeft;
|
|
|
|
|
|
this.VAnchor = VAnchor.ParentTop;
|
|
|
|
|
|
|
2017-03-15 16:17:06 -07:00
|
|
|
|
string iconPath;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
2017-03-15 16:17:06 -07:00
|
|
|
|
iconPath = Path.Combine("ViewTransformControls", "reset.png");
|
2017-05-25 17:58:20 -07:00
|
|
|
|
resetViewButton = buttonFactory.Generate("", StaticData.Instance.LoadIcon(iconPath,32,32).InvertLightness());
|
2015-11-09 12:36:47 -08:00
|
|
|
|
resetViewButton.ToolTipText = "Reset View".Localize();
|
2017-03-15 16:17:06 -07:00
|
|
|
|
resetViewButton.Click += (s, e) => ResetView?.Invoke(this, null);
|
2017-05-24 19:11:51 -07:00
|
|
|
|
AddChild(resetViewButton);
|
2015-11-09 12:36:47 -08:00
|
|
|
|
|
2017-07-05 13:55:38 -07:00
|
|
|
|
if (UserSettings.Instance.IsTouchScreen)
|
|
|
|
|
|
{
|
|
|
|
|
|
iconPath = Path.Combine("ViewTransformControls", "rotate.png");
|
|
|
|
|
|
rotateButton = buttonFactory.GenerateRadioButton("", StaticData.Instance.LoadIcon(iconPath, 32, 32));
|
|
|
|
|
|
rotateButton.ToolTipText = "Rotate (Alt + Left Mouse)".Localize();
|
|
|
|
|
|
rotateButton.Margin = new BorderDouble(3);
|
|
|
|
|
|
rotateButton.Click += (s, e) => this.ActiveButton = ViewControls3DButtons.Rotate;
|
|
|
|
|
|
AddChild(rotateButton);
|
|
|
|
|
|
|
|
|
|
|
|
iconPath = Path.Combine("ViewTransformControls", "translate.png");
|
|
|
|
|
|
translateButton = buttonFactory.GenerateRadioButton("", StaticData.Instance.LoadIcon(iconPath, 32, 32));
|
|
|
|
|
|
translateButton.ToolTipText = "Move (Shift + Left Mouse)".Localize();
|
|
|
|
|
|
translateButton.Margin = new BorderDouble(3);
|
|
|
|
|
|
translateButton.Click += (s, e) => this.ActiveButton = ViewControls3DButtons.Translate;
|
|
|
|
|
|
AddChild(translateButton);
|
|
|
|
|
|
|
|
|
|
|
|
iconPath = Path.Combine("ViewTransformControls", "scale.png");
|
|
|
|
|
|
scaleButton = buttonFactory.GenerateRadioButton("", StaticData.Instance.LoadIcon(iconPath, 32, 32));
|
|
|
|
|
|
scaleButton.ToolTipText = "Zoom (Ctrl + Left Mouse)".Localize();
|
|
|
|
|
|
scaleButton.Margin = 3;
|
|
|
|
|
|
scaleButton.Click += (s, e) => this.ActiveButton = ViewControls3DButtons.Scale;
|
|
|
|
|
|
AddChild(scaleButton);
|
|
|
|
|
|
|
|
|
|
|
|
rotateButton.Checked = true;
|
|
|
|
|
|
}
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
|
|
|
|
|
partSelectSeparator = new GuiWidget(2, 32);
|
|
|
|
|
|
partSelectSeparator.BackgroundColor = RGBA_Bytes.White;
|
2017-05-22 18:17:35 -07:00
|
|
|
|
partSelectSeparator.Margin = 3;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
AddChild(partSelectSeparator);
|
|
|
|
|
|
|
2017-03-15 16:17:06 -07:00
|
|
|
|
iconPath = Path.Combine("ViewTransformControls", "partSelect.png");
|
2017-05-25 17:58:20 -07:00
|
|
|
|
partSelectButton = buttonFactory.GenerateRadioButton("", StaticData.Instance.LoadIcon(iconPath,32,32));
|
2017-05-22 18:17:35 -07:00
|
|
|
|
partSelectButton.ToolTipText = "Select Part".Localize();
|
2017-07-05 13:55:38 -07:00
|
|
|
|
partSelectButton.Visible = false;
|
2017-05-22 18:17:35 -07:00
|
|
|
|
partSelectButton.Margin = new BorderDouble(3);
|
2017-03-15 16:17:06 -07:00
|
|
|
|
partSelectButton.Click += (s, e) => this.ActiveButton = ViewControls3DButtons.PartSelect;
|
2017-05-24 19:11:51 -07:00
|
|
|
|
AddChild(partSelectButton);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
2017-05-24 19:11:51 -07:00
|
|
|
|
iconPath = Path.Combine("ViewTransformControls", "layers.png");
|
2017-05-25 17:58:20 -07:00
|
|
|
|
var layersButton = buttonFactory.Generate("", StaticData.Instance.LoadIcon(iconPath, 32, 32).InvertLightness());
|
2017-06-03 19:08:14 -07:00
|
|
|
|
layersButton.Name = "Toggle Layer View Button";
|
2017-05-24 19:11:51 -07:00
|
|
|
|
layersButton.ToolTipText = "Layers".Localize();
|
|
|
|
|
|
layersButton.Margin = 3;
|
|
|
|
|
|
layersButton.Click += (s, e) =>
|
|
|
|
|
|
{
|
2017-07-06 12:22:56 -07:00
|
|
|
|
var parentTabPage = this.Parents<PrinterTabPage>().First();
|
2017-05-24 19:11:51 -07:00
|
|
|
|
parentTabPage.ToggleView();
|
|
|
|
|
|
};
|
|
|
|
|
|
AddChild(layersButton);
|
|
|
|
|
|
|
2017-07-03 09:30:30 -07:00
|
|
|
|
OverflowButton = new OverflowDropdown(allowLightnessInvert: false)
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = "View3D Overflow Menu",
|
|
|
|
|
|
ToolTipText = "More...".Localize(),
|
|
|
|
|
|
Margin = 3
|
|
|
|
|
|
};
|
2017-05-26 00:23:20 -07:00
|
|
|
|
AddChild(OverflowButton);
|
2017-05-22 18:17:35 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-02-03 13:06:08 -08:00
|
|
|
|
public override void OnClosed(ClosedEventArgs e)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2017-03-15 16:17:06 -07:00
|
|
|
|
unregisterEvents?.Invoke(this, null);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
base.OnClosed(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|