forked from barais/tpWeb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathview.js
More file actions
78 lines (71 loc) · 2.6 KB
/
view.js
File metadata and controls
78 lines (71 loc) · 2.6 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
var idgen=0;
/*
Une fonction annexe me permettant d'appliquer en temps réel sur le canvas la suppresion à partir du bouton.
*/
function rm(id2Delete,draw,ctx,elm){
this.delet=id2Delete;
this.draw=draw;
document.getElementById(delet).remove();
document.getElementById(delet+"l").remove();
this.draw.removeForms(elm);
this.draw.paint(ctx);
}
Drawing.prototype.UpdateShapeList=function(draw,ctx){
if(idgen >9999){
idgen=0;
}
//Declaration des variables
var elm = this.getForms()[this.getCount()];
let tmp = document.createElement("li");
tmp.id = idgen+"l";
let save2call =elm.getForm();
//Affichage du contenu des <li></li> HTML
if(save2call=="Rectangle"){
tmp.textContent="ID:"+idgen+ save2call+ "-["+elm.getX1()+"-" +elm.getY1() +"] comme point supérieur gauche de largeur :"+elm.getX2()+" et de hauteur :"+elm.getY2();
}
else{
tmp.textContent= "ID:"+idgen+save2call+ "-["+elm.getX1()+"-" +elm.getY1() +"] jusqu'à ["+elm.getX2()+"-"+elm.getY2()+"]";
}
document.getElementById("shapeList").appendChild(tmp);
//Creation du button avec le span
let but = document.createElement("button");
but.setAttribute("type","button")
but.className +="btn btn-default";
but.id=idgen;
but.addEventListener("click", function (){
rm(this.id,draw,ctx,elm);
});
let spa = document.createElement("span");
spa.className +="glyphicon glyphicon-remove-sign";
document.getElementById("shapeList").insertBefore(but,tmp);
but.appendChild(spa);
this.count++;
idgen++;
}
// Implémenter ici les fonctions paint à ajouter dans chacune des classes du modèle.
Rectangle.prototype.paint = function(ctx) {
//TODO Manager color
ctx.lineWidth = this.getThick();
ctx.strokeStyle= this.getColor();
ctx.beginPath();
ctx.rect(this.getX1(), this.getY1(),this.getX2(),this.getY2());
ctx.stroke();
};
Line.prototype.paint = function(ctx) {
//TODO Manager color
ctx.lineWidth = this.getThick();
ctx.strokeStyle= this.getColor();
ctx.beginPath();
ctx.moveTo(this.getX1(), this.getY1());
ctx.lineTo(this.getX2(), this.getY2());
ctx.stroke();
};
Drawing.prototype.paint = function(ctx) {
console.log(this.getForms());
ctx.fillStyle = '#F0F0F0'; // set canvas' background color
ctx.fillRect(0, 0, canvas.width, canvas.height);
this.getForms().forEach(function (eltDuTableau) {
// now fill the canvas
eltDuTableau.paint(ctx);
});
};