示例#1
0
        private void TestForPushingOnPolygonCorner()
        {
            Cursor cursor = GuiManager.Cursor;

            if (cursor.WindowOver != null)
            {
                return;
            }

            #region Primary Push
            if (cursor.PrimaryPush)
            {
                mCornerRectangleGrabbed = null;
                mCornerIndexGrabbed     = -1;
                mCornerIndexSelected    = -1;
                bool pushHandled = false;

                if (EditorData.EditingLogic.CurrentShapeCollection.Polygons.Count != 0)
                {
                    int rectangleNumber = 0;
                    // See if the user is over any of the corners
                    foreach (Polygon polygon in EditorData.EditingLogic.CurrentShapeCollection.Polygons)
                    {
                        for (int i = 0; i < polygon.Points.Count - 1; i++)
                        {
                            if (cursor.IsOn <AxisAlignedRectangle>(mCorners[rectangleNumber]))
                            {
                                mCornerIndexGrabbed     = i;
                                mCornerIndexSelected    = i;
                                mCornerRectangleGrabbed = mCorners[rectangleNumber];

                                pushHandled = true;
                                UndoManager.AddToWatch(polygon);
                                break;
                            }

                            rectangleNumber++;
                        }

                        if (pushHandled)
                        {
                            break;
                        }
                    }
                }
            }
            #endregion

            #region Primary Down

            if (this.mCornerRectangleGrabbed != null)
            {
                if (GuiData.ToolsWindow.IsMoveButtonPressed)
                {
                    Polygon parentPolygon = mCornerRectangleGrabbed.Parent as Polygon;

                    // Get the position of the cursor in object space
                    Vector3 newRelativePosition = new Vector3(cursor.WorldXAt(0), cursor.WorldYAt(0), 0);

                    newRelativePosition -= parentPolygon.Position;

                    Matrix invertedMatrix = parentPolygon.RotationMatrix;
#if FRB_MDX
                    invertedMatrix.Invert();
                    Vector4 temporary = Vector3.Transform(newRelativePosition, invertedMatrix);
#else
                    Matrix.Invert(ref invertedMatrix, out invertedMatrix);

                    Vector3 temporary = newRelativePosition;

                    MathFunctions.TransformVector(ref temporary, ref invertedMatrix);
#endif


                    mCornerRectangleGrabbed.RelativePosition = new Vector3(temporary.X, temporary.Y, 0);

                    parentPolygon.SetPoint(mCornerIndexGrabbed, mCornerRectangleGrabbed.RelativePosition.X,
                                           mCornerRectangleGrabbed.RelativePosition.Y);

                    if (mCornerIndexGrabbed == 0)
                    {
                        parentPolygon.SetPoint(
                            parentPolygon.Points.Count - 1,
                            mCornerRectangleGrabbed.RelativePosition.X,
                            mCornerRectangleGrabbed.RelativePosition.Y);
                    }
                }
            }

            #endregion

            #region Primary Release

            if (cursor.PrimaryClick)
            {
                if (mCornerRectangleGrabbed == null)
                {
                    mCornerIndexSelected = -1;
                }
                else
                {
                    UndoManager.RecordUndos <Polygon>();
                    UndoManager.ClearObjectsWatching <Polygon>();
                }

                mCornerRectangleGrabbed = null;
                mCornerIndexGrabbed     = -1;
            }

            #endregion
        }
        public void Activity()
        {
            #region if visible, SetCursorAndHandleColors according to what the cursor is over
            if (Visible)
            {
                SetCursorAndHandleDisplay();
            }
            #endregion

            #region if cursor.primaryPush, see if we are grabbing a handle
            if (cursor.PrimaryPush && Visible)
            {
                // see if the cursor is over any of the polys

                // Vic says: Talk about a hack - we check the color?  How lame is that.
                // I think we need to figure a different way to do this.


                foreach (Polygon lp in mSideHandles)
                {
                    if (lp.Color.ToArgb() != -256 && mHandleGrabbed != lp)
                    {
                        UndoManager.AddToWatch <SpriteGrid>(this.mParentSpriteGrid);
                        mHandleGrabbed = lp;
                    }
                }

                foreach (Polygon lp in mCornerHandles)
                {
                    if (lp.Color.ToArgb() != -256 && mHandleGrabbed != lp)
                    {
                        UndoManager.AddToWatch <SpriteGrid>(this.mParentSpriteGrid);
                        mHandleGrabbed = lp;
                    }
                }
            }
            #endregion

            #region if cursor.primaryDown and mHandleGrabbed, adjust the SpriteGrid bounds
            if (cursor.PrimaryDown && mHandleGrabbed != null &&
                (cursor.XVelocity != 0 || cursor.YVelocity != 0 ||
                 camera.XVelocity != 0 || camera.YVelocity != 0 || camera.ZVelocity != 0))
            {
                if (mHandleGrabbed == mSideHandles[1])
                {
                    mParentSpriteGrid.XRightBound = cursor.WorldXAt(mHandleGrabbed.Z);
                }
                else if (mHandleGrabbed == mSideHandles[3])
                {
                    mParentSpriteGrid.XLeftBound = cursor.WorldXAt(mHandleGrabbed.Z);
                }

                else if (mParentSpriteGrid.GridPlane == SpriteGrid.Plane.XY)
                {
                    if (mHandleGrabbed == mSideHandles[0])
                    {
                        mParentSpriteGrid.YTopBound = cursor.WorldYAt(mHandleGrabbed.Z);
                    }
                    else if (mHandleGrabbed == mSideHandles[2])
                    {
                        mParentSpriteGrid.YBottomBound = cursor.WorldYAt(mHandleGrabbed.Z);
                    }
                    else if (mHandleGrabbed == mCornerHandles[0])
                    {
                        mParentSpriteGrid.YTopBound  = cursor.WorldYAt(mHandleGrabbed.Z);
                        mParentSpriteGrid.XLeftBound = cursor.WorldXAt(mHandleGrabbed.Z);
                    }
                    else if (mHandleGrabbed == mCornerHandles[1])
                    {
                        mParentSpriteGrid.YTopBound   = cursor.WorldYAt(mHandleGrabbed.Z);
                        mParentSpriteGrid.XRightBound = cursor.WorldXAt(mHandleGrabbed.Z);
                    }
                    else if (mHandleGrabbed == mCornerHandles[2])
                    {
                        mParentSpriteGrid.YBottomBound = cursor.WorldYAt(mHandleGrabbed.Z);
                        mParentSpriteGrid.XRightBound  = cursor.WorldXAt(mHandleGrabbed.Z);
                    }
                    else if (mHandleGrabbed == mCornerHandles[3])
                    {
                        mParentSpriteGrid.YBottomBound = cursor.WorldYAt(mHandleGrabbed.Z);
                        mParentSpriteGrid.XLeftBound   = cursor.WorldXAt(mHandleGrabbed.Z);
                    }
                }
                else
                {
                    if (mHandleGrabbed == mSideHandles[0])
                    {
                        mParentSpriteGrid.ZFarBound += cursor.YVelocity;
                    }
                    else if (mHandleGrabbed == mSideHandles[2])
                    {
                        mParentSpriteGrid.ZCloseBound += cursor.YVelocity;
                    }
                    else if (mHandleGrabbed == mCornerHandles[0])
                    {
                        mParentSpriteGrid.ZFarBound += cursor.YVelocity;
                        mParentSpriteGrid.XLeftBound = cursor.WorldXAt(mHandleGrabbed.Z);
                    }
                    else if (mHandleGrabbed == mCornerHandles[1])
                    {
                        mParentSpriteGrid.ZFarBound  += cursor.YVelocity;
                        mParentSpriteGrid.XRightBound = cursor.WorldXAt(mHandleGrabbed.Z);
                    }
                    else if (mHandleGrabbed == mCornerHandles[2])
                    {
                        mParentSpriteGrid.ZCloseBound += cursor.YVelocity;
                        mParentSpriteGrid.XRightBound  = cursor.WorldXAt(mHandleGrabbed.Z);
                    }
                    else if (mHandleGrabbed == mCornerHandles[3])
                    {
                        mParentSpriteGrid.ZCloseBound += cursor.YVelocity;
                        mParentSpriteGrid.XLeftBound   = cursor.WorldXAt(mHandleGrabbed.Z);
                    }
                }

                if (mHandleGrabbed != null)
                {
                    SetLinePolygonPositions();
                }
            }

            #endregion

            if (cursor.PrimaryClick)
            {
                if (mHandleGrabbed != null)
                {
                    UndoManager.RecordUndos <SpriteGrid>();
                    UndoManager.ClearObjectsWatching <SpriteGrid>();
                }
                mHandleGrabbed = null;
            }
        }
