67 lines
2.1 KiB
C#
67 lines
2.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Paint_2
|
|
{
|
|
public partial class PaintForm : Form
|
|
{
|
|
Sketch sketch;
|
|
List<PaintTool> toolList;
|
|
bool drawing = false;
|
|
Random rnd;
|
|
|
|
int debugCounter = 0;
|
|
public PaintForm()
|
|
{
|
|
InitializeComponent();
|
|
|
|
rnd = new Random();
|
|
nupWidth.Value = canvas.Width;
|
|
nupHeight.Value = canvas.Height;
|
|
toolList = new List<PaintTool>();
|
|
toolList.Add(new Pencil());
|
|
toolList.Add(new Pencil());
|
|
sketch = new Sketch(new Size((int)nupWidth.Value, (int)nupHeight.Value), toolList);
|
|
canvas.Image = sketch.Drawing;
|
|
}
|
|
private Point MousePositionToCanvasPosition()
|
|
{
|
|
return new Point(MousePosition.X - canvas.Location.X,MousePosition.Y - canvas.Location.Y);
|
|
}
|
|
private void canvas_MouseDown(object sender, MouseEventArgs e)
|
|
{
|
|
drawing = true;
|
|
sketch.StartDrawing(MousePositionToCanvasPosition(), Color.FromArgb(rnd.Next(0,256), rnd.Next(0, 256), rnd.Next(0, 256)), 5);
|
|
tmrRefresh.Enabled = true;
|
|
|
|
//new Thread((sketch) => { (sketch as Sketch).AddDrawingPoint(this.PointToClient(MousePosition)); }).Start();
|
|
}
|
|
private void canvas_MouseUp(object sender, MouseEventArgs e)
|
|
{
|
|
tmrRefresh.Enabled = false;
|
|
sketch.AddDrawingPoint(MousePositionToCanvasPosition());
|
|
sketch.Paint();
|
|
canvas.Image = sketch.Drawing;
|
|
drawing = false;
|
|
}
|
|
|
|
private void tmrRefresh_Tick(object sender, EventArgs e)
|
|
{
|
|
if (drawing)
|
|
{
|
|
sketch.AddDrawingPoint(MousePositionToCanvasPosition());
|
|
sketch.Paint();
|
|
canvas.Image = sketch.Drawing;
|
|
}
|
|
}
|
|
}
|
|
}
|