Example #1
0
 public void MouseClicked(Point mousePos)
 {
     if (_selectionMode == SpriteEditorSelectionMode.SelectingTile)
     {
         Vector2 translatedPos = ParentEditor.ZoomBox.Camera
                                 .ConvertToWorldPos(new Vector2(mousePos.X, mousePos.Y));
         if (IceMath.IsPointInsideRectangle(new Point((int)translatedPos.X, (int)translatedPos.Y)
                                            , _spriteRectangles[_selectedRectangle]))
         {
             _selectionMode = SpriteEditorSelectionMode.Tiled;
             Rectangle spriteRect = _spriteRectangles[_selectedRectangle];
             Sprite.MaterialArea = _selectedRectangle;
             this.ParentEditor.RefreshAreaCombo();
         }
     }
 }
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            Point mousePos = new Point(e.X - this.AutoScrollPosition.X, e.Y - this.AutoScrollPosition.Y);

            _highlightedTile = -1;
            for (int i = 0; i < _rowsCountOnTexture * ParentGrid.ColumnsCountOnTexture; i++)
            {
                Point     tilePos  = GetPosOfTile(i);
                Rectangle tileRect = new Rectangle(tilePos.X, tilePos.Y, ParentGrid.TileSize.X, ParentGrid.TileSize.Y);
                if (IceMath.IsPointInsideRectangle(mousePos, tileRect))
                {
                    _highlightedTile = i;
                    return;
                }
            }
        }
