コード例 #1
0
        public override async void OnMouseMove(Mouse3DEventArgs mouseEvent3D, bool mouseIsOver)
        {
            var selectedItem = RootSelection;

            activeSelectedItem = selectedItem;
            if (MouseIsOver)
            {
                heightValueDisplayInfo.Visible = true;
            }
            else if (!hadClickOnControl)
            {
                heightValueDisplayInfo.Visible = false;
            }

            if (MouseDownOnControl)
            {
                IntersectInfo info = hitPlane.GetClosestIntersection(mouseEvent3D.MouseRay);

                if (info != null &&
                    selectedItem != null)
                {
                    var delta = info.HitPosition - initialHitPosition;

                    var bottom = GetBottomPosition(selectedItem);
                    var top    = GetTopPosition(selectedItem);

                    var up = top - bottom;

                    var newPosition = originalPointToMove + delta;

                    var    newSize          = (newPosition - bottom).Length;
                    double snapGridDistance = Object3DControlContext.SnapGridDistance;
                    // if we are about to scale the object to less than 0
                    if (up.Dot(info.HitPosition - bottom) < 0)
                    {
                        newSize = .001;
                    }

                    if (snapGridDistance > 0)
                    {
                        newSize = System.Math.Max(newSize, snapGridDistance);
                        // snap this position to the grid
                        newSize = ((int)((newSize / snapGridDistance) + .5)) * snapGridDistance;
                    }

                    scaleController.ScaleHeight(newSize);

                    await selectedItem.Rebuild();

                    var postScaleBottom = GetBottomPosition(selectedItem);

                    selectedItem.Translate(bottom - postScaleBottom);

                    Invalidate();
                }
            }

            base.OnMouseMove(mouseEvent3D, mouseIsOver);
        }
コード例 #2
0
        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;
        }