Subversion Repositories AndroidProjects

Rev

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

Rev Author Line No. Line
1399 chris 1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Threading.Tasks;
6
using System.Windows.Forms;
7
 
1416 chris 8
using BauzoidNET.graphics;
9
using BauzoidNET.math;
10
 
1399 chris 11
namespace ShapeEditor.interaction
12
{
13
    public class EllipseMode : InteractionMode
14
    {
1416 chris 15
        public static readonly Vector4 ELLIPSE_CREATE_COLOR = new Vector4(0.6f, 0.6f, 0.6f, 1.0f);
1399 chris 16
 
1416 chris 17
        private int mLastX = 0;
18
        private int mLastY = 0;
19
        private bool mLeftButtonDown = false;
1399 chris 20
 
1416 chris 21
        private int mStartX = 0;
22
        private int mStartY = 0;
23
 
1399 chris 24
        public EllipseMode(MainForm parent)
1404 chris 25
            : base(parent, InteractionMode.ELLIPSE)
1399 chris 26
        {
27
        }
28
 
1420 chris 29
        public override void MouseMove(MouseEventArgs e, bool isMouseDown = false)
1399 chris 30
        {
1416 chris 31
            if (e.Button == MouseButtons.Left)
32
            {
33
                if (!mLeftButtonDown)
34
                {
35
                    mLeftButtonDown = true;
36
                    mStartX = e.X;
37
                    mStartY = e.Y;
38
                }
39
                else
40
                {
41
                }
42
            }
43
 
44
            mLastX = e.X;
45
            mLastY = e.Y;
1399 chris 46
        }
47
 
48
        public override void MouseUp(MouseEventArgs e)
49
        {
1416 chris 50
            if (e.Button == MouseButtons.Left)
51
            {
52
                if (mLeftButtonDown)
53
                {
54
                    if ((mLastX != mStartX) && (mLastY != mStartY))
55
                    {
56
                        float x = Math.Min(mLastX, mStartX) / mParent.ZoomFactor - mParent.CurrentDoc.Sprite.transform.x / mParent.ZoomFactor;
57
                        float y = Math.Min(mLastY, mStartY) / mParent.ZoomFactor - mParent.CurrentDoc.Sprite.transform.y / mParent.ZoomFactor;
58
                        float w = Math.Abs(mLastX - mStartX) / mParent.ZoomFactor;
59
                        float h = Math.Abs(mLastY - mStartY) / mParent.ZoomFactor;
1533 chris 60
                        mParent.CurrentDoc.AddEllipse(x + w/2, y + h/2, w/2, h/2, -1, -1);
1416 chris 61
                    }
62
                }
63
                mLeftButtonDown = false;
64
            }
1399 chris 65
        }
1400 chris 66
 
67
        public override void Render()
68
        {
1416 chris 69
            if (mLeftButtonDown)
70
            {
71
                RenderUtil.drawEllipse(MainForm.App.getGraphics(), mStartX, mStartY, mLastX, mLastY, ELLIPSE_CREATE_COLOR);
72
            }
1400 chris 73
        }
1399 chris 74
    }
75
}