示例#3
0
        public void ClickGrid(SpriteGrid gridClicked, Sprite spriteClicked)
        {
            #region if eyedropper is pressed, don't select the grid, just grab the texture
            if (GuiData.ToolsWindow.eyedropper.IsPressed)
            {
                GameData.Cursor.ClickSprite(spriteClicked);
            }
            #endregion

            #region Select the grid - eyedropper is not down
            else
            {
                newlySelectedCurrentSprite     = null;
                newlySelectedCurrentSpriteGrid = null;

                #region if selecting a new grid, not painting, and changes have been made
                if ((gridClicked != CurrentSpriteGrid || currentSprites.Contains(spriteClicked) == false || spriteClicked == null) &&
                    GuiData.ToolsWindow.paintButton.IsPressed == false &&
                    ShouldAskUserIfChangesShouldBeApplied(gridClicked, spriteClicked))
                {
                    // The user may have changed the texture coordinates on the
                    // selected Sprite.  This should result in the new texture coordinates
                    // being "painted" on the SpriteGrid at the given location.
                    PaintTextureCoordinatesOnCurrentSpriteInGrid();
                    newlySelectedCurrentSprite     = spriteClicked;
                    newlySelectedCurrentSpriteGrid = gridClicked;
                    AskIfChangesShouldBeApplied(null);
                }
                #endregion

                #region else, do not need to ask if changes should be applied
                else
                {
                    if (GuiData.ToolsWindow.paintButton.IsPressed == false &&
                        GameData.EditorLogic.CurrentSprites.Contains(spriteClicked) == false)
                    {
                        if (spriteClicked != null)
                        {
                            oldPosition = spriteClicked.Position;
                        }
                        else
                        {
                            oldPosition = Vector3.Empty;
                        }

                        PaintTextureCoordinatesOnCurrentSpriteInGrid();
                    }

                    if (CurrentSpriteGrid != gridClicked)
                    {
                        GameData.DeselectCurrentSprites();
                    }

                    CurrentSpriteGrid = gridClicked;

                    // attach the grid border
                    mSpriteGridBorder.AttachTo(CurrentSpriteGrid);

                    GameData.Cursor.ClickSprite(spriteClicked);

                    SpriteGridGrabbed = gridClicked;
                    mSpriteGrabbed    = spriteClicked;

                    if (gridClicked != null)
                    {
                        UndoManager.AddToWatch <Sprite>(gridClicked.Blueprint);


                        UndoManager.AddToWatch <SpriteGrid>(gridClicked);
                    }
                    GuiData.ListWindow.SpriteGridListBox.HighlightObject(gridClicked, false);
                }
                #endregion

                cursor.ObjectGrabbed = spriteClicked;

                if (gridClicked == null)
                {
                    return;
                }

                #region Change the convert to sprite grid button to "Modify Sprite Grid"
                GuiData.ToolsWindow.convertToSpriteGridButton.Enabled = true;
                GuiData.ToolsWindow.convertToSpriteGridButton.Text    = "Modify Sprite Grid";
                #endregion
            }
            #endregion
        }
