private async void EditComplete(object s, EventArgs e) { var newWidth = xValueDisplayInfo.Value != 0 ? xValueDisplayInfo.Value : scaleController.FinalState.Width; var newDepth = yValueDisplayInfo.Value != 0 ? yValueDisplayInfo.Value : scaleController.FinalState.Depth; if (newWidth == scaleController.FinalState.Width && newDepth == scaleController.FinalState.Depth) { return; } var lockedEdge = ObjectSpace.GetCornerPosition(ActiveSelectedItem, quadrantIndex + 2); scaleController.ScaleWidthDepth(newWidth, newDepth); await ActiveSelectedItem.Rebuild(); // and keep the locked edge in place var newLockedEdge = ObjectSpace.GetCornerPosition(ActiveSelectedItem, quadrantIndex + 2); ActiveSelectedItem.Translate(lockedEdge - newLockedEdge); scaleController.EditComplete(); // make a new controller so we will have new undo data scaleController = new ScaleController(Object3DControlContext, getWidth, setWidth, getDepth, setDepth, getHeight, setHeight); }
public override void OnMouseDown(Mouse3DEventArgs mouseEvent3D) { var selectedItem = RootSelection; ActiveSelectedItem = selectedItem; if (mouseEvent3D.MouseEvent2D.Button == MouseButtons.Left && mouseEvent3D.info != null && selectedItem != null) { hadClickOnControl = true; xValueDisplayInfo.Visible = true; yValueDisplayInfo.Visible = true; var edge0 = ObjectSpace.GetEdgePosition(selectedItem, quadrantIndex); var edge1 = ObjectSpace.GetEdgePosition(selectedItem, quadrantIndex + 1); var edge3 = ObjectSpace.GetEdgePosition(selectedItem, quadrantIndex + 2); var normal01 = (edge1 - edge0).GetNormal(); var normal03 = (edge3 - edge0).GetNormal(); var planeNormal = normal01.Cross(normal03).GetNormal(); hitPlane = new PlaneShape(new Plane(planeNormal, edge0), null); initialHitPosition = mouseEvent3D.info.HitPosition; scaleController = new ScaleController(Object3DControlContext, getWidth, setWidth, getDepth, setDepth, getHeight, setHeight); Object3DControlContext.Scene.ShowSelectionShadow = false; } base.OnMouseDown(mouseEvent3D); }
public override void OnMouseDown(Mouse3DEventArgs mouseEvent3D) { if (mouseEvent3D.info != null && mouseEvent3D.MouseEvent2D.Button == MouseButtons.Left && Object3DControlContext.Scene.SelectedItem != null) { hadClickOnControl = true; activeSelectedItem = RootSelection; heightValueDisplayInfo.Visible = true; var selectedItem = activeSelectedItem; var bottomPosition = GetBottomPosition(selectedItem); var topPosition = GetTopPosition(selectedItem); originalPointToMove = topPosition; var upNormal = (topPosition - bottomPosition).GetNormal(); var sideNormal = upNormal.Cross(mouseEvent3D.MouseRay.directionNormal).GetNormal(); var planeNormal = upNormal.Cross(sideNormal).GetNormal(); hitPlane = new PlaneShape(new Plane(planeNormal, mouseEvent3D.info.HitPosition), null); initialHitPosition = mouseEvent3D.info.HitPosition; scaleController = new ScaleController(Object3DControlContext, getWidth, setWidth, getDepth, setDepth, getHeight, setHeight, getDiameters, setDiameters); Object3DControlContext.Scene.ShowSelectionShadow = false; } base.OnMouseDown(mouseEvent3D); }
public override void OnMouseDown(Mouse3DEventArgs mouseEvent3D) { var selectedItem = RootSelection; ActiveSelectedItem = selectedItem; if (mouseEvent3D.MouseEvent2D.Button == MouseButtons.Left && mouseEvent3D.info != null && selectedItem != null) { hadClickOnControl = true; diameterValueDisplayInfo.Visible = true; var(edge, otherSide) = GetHitPosition(selectedItem); var upNormal = (edge - otherSide).GetNormal(); var sideNormal = upNormal.Cross(mouseEvent3D.MouseRay.directionNormal).GetNormal(); var planeNormal = upNormal.Cross(sideNormal).GetNormal(); hitPlane = new PlaneShape(new Plane(planeNormal, mouseEvent3D.info.HitPosition), null); initialHitPosition = mouseEvent3D.info.HitPosition; scaleController = new ScaleController(Object3DControlContext, null, null, null, null, getHeight, setHeight, getDiameters, setDiameters); Object3DControlContext.Scene.ShowSelectionShadow = false; } base.OnMouseDown(mouseEvent3D); }
public override void OnMouseUp(Mouse3DEventArgs mouseEvent3D) { if (MouseDownOnControl) { scaleController.EditComplete(); scaleController = new ScaleController(Object3DControlContext, getWidth, setWidth, getDepth, setDepth, getHeight, setHeight, getDiameters, setDiameters); Object3DControlContext.Scene.ShowSelectionShadow = true; } base.OnMouseUp(mouseEvent3D); }
public override void OnMouseUp(Mouse3DEventArgs mouseEvent3D) { if (hadClickOnControl) { if (getDiameters[diameterIndex]() != scaleController.InitialState.Diameters[diameterIndex]) { scaleController.EditComplete(); scaleController = new ScaleController(Object3DControlContext, null, null, null, null, getHeight, setHeight, getDiameters, setDiameters); } Object3DControlContext.Scene.ShowSelectionShadow = true; } base.OnMouseUp(mouseEvent3D); }
public override void OnMouseUp(Mouse3DEventArgs mouseEvent3D) { if (hadClickOnControl) { if (getWidth() != scaleController.InitialState.Width || getDepth() != scaleController.InitialState.Depth) { scaleController.EditComplete(); // make a new controller so we will have new undo data scaleController = new ScaleController(Object3DControlContext, getWidth, setWidth, getDepth, setDepth, getHeight, setHeight); } Object3DControlContext.Scene.ShowSelectionShadow = true; } base.OnMouseUp(mouseEvent3D); }
public ScaleWidthDepthCornerControl(IObject3DControlContext object3DControlContext, Func <double> getWidth, Action <double> setWidth, Func <double> getDepth, Action <double> setDepth, Func <double> getHeight, Action <double> setHeight, int quadrant) : base(object3DControlContext) { theme = MatterControl.AppContext.Theme; this.getWidth = getWidth; this.setWidth = setWidth; this.getDepth = getDepth; this.setDepth = setDepth; this.getHeight = getHeight; this.setHeight = setHeight; scaleController = new ScaleController(object3DControlContext, getWidth, setWidth, getDepth, setDepth, getHeight, setHeight); xValueDisplayInfo = new InlineEditControl() { ForceHide = ForceHideScale, GetDisplayString = (value) => "{0:0.0}".FormatWith(value), }; xValueDisplayInfo.EditComplete += EditComplete; xValueDisplayInfo.VisibleChanged += (s, e) => { if (!xValueDisplayInfo.Visible) { hadClickOnControl = false; } }; yValueDisplayInfo = new InlineEditControl() { ForceHide = ForceHideScale, GetDisplayString = (value) => "{0:0.0}".FormatWith(value) }; yValueDisplayInfo.EditComplete += EditComplete; yValueDisplayInfo.VisibleChanged += (s, e) => { if (!yValueDisplayInfo.Visible) { hadClickOnControl = false; } }; Object3DControlContext.GuiSurface.AddChild(xValueDisplayInfo); Object3DControlContext.GuiSurface.AddChild(yValueDisplayInfo); this.quadrantIndex = quadrant; DrawOnTop = true; minXminYMesh = PlatonicSolids.CreateCube(selectCubeSize, selectCubeSize, selectCubeSize); CollisionVolume = minXminYMesh.CreateBVHData(); Object3DControlContext.GuiSurface.BeforeDraw += Object3DControl_BeforeDraw; }
public ScaleHeightControl(IObject3DControlContext context, Func <double> getWidth, Action <double> setWidth, Func <double> getDepth, Action <double> setDepth, Func <double> getHeight, Action <double> setHeight, List <Func <double> > getDiameters = null, List <Action <double> > setDiameters = null) : base(context) { theme = MatterControl.AppContext.Theme; this.getWidth = getWidth; this.setWidth = setWidth; this.getDepth = getDepth; this.setDepth = setDepth; this.getHeight = getHeight; this.setHeight = setHeight; this.getDiameters = getDiameters; this.setDiameters = setDiameters; scaleController = new ScaleController(Object3DControlContext, getWidth, setWidth, getDepth, setDepth, getHeight, setHeight, getDiameters, setDiameters); heightValueDisplayInfo = new InlineEditControl() { ForceHide = () => { // if the selection changes if (RootSelection != activeSelectedItem) { return(true); } // if another control gets a hover if (Object3DControlContext.HoveredObject3DControl != this && Object3DControlContext.HoveredObject3DControl != null) { return(true); } // if we clicked on the control if (hadClickOnControl) { return(false); } return(false); }, GetDisplayString = (value) => "{0:0.0}".FormatWith(value) }; heightValueDisplayInfo.VisibleChanged += (s, e) => { if (!heightValueDisplayInfo.Visible) { hadClickOnControl = false; } }; heightValueDisplayInfo.EditComplete += async(s, e) => { if (heightValueDisplayInfo.Value == scaleController.FinalState.Height) { return; } var selectedItem = activeSelectedItem; var bottom = GetBottomPosition(selectedItem); scaleController.ScaleHeight(heightValueDisplayInfo.Value); await selectedItem.Rebuild(); var postScaleBottom = GetBottomPosition(selectedItem); selectedItem.Translate(bottom - postScaleBottom); scaleController.EditComplete(); scaleController = new ScaleController(Object3DControlContext, getWidth, setWidth, getDepth, setDepth, getHeight, setHeight, getDiameters, setDiameters); }; Object3DControlContext.GuiSurface.AddChild(heightValueDisplayInfo); DrawOnTop = true; topScaleMesh = PlatonicSolids.CreateCube(arrowSize, arrowSize, arrowSize); CollisionVolume = topScaleMesh.CreateBVHData(); Object3DControlContext.GuiSurface.BeforeDraw += Object3DControl_BeforeDraw; }
public ScaleDiameterControl(IObject3DControlContext context, Func <double> getHeight, Action <double> setHeight, List <Func <double> > getDiameters, List <Action <double> > setDiameters, int diameterIndex, ObjectSpace.Placement placement = ObjectSpace.Placement.Bottom, Func <bool> controlVisible = null, double angleOffset = 0) : base(context) { this.getHeight = getHeight; this.setHeight = setHeight; this.getDiameters = getDiameters; this.setDiameters = setDiameters; this.controlVisible = controlVisible; this.placement = placement; this.diameterIndex = diameterIndex; this.angleOffset = angleOffset; theme = MatterControl.AppContext.Theme; scaleController = new ScaleController(Object3DControlContext, null, null, null, null, getHeight, setHeight, getDiameters, setDiameters); diameterValueDisplayInfo = new InlineEditControl() { ForceHide = ForceHideScale, GetDisplayString = (value) => "{0:0.0}".FormatWith(value), }; diameterValueDisplayInfo.EditComplete += async(s, e) => { var newDiameter = diameterValueDisplayInfo.Value != 0 ? diameterValueDisplayInfo.Value : getDiameters[diameterIndex](); if (newDiameter == scaleController.FinalState.Diameters[diameterIndex]) { return; } Vector3 lockedEdge = ObjectSpace.GetCenterPosition(ActiveSelectedItem, placement); scaleController.ScaleDiameter(newDiameter, diameterIndex); await ActiveSelectedItem.Rebuild(); // and keep the locked edge in place Vector3 newLockedEdge = ObjectSpace.GetCenterPosition(ActiveSelectedItem, placement); ActiveSelectedItem.Translate(lockedEdge - newLockedEdge); scaleController.EditComplete(); scaleController = new ScaleController(Object3DControlContext, null, null, null, null, getHeight, setHeight, getDiameters, setDiameters); }; diameterValueDisplayInfo.VisibleChanged += (s, e) => { if (!diameterValueDisplayInfo.Visible) { hadClickOnControl = false; } }; Object3DControlContext.GuiSurface.AddChild(diameterValueDisplayInfo); DrawOnTop = true; grabControlMesh = SphereObject3D.CreateSphere(grabControlSize, 15, 10); CollisionVolume = grabControlMesh.CreateBVHData(); Object3DControlContext.GuiSurface.BeforeDraw += Object3DControl_BeforeDraw; }
public ScaleWidthDepthEdgeControl(IObject3DControlContext context, Func <double> getWidth, Action <double> setWidth, Func <double> getDepth, Action <double> setDepth, Func <double> getHeight, Action <double> setHeight, int edgeIndex) : base(context) { theme = MatterControl.AppContext.Theme; switch (edgeIndex) { case 0: Name = "ScaleDepthBack"; break; case 1: Name = "ScaleWidthLeft"; break; case 2: Name = "ScaleDepthFront"; break; case 3: Name = "ScaleWidthRight"; break; } this.getWidth = getWidth; this.setWidth = setWidth; this.getDepth = getDepth; this.setDepth = setDepth; this.getHeight = getHeight; this.setHeight = setHeight; scaleController = new ScaleController(Object3DControlContext, getWidth, setWidth, getDepth, setDepth, getHeight, setHeight); xValueDisplayInfo = new InlineEditControl() { ForceHide = ForceHideScale, GetDisplayString = (value) => "{0:0.0}".FormatWith(value), Name = "XValueDisplay", }; xValueDisplayInfo.EditComplete += EditComplete; xValueDisplayInfo.VisibleChanged += (s, e) => { if (!xValueDisplayInfo.Visible) { hadClickOnControl = false; } }; yValueDisplayInfo = new InlineEditControl() { ForceHide = ForceHideScale, GetDisplayString = (value) => "{0:0.0}".FormatWith(value), Name = "YValueDisplay", }; yValueDisplayInfo.EditComplete += EditComplete; yValueDisplayInfo.VisibleChanged += (s, e) => { if (!yValueDisplayInfo.Visible) { hadClickOnControl = false; } }; if (edgeIndex % 2 == 1) { Object3DControlContext.GuiSurface.AddChild(xValueDisplayInfo); } else { Object3DControlContext.GuiSurface.AddChild(yValueDisplayInfo); } this.edgeIndex = edgeIndex; DrawOnTop = true; minXminYMesh = PlatonicSolids.CreateCube(selectCubeSize, selectCubeSize, selectCubeSize); CollisionVolume = minXminYMesh.CreateBVHData(); Object3DControlContext.GuiSurface.BeforeDraw += Object3DControl_BeforeDraw; }