Example #3
0
 /// <summary>
 /// Called by the parent form when the mouse is moving on the control
 /// </summary>
 /// <param name="mousePos">The mouse position relative to the control</param>
 public void CheckMousePosition(Point mousePos)
 {
     if (_selectionMode == SpriteEditorSelectionMode.SelectingTile)
     {
         Vector2 translatedPos = ParentEditor.ZoomBox.Camera
                                 .ConvertToWorldPos(new Vector2(mousePos.X, mousePos.Y));
         foreach (var rect in this.SpriteRectangles)
         {
             Rectangle translatedRect = rect.Value;
             if (IceMath.IsPointInsideRectangle(new Point((int)translatedPos.X, (int)translatedPos.Y),
                                                translatedRect))
             {
                 _selectedRectangle = rect.Key;
             }
         }
     }
 }
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            if (SceneManager.ActiveScene != null)
            {
                // update the mouse position (this will update the Scene mouse too)
                this.RealMousePos = new Vector2(e.X, e.Y);
                if (MilkshakeForm.Instance.SceneEditorTool == MilkshakeSceneEditorTool.Select)
                {
                    // if the user is dragging selected item(s)
                    if (_isDraggingItem == true && _selectedItems.Count > 0)
                    {
                        Vector2 dragDistance     = SceneMousePos - _dragItemStartPos;
                        Vector2 diffDragDistance = Vector2.Zero;
                        dragDistance.X = (float)Math.Round(dragDistance.X);
                        dragDistance.Y = (float)Math.Round(dragDistance.Y);
                        //Console.WriteLine("dragDistance: " + dragDistance + " start: " + _dragItemStartPos);
                        if (dragDistance.LengthSquared() > 0)
                        {
                            if (shouldMakeCopy == true)
                            {
                                shouldMakeCopy = false;
                                MilkshakeForm.Instance.CopySelectedItems();
                                List <SceneItem> _newItems = MilkshakeForm.Instance.PasteSelectedItems();
                                _selectedItems.Clear();
                                foreach (var item in _newItems)
                                {
                                    _selectedItems.Add(item);
                                }
                            }
                            foreach (SceneItem item in _selectedItems)
                            {
                                Vector2 newPos = item.Position + dragDistance;
                                if (Preferences.ShowGrid == true && Preferences.SnapToGrid == true)
                                {
                                    #region SnapToGrid
                                    Point   gridSize     = Preferences.GridSizes[Preferences.SelectedGrid - 1];
                                    int     snapZone     = Preferences.GridAttractionZones[Preferences.SelectedGrid - 1];
                                    int     left         = item.BoundingRect.Left + (int)dragDistance.X;
                                    int     right        = item.BoundingRect.Right + (int)dragDistance.X;
                                    int     top          = item.BoundingRect.Top + (int)dragDistance.Y;
                                    int     bottom       = item.BoundingRect.Bottom + (int)dragDistance.Y;
                                    Vector2 halfGridSize = new Vector2(gridSize.X / 2, gridSize.Y);
                                    Vector2 leftSnap     = new Vector2(
                                        IceMath.Floor(left / (float)gridSize.X),
                                        left % (float)gridSize.X);
                                    Vector2 rightSnap = new Vector2(
                                        IceMath.Ceiling(right / (float)gridSize.X),
                                        ((float)gridSize.X - right
                                         % (float)gridSize.X) % (float)gridSize.X);
                                    if (leftSnap.X < 0)
                                    {
                                        leftSnap.Y = (gridSize.X + leftSnap.Y) % gridSize.X;
                                    }
                                    if (leftSnap.Y > halfGridSize.X)
                                    {
                                        leftSnap.X += 1;
                                        leftSnap.Y  = leftSnap.Y - gridSize.X;
                                    }
                                    if (rightSnap.Y > halfGridSize.X)
                                    {
                                        rightSnap.X -= 1;
                                        rightSnap.Y  = rightSnap.Y - gridSize.X;
                                    }

                                    Vector2 snapX = Vector2.Zero;
                                    if (Math.Abs(leftSnap.Y) <= Math.Abs(rightSnap.Y))
                                    {
                                        snapX = leftSnap;
                                    }
                                    else
                                    {
                                        snapX = rightSnap;
                                    }
                                    //Console.WriteLine("L: " + leftSnap + " R: " + rightSnap + " ");
                                    if (Math.Abs(snapX.Y) <= (float)snapZone)
                                    {
                                        float diff   = newPos.X - (float)left;
                                        float oldPos = newPos.X;
                                        newPos.X = snapX.X * gridSize.X + diff;
                                        if (snapX != leftSnap)
                                        {
                                            newPos.X -= right - left;
                                        }
                                        diffDragDistance.X = newPos.X - oldPos;
                                    }

                                    Vector2 topSnap = new Vector2(
                                        IceMath.Floor(top / (float)gridSize.Y),
                                        top % (float)gridSize.Y);
                                    Vector2 bottomSnap = new Vector2(
                                        IceMath.Ceiling(bottom / (float)gridSize.Y),
                                        ((float)gridSize.Y - bottom
                                         % (float)gridSize.Y) % (float)gridSize.Y);
                                    if (topSnap.X < 0)
                                    {
                                        topSnap.Y = (gridSize.Y + topSnap.Y) % gridSize.Y;
                                    }
                                    if (topSnap.Y > halfGridSize.X)
                                    {
                                        topSnap.X += 1;
                                        topSnap.Y  = topSnap.Y - gridSize.Y;
                                    }
                                    if (bottomSnap.Y > halfGridSize.X)
                                    {
                                        bottomSnap.X -= 1;
                                        bottomSnap.Y  = bottomSnap.Y - gridSize.Y;
                                    }

                                    Vector2 snapY = Vector2.Zero;
                                    if (Math.Abs(topSnap.Y) <= Math.Abs(bottomSnap.Y))
                                    {
                                        snapY = topSnap;
                                    }
                                    else
                                    {
                                        snapY = bottomSnap;
                                    }
                                    //Console.WriteLine("T: " + topSnap + " B: " + bottomSnap + " ");
                                    if (Math.Abs(snapY.Y) <= (float)snapZone)
                                    {
                                        float diff   = newPos.Y - (float)top;
                                        float oldPos = newPos.Y;
                                        newPos.Y = snapY.X * gridSize.Y + diff;
                                        if (snapY != topSnap)
                                        {
                                            newPos.Y -= bottom - top;
                                        }
                                        diffDragDistance.Y = newPos.Y - oldPos;
                                    }
                                    #endregion
                                }
                                item.Position = newPos;
                                MilkshakeForm.Instance.SceneWasModified = true;
                            }
                            _refreshSceneItemProperties = true;
                        }
                        _dragItemStartPos = SceneMousePos;
                        if (diffDragDistance.X != 0)
                        {
                            _dragItemStartPos.X += diffDragDistance.X;
                        }
                        if (diffDragDistance.Y != 0)
                        {
                            _dragItemStartPos.Y += diffDragDistance.Y;
                        }
                    }
                    else
                    {
                        // check if the mouse is hovering an object
                        // and highlight it
                        _highlightedItem = null;
                        foreach (SceneItem item in SceneManager.ActiveScene.SceneItems)
                        {
                            if (item is PostProcessAnimation)
                            {
                                continue;
                            }
                            Microsoft.Xna.Framework.Point mousePoint
                                = new Microsoft.Xna.Framework.Point((int)SceneMousePos.X,
                                                                    (int)SceneMousePos.Y);
                            if (IceMath.IsPointInsideRectangle(mousePoint, item.BoundingRect))
                            {
                                if (item.Visible)
                                {
                                    _highlightedItem = item;
                                }
                            }
                        }
                        // check the selected items and give them priority over the others
                        foreach (SceneItem item in _selectedItems)
                        {
                            Microsoft.Xna.Framework.Point mousePoint
                                = new Microsoft.Xna.Framework.Point((int)SceneMousePos.X,
                                                                    (int)SceneMousePos.Y);
                            if (IceMath.IsPointInsideRectangle(mousePoint, item.BoundingRect))
                            {
                                if (item.Visible)
                                {
                                    _highlightedItem = item;
                                }
                            }
                        }
                    }
                }
                // Check for scene dragging with the mouse
                if (_isDraggingScene == true)
                {
                    Camera  cam          = SceneManager.ActiveScene.ActiveCameras[0];
                    Vector2 dragDistance = -(RealMousePos - _dragSceneStartPos) / cam.Zoom;
                    cam.Position += dragDistance;
                    _refreshSceneItemProperties = true;
                    _dragSceneStartPos          = RealMousePos;
                }
            }
        }