示例#4
0
        public void Control(Cursor cursor, Camera camera, float xToY)
        {
            // Nick Spacek got an exception in this method.  Not sure why - I can't get it.
            // So I'll chop it up into try catch blocks to narrow it down.
            try
            {
                if (CurrentObject == null)
                {
                    Visible = false;
                }

                if (!cursor.PrimaryDown)
                {
                    AxesClicked         = false;
                    changeVector.X      = changeVector.Y = changeVector.Z = 0;
                    mCursorPushedOnAxis = false;
                }

                if (origin.Visible == false)
                {
                    return;
                }
            }
            catch (NullReferenceException)
            {
                throw new NullReferenceException("Exception in Control method setup");
            }

            Sprite spriteHighlighted = cursor.GetSpriteOver(this.editAxisSpriteArray);

            try
            {
                #region Fades for the cursor being over or not over certain parts

                editAxisSpriteArray.Alpha = .5f * GraphicalEnumerations.MaxColorComponentValue;
                mCursorOverAxis           = false;

                if (spriteHighlighted != null)
                {
                    spriteHighlighted.Alpha = GraphicalEnumerations.MaxColorComponentValue;
                    mCursorOverAxis         = true;
                }

                #endregion
            }
            catch (NullReferenceException)
            {
                throw new NullReferenceException("Exception in setting fades.");
            }

            try
            {
                #region Pushing button
                if (cursor.PrimaryPush)
                {
                    if (spriteHighlighted != null)
                    {
                        mCursorPushedOnAxis = true;
                        axisGrabbed         = spriteHighlighted;
                        cursor.SetObjectRelativePosition(origin);

                        if (origin.Parent is Sprite)
                        {
                            UndoManager.AddToWatch(origin.Parent as Sprite);
                        }
                    }
                }
                #endregion
            }
            catch (NullReferenceException)
            {
                throw new NullReferenceException("Exception in Pushing button");
            }

            DraggingActivity(cursor, xToY);

            try
            {
                #region Clicking button
                if (cursor.PrimaryClick && mCursorPushedOnAxis)
                {
                    mCursorPushedOnAxis   = false;
                    axisGrabbed           = null;
                    cursor.StaticPosition = false;
                    AxesClicked           = true;

                    UndoManager.RecordUndos <Sprite>();
                    UndoManager.ClearObjectsWatching <Sprite>();
                }

                #endregion
            }
            catch
            {
                throw new NullReferenceException("Exception in Clicking button");
            }
        }
