-
Notifications
You must be signed in to change notification settings - Fork 0
/
DrawView.cs
117 lines (92 loc) · 2.16 KB
/
DrawView.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Util;
using Android.Views;
using Android.Widget;
using Android.Graphics;
namespace BluetoothChat
{
[Register("BluetoothChat.DrawView")]
public class DrawView : View
{
private Path drawPath;
private Paint drawPaint, canvasPaint;
private Canvas drawCanvas;
private Bitmap canvasBitmap;
public DrawView (Context context) :
base (context)
{
Initialize ();
}
public DrawView (Context context, IAttributeSet attrs) :
base (context, attrs)
{
Initialize ();
}
public DrawView (Context context, IAttributeSet attrs, int defStyle) :
base (context, attrs, defStyle)
{
Initialize ();
}
void Initialize ()
{
drawPath = new Path ();
drawPaint = new Paint ();
drawPaint.AntiAlias = true;
drawPaint.StrokeWidth = 15;
drawPaint.SetStyle (Paint.Style.Stroke);
drawPaint.StrokeJoin = Paint.Join.Round;
drawPaint.StrokeCap = Paint.Cap.Round;
canvasPaint = new Paint (PaintFlags.Dither);
// var drawButt = FindViewById<Button> (Resource.Id.drawButton);
// drawButt.Click += (object sender, EventArgs e) => {
//
// Console.WriteLine("draw");
// setColor(false);
// };
//
// var clearButt = FindViewById<Button> (Resource.Id.clearButton);
// clearButt.Click += (object sender, EventArgs e) => {
//
// Console.WriteLine("clear");
// setColor(true);
// };
}
public void setColor(bool erase){
Invalidate ();
if (!erase) {
drawPaint.Color = Color.Black;
} else {
drawPaint.Color = Color.White;
}
}
public bool onTouchEvent(MotionEvent event1){
Console.WriteLine ("touch event");
float x = event1.GetX ();
float y = event1.GetY ();
switch (event1.Action) {
case MotionEventActions.Down:
drawPath.MoveTo (x, y);
break;
case MotionEventActions.Move:
drawPath.LineTo (x, y);
break;
case MotionEventActions.Up:
drawCanvas.DrawPath (drawPath, drawPaint);
drawPath.Reset ();
break;
default:
return false;
}
Invalidate ();
return true;
}
}
}