forked from barais/tpWeb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.js
More file actions
85 lines (63 loc) · 2.66 KB
/
controller.js
File metadata and controls
85 lines (63 loc) · 2.66 KB
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
function Pencil(ctx, drawing, canvas) {
this.currentShape = 0;
this.ctx = ctx;
this.circle = false;
// Liez ici les widgets à la classe pour modifier les attributs présents ci-dessus.
new DnD(canvas, this);
this.onInteractionStart = function(dnd) {
if (document.getElementById("butRect").checked){
this.currentShape = new Rectangle(dnd.initX,dnd.initY,dnd.finalX,dnd.finalY,
document.getElementById("spinnerWidth").value, document.getElementById("colour").value);
}else if (document.getElementById("butLine").checked){
this.currentShape = new Line(dnd.initX,dnd.initY,dnd.finalX,dnd.finalY,
document.getElementById("spinnerWidth").value, document.getElementById("colour").value);
}
else if (document.getElementById("butCircle").checked){
var abPow = Math.pow(Math.abs(dnd.initX-dnd.finalX),2);
var acPow = Math.pow(Math.abs(dnd.initY-dnd.finalY),2);
var rayon = Math.sqrt(abPow + acPow);
this.currentShape = new Circle(dnd.initX,dnd.initY,rayon,
document.getElementById("spinnerWidth").value, document.getElementById("colour").value);
this.circle = true;
}
else{
this.currentShape.paint(ctx, canvas);
}
}.bind(this) ;
this.onInteractionUpdate = function(dnd) {
if (this.currentShape != 0 && !this.circle){
this.currentShape.finalX = dnd.finalX;
this.currentShape.finalY = dnd.finalY;
}
else if(this.currentShape != 0&&this.circle){
var abPow = Math.pow(Math.abs(dnd.initX-dnd.finalX),2);
var acPow = Math.pow(Math.abs(dnd.initY-dnd.finalY),2);
var rayon = Math.sqrt(abPow + acPow);
this.currentShape = new Circle(dnd.initX,dnd.initY,rayon,
document.getElementById("spinnerWidth").value, document.getElementById("colour").value);
}
//this.currentShape.clear(this.ctx)
drawing.paint(this.ctx);
this.currentShape.paint(this.ctx);
}.bind(this) ;
this.onInteractionEnd = function(dnd) {
if (this.currentShape != 0 && !this.circle){
this.currentShape.finalX = dnd.finalX;
this.currentShape.finalY = dnd.finalY;
}
else if(this.currentShape != 0&&this.circle){
var abPow = Math.pow(Math.abs(dnd.initX-dnd.finalX),2);
var acPow = Math.pow(Math.abs(dnd.initY-dnd.finalY),2);
var rayon = Math.sqrt(abPow + acPow);
this.currentShape = new Circle(dnd.initX,dnd.initY,rayon,
document.getElementById("spinnerWidth").value, document.getElementById("colour").value);
this.circle = false;
}
this.currentShape.clear(this.ctx)
drawing.addForms(this.currentShape);
drawing.paint(this.ctx);
drawing.updateShapeList(this.currentShape);
this.currentShape = null;
}.bind(this) ;
// Implémentez ici les 3 fonctions onInteractionStart, onInteractionUpdate et onInteractionEnd
};