示例#5
0
        /// <summary>
        /// Controls selecting new Shapes and performing move, scale, and rotate (when appropriate).
        /// </summary>
        #endregion
        private void CursorControlOverShapes()
        {
            if (GuiManager.DominantWindowActive)
            {
                return;
            }


            Cursor cursor = GuiManager.Cursor;

            #region Pushing selects and grabs a Shape or the corner of a Polygon
            if (cursor.PrimaryPush)
            {
                #region If the user has not interacted with the corners then see check for grabbing any Shapes

                if (mReactiveHud.HasPolygonEdgeGrabbed == false)
                {
                    mObjectGrabbed = GetShapeOver(cursor.PrimaryDoublePush);

                    ShowErrorIfObjectCanNotBeGrabbed();

                    // If the object is not null store its original position.  This will be used
                    // for SHIFT+drag which allows movement only on one axis.
                    if (mObjectGrabbed != null)
                    {
                        PositionedObjectMover.SetStartPosition(mObjectGrabbed);
                    }

                    cursor.SetObjectRelativePosition(mObjectGrabbed);

                    if (PolygonGrabbed != null)
                    {
                        UndoManager.AddToWatch(PolygonGrabbed);
                        SelectPolygon(PolygonGrabbed);
                    }

                    if (AxisAlignedCubeGrabbed != null)
                    {
                        UndoManager.AddToWatch(AxisAlignedCubeGrabbed);
                        SelectAxisAlignedCube(AxisAlignedCubeGrabbed);
                    }

                    if (AxisAlignedRectangleGrabbed != null)
                    {
                        UndoManager.AddToWatch(AxisAlignedRectangleGrabbed);
                        SelectAxisAlignedRectangle(AxisAlignedRectangleGrabbed);
                    }
                    if (CircleGrabbed != null)
                    {
                        UndoManager.AddToWatch(CircleGrabbed);
                        SelectCircle(CircleGrabbed);
                    }
                    if (SphereGrabbed != null)
                    {
                        UndoManager.AddToWatch(SphereGrabbed);
                        SelectSphere(SphereGrabbed);
                    }

                    if (mObjectGrabbed == null)
                    {
                        DeselectAll();
                    }
                }

                #endregion
            }
            #endregion

            #region Holding the button down can be used to drag objects
            if (cursor.PrimaryDown)
            {
                PerformDraggingUpdate();
            }
            #endregion

            #region Clicking (releasing) the mouse lets go of grabbed Polygons

            if (cursor.PrimaryClick)
            {
                if (PolygonGrabbed != null)
                {
                    UndoManager.RecordUndos <Polygon>();
                    UndoManager.ClearObjectsWatching <Polygon>();
                }

                if (AxisAlignedRectangleGrabbed != null)
                {
                    UndoManager.RecordUndos <AxisAlignedRectangle>();
                    UndoManager.ClearObjectsWatching <AxisAlignedRectangle>();
                }

                if (AxisAlignedCubeGrabbed != null)
                {
                    UndoManager.RecordUndos <AxisAlignedCube>();
                    UndoManager.ClearObjectsWatching <AxisAlignedCube>();
                }

                if (CircleGrabbed != null)
                {
                    UndoManager.RecordUndos <Circle>();
                    UndoManager.ClearObjectsWatching <Circle>();
                }

                if (SphereGrabbed != null)
                {
                    UndoManager.RecordUndos <Sphere>();
                    UndoManager.ClearObjectsWatching <Sphere>();
                }

                mObjectGrabbed = null;

                cursor.StaticPosition = false;

                cursor.ObjectGrabbed = null;
            }

            #endregion
        }