Subversion Repositories AndroidProjects

Rev

Rev 1420 | Blame | Compare with Previous | Last modification | View Log | RSS feed

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using BauzoidNET.graphics;
using BauzoidNET.math;

namespace ShapeEditor.interaction
{
    public class RectangleMode : InteractionMode
    {
        public static readonly Vector4 RECTANGLE_CREATE_COLOR = new Vector4(0.6f, 0.6f, 0.6f, 1.0f);

        private int mLastX = 0;
        private int mLastY = 0;
        private bool mLeftButtonDown = false;

        private int mStartX = 0;
        private int mStartY = 0;

        public RectangleMode(MainForm parent)
            : base(parent, InteractionMode.RECTANGLE)
        {
        }

        public override void MouseMove(MouseEventArgs e, bool isMouseDown = false)
        {
            if (e.Button == MouseButtons.Left)
            {
                if (!mLeftButtonDown)
                {
                    mLeftButtonDown = true;
                    mStartX = e.X;
                    mStartY = e.Y;
                }
                else
                {
                }
            }

            mLastX = e.X;
            mLastY = e.Y;
        }

        public override void MouseUp(MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                if (mLeftButtonDown)
                {
                    if ((mLastX != mStartX) && (mLastY != mStartY))
                    {
                        float x = Math.Min(mLastX, mStartX) / mParent.ZoomFactor - mParent.CurrentDoc.Sprite.transform.x / mParent.ZoomFactor;
                        float y = Math.Min(mLastY, mStartY) / mParent.ZoomFactor - mParent.CurrentDoc.Sprite.transform.y / mParent.ZoomFactor;
                        float w = Math.Abs(mLastX - mStartX) / mParent.ZoomFactor;
                        float h = Math.Abs(mLastY - mStartY) / mParent.ZoomFactor;
                        mParent.CurrentDoc.AddRectangle(x, y, w, h, -1, -1);
                    }
                }
                mLeftButtonDown = false;
            }
        }

        public override void Render()
        {
            if (mLeftButtonDown)
            {
                RenderUtil.drawQuad(MainForm.App.getGraphics(), mStartX, mStartY, mLastX, mLastY, RECTANGLE_CREATE_COLOR);
            }
        }
    }
}