Fixed cursor offset problem
This commit is contained in:
8
Paint_2/Form1.Designer.cs
generated
8
Paint_2/Form1.Designer.cs
generated
@@ -221,6 +221,7 @@
|
|||||||
this.btnColorHistory4.Size = new System.Drawing.Size(25, 25);
|
this.btnColorHistory4.Size = new System.Drawing.Size(25, 25);
|
||||||
this.btnColorHistory4.TabIndex = 4;
|
this.btnColorHistory4.TabIndex = 4;
|
||||||
this.btnColorHistory4.UseVisualStyleBackColor = false;
|
this.btnColorHistory4.UseVisualStyleBackColor = false;
|
||||||
|
this.btnColorHistory4.Click += new System.EventHandler(this.BtnColor_Click);
|
||||||
//
|
//
|
||||||
// btnColorHistory3
|
// btnColorHistory3
|
||||||
//
|
//
|
||||||
@@ -232,6 +233,7 @@
|
|||||||
this.btnColorHistory3.Size = new System.Drawing.Size(25, 25);
|
this.btnColorHistory3.Size = new System.Drawing.Size(25, 25);
|
||||||
this.btnColorHistory3.TabIndex = 3;
|
this.btnColorHistory3.TabIndex = 3;
|
||||||
this.btnColorHistory3.UseVisualStyleBackColor = false;
|
this.btnColorHistory3.UseVisualStyleBackColor = false;
|
||||||
|
this.btnColorHistory3.Click += new System.EventHandler(this.BtnColor_Click);
|
||||||
//
|
//
|
||||||
// btnColorHistory2
|
// btnColorHistory2
|
||||||
//
|
//
|
||||||
@@ -243,6 +245,7 @@
|
|||||||
this.btnColorHistory2.Size = new System.Drawing.Size(25, 25);
|
this.btnColorHistory2.Size = new System.Drawing.Size(25, 25);
|
||||||
this.btnColorHistory2.TabIndex = 2;
|
this.btnColorHistory2.TabIndex = 2;
|
||||||
this.btnColorHistory2.UseVisualStyleBackColor = false;
|
this.btnColorHistory2.UseVisualStyleBackColor = false;
|
||||||
|
this.btnColorHistory2.Click += new System.EventHandler(this.BtnColor_Click);
|
||||||
//
|
//
|
||||||
// btnColorHistory1
|
// btnColorHistory1
|
||||||
//
|
//
|
||||||
@@ -254,6 +257,7 @@
|
|||||||
this.btnColorHistory1.Size = new System.Drawing.Size(25, 25);
|
this.btnColorHistory1.Size = new System.Drawing.Size(25, 25);
|
||||||
this.btnColorHistory1.TabIndex = 0;
|
this.btnColorHistory1.TabIndex = 0;
|
||||||
this.btnColorHistory1.UseVisualStyleBackColor = false;
|
this.btnColorHistory1.UseVisualStyleBackColor = false;
|
||||||
|
this.btnColorHistory1.Click += new System.EventHandler(this.BtnColor_Click);
|
||||||
//
|
//
|
||||||
// lblSelectedColor
|
// lblSelectedColor
|
||||||
//
|
//
|
||||||
@@ -388,10 +392,11 @@
|
|||||||
this.nupPencilWidth.Size = new System.Drawing.Size(141, 21);
|
this.nupPencilWidth.Size = new System.Drawing.Size(141, 21);
|
||||||
this.nupPencilWidth.TabIndex = 17;
|
this.nupPencilWidth.TabIndex = 17;
|
||||||
this.nupPencilWidth.Value = new decimal(new int[] {
|
this.nupPencilWidth.Value = new decimal(new int[] {
|
||||||
2,
|
10,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0});
|
0});
|
||||||
|
this.nupPencilWidth.ValueChanged += new System.EventHandler(this.nupPencilWidth_ValueChanged);
|
||||||
//
|
//
|
||||||
// label8
|
// label8
|
||||||
//
|
//
|
||||||
@@ -503,6 +508,7 @@
|
|||||||
this.btnClear.TabIndex = 27;
|
this.btnClear.TabIndex = 27;
|
||||||
this.btnClear.Text = "Clear";
|
this.btnClear.Text = "Clear";
|
||||||
this.btnClear.UseVisualStyleBackColor = false;
|
this.btnClear.UseVisualStyleBackColor = false;
|
||||||
|
this.btnClear.Click += new System.EventHandler(this.btnClear_Click);
|
||||||
//
|
//
|
||||||
// btnFill
|
// btnFill
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -32,12 +32,13 @@ namespace Paint_2
|
|||||||
}
|
}
|
||||||
private Point MousePositionToCanvasPosition()
|
private Point MousePositionToCanvasPosition()
|
||||||
{
|
{
|
||||||
return new Point(MousePosition.X - canvas.Location.X,MousePosition.Y - canvas.Location.Y);
|
//return new Point(MousePosition.X - canvas.Location.X, MousePosition.Y - canvas.Location.Y);
|
||||||
|
return canvas.PointToClient(MousePosition);
|
||||||
}
|
}
|
||||||
private void canvas_MouseDown(object sender, MouseEventArgs e)
|
private void canvas_MouseDown(object sender, MouseEventArgs e)
|
||||||
{
|
{
|
||||||
drawing = true;
|
drawing = true;
|
||||||
sketch.StartDrawing(MousePositionToCanvasPosition(), Color.FromArgb(rnd.Next(0,256), rnd.Next(0, 256), rnd.Next(0, 256)), (int)nupPencilWidth.Value);
|
sketch.StartDrawing(MousePositionToCanvasPosition(), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), (int)nupPencilWidth.Value);
|
||||||
tmrRefresh.Enabled = true;
|
tmrRefresh.Enabled = true;
|
||||||
|
|
||||||
List<Color> colorHistory = sketch.CurrentTool.GetLastColors(4);
|
List<Color> colorHistory = sketch.CurrentTool.GetLastColors(4);
|
||||||
@@ -50,8 +51,8 @@ namespace Paint_2
|
|||||||
{
|
{
|
||||||
tmrRefresh.Enabled = false;
|
tmrRefresh.Enabled = false;
|
||||||
sketch.AddDrawingPoint(MousePositionToCanvasPosition());
|
sketch.AddDrawingPoint(MousePositionToCanvasPosition());
|
||||||
canvas.Image = sketch.Paint();
|
|
||||||
drawing = false;
|
drawing = false;
|
||||||
|
RefreshUi();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void tmrRefresh_Tick(object sender, EventArgs e)
|
private void tmrRefresh_Tick(object sender, EventArgs e)
|
||||||
@@ -59,8 +60,39 @@ namespace Paint_2
|
|||||||
if (drawing)
|
if (drawing)
|
||||||
{
|
{
|
||||||
sketch.AddDrawingPoint(MousePositionToCanvasPosition());
|
sketch.AddDrawingPoint(MousePositionToCanvasPosition());
|
||||||
canvas.Image = sketch.Paint();
|
|
||||||
}
|
}
|
||||||
|
RefreshUi();
|
||||||
|
}
|
||||||
|
private void BtnColor_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Button button = sender as Button;
|
||||||
|
sketch.ChangePaintToolColor(button.BackColor);
|
||||||
|
tmrRefresh_Tick(sender, e);
|
||||||
|
}
|
||||||
|
private string ColorToString(Color color)
|
||||||
|
{
|
||||||
|
// Expected Hex:FFFFFF R:255 G:255 B:255
|
||||||
|
string result = "";
|
||||||
|
int toBase = 16;
|
||||||
|
result += "Hex:" + Convert.ToString(color.R, toBase) + Convert.ToString(color.G, toBase) + Convert.ToString(color.B, toBase) + " ";
|
||||||
|
result += "R:" + color.R + " G:" + color.G + " B:" + color.B;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
private void RefreshUi()
|
||||||
|
{
|
||||||
|
canvas.Image = sketch.Paint();
|
||||||
|
lblSelectedColor.Text = ColorToString(sketch.CurrentTool.Color);
|
||||||
|
}
|
||||||
|
private void btnClear_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
sketch.Clear();
|
||||||
|
RefreshUi();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void nupPencilWidth_ValueChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
sketch.ChangePaintToolWidth((int)nupPencilWidth.Value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,9 +15,10 @@ namespace Paint_2
|
|||||||
List<int> Widths { get; set; }
|
List<int> Widths { get; set; }
|
||||||
int Width { get; set; }
|
int Width { get; set; }
|
||||||
|
|
||||||
void Start(Point point,Color color,int width);
|
void Start(Color color,int width);
|
||||||
void Stop(Point point);
|
void Stop(Point point);
|
||||||
void Add(Point point);
|
void Add(Point point);
|
||||||
|
void Clear();
|
||||||
List<Color> GetLastColors(int colorNumber);
|
List<Color> GetLastColors(int colorNumber);
|
||||||
void Paint(Bitmap canvas);
|
void Paint(Bitmap canvas);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,16 +52,19 @@ namespace Paint_2
|
|||||||
drawingCounter += 1;
|
drawingCounter += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void Start(Point point, Color color, int width)
|
public void Start(Color color, int width)
|
||||||
{
|
{
|
||||||
Color = color;
|
Color = color;
|
||||||
Width = width;
|
Width = width;
|
||||||
List<Point> points = new List<Point>();
|
List<Point> points = new List<Point>();
|
||||||
points.Add(point);
|
|
||||||
Drawings.Add(points);
|
Drawings.Add(points);
|
||||||
Colors.Add(Color);
|
Colors.Add(Color);
|
||||||
Widths.Add(Width);
|
Widths.Add(Width);
|
||||||
}
|
}
|
||||||
|
public void Clear()
|
||||||
|
{
|
||||||
|
Drawings = new List<List<Point>>();
|
||||||
|
}
|
||||||
public void Stop(Point point)
|
public void Stop(Point point)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
@@ -72,16 +75,20 @@ namespace Paint_2
|
|||||||
if (Colors.Count <= colorNumber)
|
if (Colors.Count <= colorNumber)
|
||||||
{
|
{
|
||||||
//We need to fill with black color
|
//We need to fill with black color
|
||||||
for (int i = colorNumber; i >= 0; i--)
|
for (int i = Colors.Count; i > 0; i--)
|
||||||
|
{
|
||||||
|
result.Add(Colors[(Colors.Count) - i]);
|
||||||
|
}
|
||||||
|
for (int i = colorNumber - Colors.Count;i > 0; i--)
|
||||||
{
|
{
|
||||||
result.Add(Color.FromArgb(0x00,0x00,0x00));
|
result.Add(Color.FromArgb(0x00,0x00,0x00));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for(int i = colorNumber; i > 0; i--)
|
for (int i = colorNumber; i > 0; i--)
|
||||||
{
|
{
|
||||||
result.Add(Colors[(Colors.Count)-i]);
|
result.Add(Colors[(Colors.Count) - i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -29,7 +29,8 @@ namespace Paint_2
|
|||||||
|
|
||||||
CurrentColor = Color.FromArgb(0xFF, 0xFF, 0xFF);
|
CurrentColor = Color.FromArgb(0xFF, 0xFF, 0xFF);
|
||||||
IsDrawing = false;
|
IsDrawing = false;
|
||||||
Drawing = new Bitmap(sketchSize.Width, sketchSize.Height);
|
SketchSize = sketchSize;
|
||||||
|
Drawing = new Bitmap(SketchSize.Width, SketchSize.Height);
|
||||||
ToolList = toolList;
|
ToolList = toolList;
|
||||||
if (toolList[0] != null)
|
if (toolList[0] != null)
|
||||||
{
|
{
|
||||||
@@ -46,7 +47,16 @@ namespace Paint_2
|
|||||||
}
|
}
|
||||||
public void StartDrawing(Point location,Color color,int width)
|
public void StartDrawing(Point location,Color color,int width)
|
||||||
{
|
{
|
||||||
CurrentTool.Start(location,color,width);
|
CurrentTool.Start(color,width);
|
||||||
|
CurrentTool.Add(location);
|
||||||
|
}
|
||||||
|
public void ChangePaintToolColor(Color color)
|
||||||
|
{
|
||||||
|
CurrentTool.Start(color,CurrentTool.Width);
|
||||||
|
}
|
||||||
|
public void ChangePaintToolWidth(int width)
|
||||||
|
{
|
||||||
|
CurrentTool.Start(CurrentTool.Color,width);
|
||||||
}
|
}
|
||||||
public void StopDrawing(Point location)
|
public void StopDrawing(Point location)
|
||||||
{
|
{
|
||||||
@@ -56,6 +66,14 @@ namespace Paint_2
|
|||||||
{
|
{
|
||||||
CurrentTool.Add(location);
|
CurrentTool.Add(location);
|
||||||
}
|
}
|
||||||
|
public void Clear()
|
||||||
|
{
|
||||||
|
Drawing = new Bitmap(SketchSize.Width, SketchSize.Height);
|
||||||
|
foreach (PaintTool tool in ToolList)
|
||||||
|
{
|
||||||
|
tool.Clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
public Bitmap Paint()
|
public Bitmap Paint()
|
||||||
{
|
{
|
||||||
foreach (PaintTool tool in ToolList)
|
foreach (PaintTool tool in ToolList)
|
||||||
|
|||||||
Reference in New Issue
Block a user