2016-02-16 08:30:13 -08: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;
|
2022-07-15 17:28:39 -07:00
|
|
|
|
using MatterHackers.Agg.UI;
|
2017-03-15 16:17:06 -07:00
|
|
|
|
using MatterHackers.DataConverters3D;
|
2016-02-16 08:30:13 -08:00
|
|
|
|
using MatterHackers.MeshVisualizer;
|
|
|
|
|
|
using MatterHackers.PolygonMesh;
|
|
|
|
|
|
using MatterHackers.RenderOpenGl;
|
|
|
|
|
|
using MatterHackers.VectorMath;
|
|
|
|
|
|
|
|
|
|
|
|
namespace MatterHackers.MatterControl.PartPreviewWindow
|
|
|
|
|
|
{
|
2020-09-12 13:09:17 -07:00
|
|
|
|
public class SelectionShadow : Object3DControl
|
2016-02-16 08:30:13 -08:00
|
|
|
|
{
|
2020-09-13 08:32:43 -07:00
|
|
|
|
private static Mesh normalShadowMesh;
|
2017-04-07 11:54:53 -07:00
|
|
|
|
|
2019-04-26 18:51:45 -07:00
|
|
|
|
private Color shadowColor;
|
|
|
|
|
|
|
2020-09-13 08:32:43 -07:00
|
|
|
|
private readonly ThemeConfig theme;
|
2016-02-16 08:30:13 -08:00
|
|
|
|
|
2020-09-11 19:59:14 -07:00
|
|
|
|
public SelectionShadow(IObject3DControlContext context)
|
2017-07-12 22:12:08 -07:00
|
|
|
|
: base(context)
|
2016-02-16 08:30:13 -08:00
|
|
|
|
{
|
2019-04-26 18:51:45 -07:00
|
|
|
|
theme = AppContext.Theme;
|
|
|
|
|
|
shadowColor = theme.ResolveColor(theme.BackgroundColor, Color.Black.WithAlpha(80)).WithAlpha(110);
|
2016-02-16 08:30:13 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-12 19:44:18 -07:00
|
|
|
|
public override void SetPosition(IObject3D selectedItem, MeshSelectInfo selectInfo)
|
2016-02-16 08:30:13 -08:00
|
|
|
|
{
|
2019-05-21 07:27:58 -07:00
|
|
|
|
AxisAlignedBoundingBox selectedBounds = selectedItem.GetAxisAlignedBoundingBox();
|
2016-02-16 08:30:13 -08:00
|
|
|
|
Vector3 boundsCenter = selectedBounds.Center;
|
|
|
|
|
|
|
2017-10-31 12:51:16 -07:00
|
|
|
|
TotalTransform = Matrix4X4.CreateTranslation(new Vector3(boundsCenter.X, boundsCenter.Y, 0.1));
|
2016-02-16 08:30:13 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-13 08:32:43 -07:00
|
|
|
|
private Mesh GetNormalShadowMesh()
|
2017-04-07 11:54:53 -07:00
|
|
|
|
{
|
2019-05-18 08:48:23 -07:00
|
|
|
|
if (normalShadowMesh == null)
|
2017-04-07 11:54:53 -07:00
|
|
|
|
{
|
|
|
|
|
|
normalShadowMesh = PlatonicSolids.CreateCube(1, 1, .1);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return normalShadowMesh;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-11 19:59:14 -07:00
|
|
|
|
public override void Draw(DrawGlContentEventArgs e)
|
2016-02-16 08:30:13 -08:00
|
|
|
|
{
|
2018-08-08 14:00:35 -07:00
|
|
|
|
var selectedItem = RootSelection;
|
2018-06-05 13:38:25 -07:00
|
|
|
|
if (selectedItem != null
|
2020-09-12 09:51:43 -07:00
|
|
|
|
&& Object3DControlContext.Scene.ShowSelectionShadow)
|
2016-02-16 08:30:13 -08:00
|
|
|
|
{
|
|
|
|
|
|
// draw the bounds on the bed
|
2019-05-21 07:27:58 -07:00
|
|
|
|
AxisAlignedBoundingBox selectedBounds = selectedItem.GetAxisAlignedBoundingBox();
|
2016-02-16 08:30:13 -08:00
|
|
|
|
|
2017-04-07 11:54:53 -07:00
|
|
|
|
var withScale = Matrix4X4.CreateScale(selectedBounds.XSize, selectedBounds.YSize, 1) * TotalTransform;
|
2019-04-26 18:51:45 -07:00
|
|
|
|
GLHelper.Render(GetNormalShadowMesh(), shadowColor, withScale, RenderTypes.Shaded);
|
2016-02-16 08:30:13 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-11 19:59:14 -07:00
|
|
|
|
base.Draw(e);
|
2016-02-16 08:30:13 -08:00
|
|
|
|
}
|
2020-09-12 19:44:18 -07:00
|
|
|
|
|
2022-03-02 00:52:04 +00:00
|
|
|
|
public override AxisAlignedBoundingBox GetWorldspaceAABB()
|
|
|
|
|
|
{
|
|
|
|
|
|
var selectedItem = RootSelection;
|
|
|
|
|
|
if (selectedItem != null
|
|
|
|
|
|
&& Object3DControlContext.Scene.ShowSelectionShadow)
|
|
|
|
|
|
{
|
|
|
|
|
|
AxisAlignedBoundingBox selectedBounds = selectedItem.GetAxisAlignedBoundingBox();
|
|
|
|
|
|
var withScale = Matrix4X4.CreateScale(selectedBounds.XSize, selectedBounds.YSize, 1) * TotalTransform;
|
|
|
|
|
|
return GetNormalShadowMesh().GetAxisAlignedBoundingBox().NewTransformed(withScale);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return AxisAlignedBoundingBox.Empty();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-12 19:44:18 -07:00
|
|
|
|
public override void Dispose()
|
|
|
|
|
|
{
|
|
|
|
|
|
// no widgets allocated so nothing to close
|
|
|
|
|
|
}
|
2021-05-01 22:06:43 -07:00
|
|
|
|
|
|
|
|
|
|
public override void CancelOperation()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
2016-02-16 08:30:13 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|