-
Notifications
You must be signed in to change notification settings - Fork 0
/
DRDrawCoursePen.as
76 lines (54 loc) · 1.54 KB
/
DRDrawCoursePen.as
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
class DRDrawCoursePen extends DRPen {
static var INTERVAL = 20.0;
static var TRAIL_LENGTH = 8;
var firstX:Number;
var firstY:Number;
var lastX:Number;
var lastY:Number;
var mousePath:Array;
var course:DRCourse;
function DRDrawCoursePen() {
super("draw");
}
function onPenDown() {
course = DRCourse.course;
}
function onMouseDown() {
if (lastX == null) {
firstX = _xmouse;
firstY = _ymouse;
mousePath = [ [_xmouse, _ymouse] ];
addPoint(_xmouse, _ymouse);
} else {
finish();
}
}
function onMouseMove() {
if (lastX == null) return;
var dx = lastX - _xmouse;
var dy = lastY - _ymouse;
var distSqr = dx * dx + dy * dy;
if (distSqr >= INTERVAL * INTERVAL) {
addPoint(_xmouse, _ymouse);
}
mousePath.push( [_xmouse, _ymouse] );
while (mousePath.length > TRAIL_LENGTH) {
mousePath.shift();
}
}
function onKeyDown(){
// SHIFT ==> constrain in one dimension
}
function addPoint(x:Number, y:Number) {
course.addPoint(x, y, mousePath[0][0], mousePath[0][1]);
lastX = _xmouse;
lastY = _ymouse;
}
function finish() {
addPoint(firstX, firstY);
lastX = null;
lastY = null;
course.loop();
switchPen("edit");
}
}