Example #5
0
 protected override void OnMouseMove(MouseEventArgs e)
 {
     base.OnMouseMove(e);
     if (this.ParentEditor.SelectedCompositeKeyFrame != null)
     {
         // update the mouse position (this will update the Scene mouse too)
         RealMousePos = new Vector2(e.X, e.Y);
         // if the user is dragging selected item(s)
         if (_isDraggingItem == true && this.SelectedBones.Count > 0)
         {
             Vector2 dragDistance = this.SceneMousePos - _dragItemStartPos;
             if (dragDistance.LengthSquared() > 0)
             {
                 foreach (String boneTransformRef in this.SelectedBones)
                 {
                     CompositeBoneTransform boneTransform
                         = this.ParentEditor.SelectedCompositeKeyFrame.GetBoneTransformFromKeyFrame(
                               this.ParentEditor.SelectedCompositeKeyFrame, boneTransformRef);
                     if ((Control.ModifierKeys & Keys.Control) == Keys.Control)
                     {
                         float originalAngle = _dragItemStartPos.Angle();
                         float targetAngle   = this.SceneMousePos.Angle();
                         boneTransform.Rotation = MathHelper.WrapAngle((float)Math.Round((double)(boneTransform.Rotation + (targetAngle - originalAngle)), 2));
                     }
                     else
                     {
                         boneTransform.Position += dragDistance;
                     }
                 }
                 _refreshSceneItemProperties = true;
                 ParentEditor.UpdatePreview  = true;
             }
             _dragItemStartPos = SceneMousePos;
         }
         else
         {
             // check if the mouse is hovering an object
             // and highlight it
             this.HighlightedBone = null;
             foreach (CompositeBoneTransform boneTransform
                      in ParentEditor.SelectedCompositeKeyFrame.BoneTransforms)
             {
                 // ignore 'locked' bones
                 if (boneTransform.IsPositionCurrentlyInherited() == true)
                 {
                     continue;
                 }
                 SceneItem boneTransformSceneItem = boneTransform.GetSceneItem();
                 if (boneTransform.IsVisible == true && boneTransformSceneItem != null)
                 {
                     Rectangle boundingRect = boneTransformSceneItem.BoundingRect;
                     Microsoft.Xna.Framework.Point mousePoint
                         = new Microsoft.Xna.Framework.Point((int)SceneMousePos.X,
                                                             (int)SceneMousePos.Y);
                     if (IceMath.IsPointInsideRectangle(mousePoint, boundingRect))
                     {
                         this.HighlightedBone = boneTransform.BoneReference;
                     }
                 }
             }
             // check the selected items and give them priority over the others
             foreach (String boneTransformRef in this.SelectedBones)
             {
                 CompositeBoneTransform boneTransform
                     = ParentEditor.SelectedCompositeKeyFrame.GetBoneTransformFromKeyFrame(
                           ParentEditor.SelectedCompositeKeyFrame, boneTransformRef);
                 SceneItem boneTransformSceneItem = boneTransform.GetSceneItem();
                 if (boneTransform.IsVisible == true && boneTransformSceneItem != null)
                 {
                     Rectangle boundingRect = boneTransformSceneItem.BoundingRect;
                     Microsoft.Xna.Framework.Point mousePoint
                         = new Microsoft.Xna.Framework.Point((int)SceneMousePos.X,
                                                             (int)SceneMousePos.Y);
                     if (IceMath.IsPointInsideRectangle(mousePoint, boundingRect))
                     {
                         this.HighlightedBone = boneTransformRef;
                     }
                 }
             }
         }
         // Check for scene dragging with the mouse
         if (_isDraggingScene == true)
         {
             Vector2 dragDistance = -(RealMousePos - _dragSceneStartPos);
             ParentEditor.ZoomBox.Camera.Position += dragDistance;
             _dragSceneStartPos = RealMousePos;
         }
     }
 }