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
78 lines (66 loc) · 2.09 KB
/
controller.js
File metadata and controls
78 lines (66 loc) · 2.09 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
var editingMode = { rect: 0, line: 1 };
function Pencil(ctx, drawing, canvas) {
this.currEditingMode;
this.currLineWidth;
this.currColour;
this.currentShape = 0;
this.ctx = ctx;
// Liez ici les widgets à la classe pour modifier les attributs présents ci-dessus.
this.FLineWidth = function(){
this.currLineWidth = document.getElementById('spinnerWidth').value;
}.bind(this);
new DnD(canvas, this);
this.FEditingMode = function(){
if (document.getElementById("butRect").checked){
this.currEditingMode =editingMode.rect;
}
else{
this.currEditingMode =editingMode.line;
}
}.bind(this);
this.FColor = function(){
this.currColour = document.getElementById('colour').value;
}.bind(this);
// Implémentez ici les 3 fonctions onInteractionStart, onInteractionUpdate et onInteractionEnd
this.onInteractionStart = function(dnd){
this.FEditingMode();
this.FLineWidth();
this.FColor();
switch(this.currEditingMode){
case editingMode.rect: {
this.currentShape = new Rectangle(dnd.getXStart(),dnd.getYStart(),0,0,this.currLineWidth,this.currColour);
break;
}
case editingMode.line: {
this.currentShape = new Line(dnd.getXStart(),dnd.getYStart(),dnd.getXEnd(),dnd.getYEnd(),this.currLineWidth,this.currColour);
break;
}
}
}.bind(this);
this.onInteractionUpdate = function(dnd){
if(this.currEditingMode == 0){
this.currentShape.x2 = dnd.getXEnd()-this.currentShape.x1;
this.currentShape.y2 = dnd.getYEnd()-this.currentShape.y1;
}
else {
this.currentShape.x2 = dnd.getXEnd();
this.currentShape.y2 = dnd.getYEnd();
}
drawing.paint(this.ctx);
this.currentShape.paint(this.ctx);
}.bind(this);
this.onInteractionEnd = function(dnd){
if(this.currEditingMode == 0){
this.currentShape.x2 =dnd.getXEnd()-this.currentShape.x1;
this.currentShape.y2 = dnd.getYEnd()-this.currentShape.y1;
}
else {
this.currentShape.x2 = dnd.getXEnd();
this.currentShape.y2 = dnd.getYEnd();
}
this.currentShape.paint(this.ctx);
drawing.addForms(this.currentShape);
drawing.paint(this.ctx);
drawing.UpdateShapeList(drawing,ctx);
}.bind(this);
};