|
35
|
1 |
/* |
|
|
2 |
* This file is part of the TraKERS\Front IDILL package. |
|
|
3 |
* |
|
|
4 |
* (c) IRI <http://www.iri.centrepompidou.fr/> |
|
|
5 |
* |
|
|
6 |
* For the full copyright and license information, please view the LICENSE |
|
|
7 |
* file that was distributed with this source code. |
|
|
8 |
*/ |
|
|
9 |
|
|
|
10 |
/* |
|
|
11 |
* Projet : TraKERS |
|
|
12 |
* Module : Front IDILL |
|
|
13 |
* Fichier : mosaic.js |
|
|
14 |
* |
|
|
15 |
* Auteur : alexandre.bastien@iri.centrepompidou.fr |
|
|
16 |
* |
|
|
17 |
* Fonctionnalités : Définit la "classe" courbe et définit des fonctions d'intéractions (dessin...). |
|
|
18 |
*/ |
|
|
19 |
|
|
|
20 |
function curve() |
|
|
21 |
{ |
|
|
22 |
tool.fixedDistance = 10; |
|
|
23 |
this.path; |
|
|
24 |
this.pathStroke; |
|
|
25 |
this.lastPoint; |
|
|
26 |
} |
|
|
27 |
|
|
|
28 |
curve.prototype.onMouseDown = function(event) |
|
|
29 |
{ |
|
|
30 |
this.pathStroke = new Path(); |
|
|
31 |
this.path = new Path(); |
|
|
32 |
|
|
|
33 |
this.pathStroke.fillColor = '#366F7A'; |
|
|
34 |
this.path.fillColor = '#02FEFF'; |
|
|
35 |
|
|
|
36 |
console.log('down'); |
|
|
37 |
}; |
|
|
38 |
|
|
|
39 |
curve.prototype.onMouseDrag = function(event) |
|
|
40 |
{ |
|
|
41 |
//if(event.point.x < 0 || event.point.x > canvasWidth || event.point.y < 0 || event.point.y > canvasHeight) |
|
|
42 |
//return; |
|
|
43 |
|
|
|
44 |
var step = event.delta / 5; |
|
|
45 |
var stepStroke = event.delta / 3; |
|
|
46 |
step.angle += 90; |
|
|
47 |
stepStroke.angle += 90; |
|
|
48 |
|
|
|
49 |
var top = event.point + step; |
|
|
50 |
var bottom = event.point - step; |
|
|
51 |
|
|
|
52 |
var topStroke = event.point + stepStroke; |
|
|
53 |
var bottomStroke = event.point - stepStroke; |
|
|
54 |
|
|
|
55 |
this.path.add(top); |
|
|
56 |
this.path.insert(0, bottom); |
|
|
57 |
this.path.smooth(); |
|
|
58 |
|
|
|
59 |
this.pathStroke.add(topStroke); |
|
|
60 |
this.pathStroke.insert(0, bottomStroke); |
|
|
61 |
this.pathStroke.smooth(); |
|
|
62 |
|
|
|
63 |
this.lastPoint = event.middlePoint; |
|
|
64 |
}; |
|
|
65 |
|
|
|
66 |
curve.prototype.onMouseUp = function(event) |
|
|
67 |
{ |
|
|
68 |
this.pathStroke.remove(); |
|
|
69 |
this.path.remove(); |
|
|
70 |
}; |
|
|
71 |
|
|
|
72 |
curve.prototype.onKeyDown = function(event) |
|
|
73 |
{ |
|
|
74 |
//S'il n'y a rien a colorier, on quitte. |
|
|
75 |
if(typeof this.pathStroke === 'undefined' || typeof this.path === 'undefined') |
|
|
76 |
return; |
|
|
77 |
|
|
|
78 |
if(event.key == 'r' || event.key == 'R') |
|
|
79 |
{ |
|
|
80 |
this.pathStroke.fillColor = '#49564F'; |
|
|
81 |
this.path.fillColor = '#00FE00' |
|
|
82 |
} |
|
|
83 |
else if(event.key == 'x' || event.key == 'X') |
|
|
84 |
{ |
|
|
85 |
this.pathStroke.fillColor = '#535F6D'; |
|
|
86 |
this.path.fillColor = '#CCCCCC' |
|
|
87 |
} |
|
|
88 |
else if(event.key == 'w' || event.key == 'W') |
|
|
89 |
{ |
|
|
90 |
this.pathStroke.fillColor = '#366F7A'; |
|
|
91 |
this.path.fillColor = '#02FEFF' |
|
|
92 |
} |
|
|
93 |
}; |