Exemplo n.º 1
0
        /// <summary>
        /// Handles the MouseDown event of the panelSprite control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="MouseEventArgs"/> instance containing the event data.</param>
        private void panelSprite_MouseDown(object sender, MouseEventArgs e)
        {
            // If we don't have focus, don't ruin our sprite trying to get it back.
            if (!panelSprite.Focused)
            {
                panelSprite.Focus();
                return;
            }

            try
            {
                switch (SpriteEditorMode)
                {
                case SpriteEditorMode.AutoClip:
                    Cursor.Current = Cursors.WaitCursor;

                    var autoClipper = new AutoClipper((Point) new Vector2(e.X - _content.TextureSprite.Position.X, e.Y - _content.TextureSprite.Position.Y));

                    Rectangle clipRect = autoClipper.Clip(_content.Texture);

                    // If we didn't get a clip area, then just leave.
                    if (clipRect.IsEmpty)
                    {
                        return;
                    }

                    // Set the clipper position.
                    _clipper.ClipRegion    = clipRect;
                    _content.Size          = clipRect.Size;
                    _content.TextureRegion = clipRect;
                    break;

                case SpriteEditorMode.Edit:
                    _clipper.OnMouseDown(e);
                    break;

                case SpriteEditorMode.View:
                    var anchorOffset = (Point)Vector2.Modulate(_anchorSprite.Anchor, _anchorSprite.Scale);
                    var anchorRect   = new Rectangle((Point)(_anchorSprite.Position - anchorOffset),
                                                     (Size)_anchorSprite.ScaledSize);

                    if (anchorRect.Contains(e.Location))
                    {
                        SpriteEditorMode = SpriteEditorMode.AnchorDrag;
                        _dragDelta       = new Point(e.X - anchorRect.X - anchorOffset.X, e.Y - anchorRect.Y - anchorOffset.Y);

                        panelSprite.Cursor = Cursors.Hand;
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                GorgonDialogs.ErrorBox(ParentForm, ex);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Handles the MouseDown event of the panelTextureDisplay control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="MouseEventArgs"/> instance containing the event data.</param>
        private void panelTextureDisplay_MouseDown(object sender, MouseEventArgs e)
        {
            try
            {
                if (_clipper == null)
                {
                    return;
                }

                if (_clipper.OnMouseDown(e))
                {
                    DisableNumericLimits();
                }
            }
            catch (Exception ex)
            {
                GorgonDialogs.ErrorBox(ParentForm, ex);
            }
            finally
            {
                ValidateCommands();
                UpdateLabelInfo();
            }
        }