Exemple #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;
            }
        }
Exemple #2
0
        /// <summary>
        /// Handles the MouseUp 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_MouseUp(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.AnchorDrag:
                    SpriteEditorMode   = SpriteEditorMode.View;
                    _dragDelta         = Point.Empty;
                    panelSprite.Cursor = Cursors.Default;
                    _content.RefreshProperty("Anchor");
                    break;

                case SpriteEditorMode.Edit:
                    if (!_clipper.OnMouseUp(e))
                    {
                        return;
                    }

                    var newRegion = Rectangle.Round(_clipper.ClipRegion);
                    _content.Size          = newRegion.Size;
                    _content.TextureRegion = newRegion;
                    _clipper.TextureSize   = _content.Texture.Settings.Size;
                    _clipper.Scale         = new Vector2(1);
                    break;
                }
            }
            catch (Exception ex)
            {
                GorgonDialogs.ErrorBox(ParentForm, ex);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
Exemple #3
0
        /// <summary>
        /// Handles the Click event of the buttonAutoClip control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void buttonAutoClip_Click(object sender, EventArgs e)
        {
            try
            {
                if (SpriteEditorMode == SpriteEditorMode.AutoClip)
                {
                    panelSprite.Cursor = Cursors.Default;
                    SpriteEditorMode   = SpriteEditorMode.View;
                    buttonCenter_Click(this, e);
                    return;
                }

                _content.TextureSprite.Scale = new Vector2(1);
                _clipper.NoBounds            = true;
                _clipper.ClipRegion          = new RectangleF(_content.TextureRegion.Location, _content.Size);
                _clipper.TextureSize         = _content.Texture.Settings.Size;
                _clipper.Offset = new Vector2(_halfScreen.X - _content.Size.Width / 2.0f - _content.TextureRegion.X,
                                              _halfScreen.Y - _content.Size.Height / 2.0f - _content.TextureRegion.Y);
                _clipper.HideNodes = true;
                _halfSprite        = new Point(_content.Size.Width / 2, _content.Size.Height / 2);


                SpriteEditorMode = SpriteEditorMode.AutoClip;

                scrollHorizontal.Value = _content.TextureRegion.X;
                scrollVertical.Value   = _content.TextureRegion.Y;

                CalculateSpritePosition();

                panelSprite.Cursor = Cursors.Cross;
                panelSprite.Focus();
            }
            catch (Exception ex)
            {
                GorgonDialogs.ErrorBox(ParentForm, ex);
            }
            finally
            {
                ValidateControls();
            }
        }
Exemple #4
0
        /// <summary>
        /// Handles the Click event of the buttonClip control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void buttonClip_Click(object sender, EventArgs e)
        {
            try
            {
                if (SpriteEditorMode == SpriteEditorMode.Edit)
                {
                    _zoomWindow               = null;
                    panelSprite.Cursor        = Cursors.Default;
                    panelZoomControls.Visible = false;
                    SpriteEditorMode          = SpriteEditorMode.View;
                    buttonCenter_Click(this, e);
                    return;
                }

                // If the texture rectangle and the sprite size are not equal, then inform the user that we
                // may need to make a destructive change to their sprite.
                if ((_content.Size.Width != _content.TextureRegion.Width) ||
                    (_content.Size.Height != _content.TextureRegion.Height))
                {
                    if (GorgonDialogs.ConfirmBox(ParentForm, Resources.GORSPR_DLG_CONFIRM_SPREDIT) == ConfirmationResult.No)
                    {
                        return;
                    }

                    // Reset the texture region to match the size of the sprite.
                    _content.TextureRegion = new Rectangle(_content.TextureRegion.Location, _content.Size);
                }

                _content.TextureSprite.Scale = new Vector2(1);
                panelZoomControls.Visible    = true;
                _clipper.NoBounds            = true;
                _clipper.ClipRegion          = new RectangleF(_content.TextureRegion.Location, _content.Size);
                _clipper.TextureSize         = _content.Texture.Settings.Size;
                _clipper.Offset = new Vector2(_halfScreen.X - _content.Size.Width / 2.0f - _content.TextureRegion.X,
                                              _halfScreen.Y - _content.Size.Height / 2.0f - _content.TextureRegion.Y);
                _clipper.HideNodes = false;
                _halfSprite        = new Point(_content.Size.Width / 2, _content.Size.Height / 2);

                CreateZoomWindow();

                SpriteEditorMode = SpriteEditorMode.Edit;

                scrollHorizontal.Value = _content.TextureRegion.X;
                scrollVertical.Value   = _content.TextureRegion.Y;

                CalculateSpritePosition();

                UpdateZoomWindow(Cursor.Position);

                // Force focus on the panel.
                panelSprite.Focus();
            }
            catch (Exception ex)
            {
                GorgonDialogs.ErrorBox(ParentForm, ex);
            }
            finally
            {
                ValidateControls();
            }
        }