Rev 1400 |
Rev 1402 |
Go to most recent revision |
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
)
{
}
public override void MouseDown
(MouseEventArgs e
)
{
}
public override void MouseMove
(MouseEventArgs e
)
{
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
)
{
int x
= Math
.Min(mLastX, mStartX
);
int y
= Math
.Min(mLastY, mStartY
);
int w
= Math
.Abs(mLastX
- mStartX
);
int h
= Math
.Abs(mLastY
- mStartY
);
mParent
.CurrentDoc.AddRectangle(x, y, w, h
);
}
mLeftButtonDown
= false;
}
}
public override void Render
()
{
if (mLeftButtonDown
)
{
RenderUtil
.drawQuad(MainForm
.App.getGraphics(), mStartX, mStartY, mLastX, mLastY, RECTANGLE_CREATE_COLOR
);
}
}
}
}