| author | ymh <ymh.work@gmail.com> |
| Mon, 27 Apr 2015 17:22:46 +0200 | |
| changeset 435 | e529b633c339 |
| parent 328 | 3e69a85d73e9 |
| child 441 | 4732f078d0fe |
| permissions | -rw-r--r-- |
| 326 | 1 |
|
2 |
define([], function () { |
|
3 |
'use strict'; |
|
4 |
||
5 |
/* ShapeBuilder Begin */ |
|
6 |
||
7 |
var builders = { |
|
8 |
"circle":{ |
|
9 |
getShape: function() { |
|
10 |
return new paper.Path.Circle([0, 0], 1); |
|
11 |
}, |
|
12 |
getImageShape: function(center, radius) { |
|
13 |
return new paper.Path.Circle(center, radius); |
|
14 |
} |
|
15 |
}, |
|
16 |
"rectangle":{ |
|
17 |
getShape: function() { |
|
18 |
return new paper.Path.Rectangle([-2, -2], [2, 2]); |
|
19 |
}, |
|
20 |
getImageShape: function(center, radius) { |
|
21 |
return new paper.Path.Rectangle([-radius, -radius], [radius*2, radius*2]); |
|
22 |
} |
|
23 |
}, |
|
24 |
"ellipse":{ |
|
25 |
getShape: function() { |
|
26 |
return new paper.Path.Ellipse(new paper.Rectangle([-2, -1], [2, 1])); |
|
27 |
}, |
|
28 |
getImageShape: function(center, radius) { |
|
29 |
return new paper.Path.Ellipse(new paper.Rectangle([-radius, -radius/2], [radius*2, radius])); |
|
30 |
} |
|
31 |
}, |
|
32 |
"polygon":{ |
|
33 |
getShape: function() { |
|
34 |
return new paper.Path.RegularPolygon([0, 0], 6, 1); |
|
35 |
}, |
|
36 |
getImageShape: function(center, radius) { |
|
37 |
return new paper.Path.RegularPolygon([0, 0], 6, radius); |
|
38 |
} |
|
39 |
}, |
|
40 |
"diamond":{ |
|
41 |
getShape: function() { |
|
|
435
e529b633c339
Add shape management, correction on shape manip[ulation on the client, correct 404 error on space creation, increment version
ymh <ymh.work@gmail.com>
parents:
328
diff
changeset
|
42 |
var d = new paper.Path.Rectangle([-Math.SQRT2, -Math.SQRT2], [Math.SQRT2, Math.SQRT2]); |
| 326 | 43 |
d.rotate(45); |
44 |
return d; |
|
45 |
}, |
|
46 |
getImageShape: function(center, radius) { |
|
|
435
e529b633c339
Add shape management, correction on shape manip[ulation on the client, correct 404 error on space creation, increment version
ymh <ymh.work@gmail.com>
parents:
328
diff
changeset
|
47 |
var d = new paper.Path.Rectangle([-radius*Math.SQRT2/2, -radius*Math.SQRT2/2], [radius*Math.SQRT2, radius*Math.SQRT2]); |
| 326 | 48 |
d.rotate(45); |
49 |
return d; |
|
50 |
} |
|
51 |
}, |
|
52 |
"star":{ |
|
53 |
getShape: function() { |
|
54 |
return new paper.Path.Star([0, 0], 8, 1, 0.7); |
|
55 |
}, |
|
56 |
getImageShape: function(center, radius) { |
|
57 |
return new paper.Path.Star([0, 0], 8, radius*1, radius*0.7); |
|
58 |
} |
|
59 |
}, |
|
| 327 | 60 |
"svg": function(path){ |
61 |
return { |
|
62 |
getShape: function() { |
|
63 |
return new paper.Path(path); |
|
64 |
}, |
|
65 |
getImageShape: function(center, radius) { |
|
|
435
e529b633c339
Add shape management, correction on shape manip[ulation on the client, correct 404 error on space creation, increment version
ymh <ymh.work@gmail.com>
parents:
328
diff
changeset
|
66 |
// No calcul for the moment |
| 327 | 67 |
return new paper.Path(); |
68 |
} |
|
| 328 | 69 |
}; |
| 327 | 70 |
} |
| 326 | 71 |
}; |
|
435
e529b633c339
Add shape management, correction on shape manip[ulation on the client, correct 404 error on space creation, increment version
ymh <ymh.work@gmail.com>
parents:
328
diff
changeset
|
72 |
|
| 326 | 73 |
var ShapeBuilder = function (shape){ |
|
435
e529b633c339
Add shape management, correction on shape manip[ulation on the client, correct 404 error on space creation, increment version
ymh <ymh.work@gmail.com>
parents:
328
diff
changeset
|
74 |
if(shape === null || typeof shape === "undefined"){ |
| 327 | 75 |
shape = "circle"; |
76 |
} |
|
| 328 | 77 |
if(shape.substr(0,4)==="svg:"){ |
78 |
return builders.svg(shape.substr(4)); |
|
| 327 | 79 |
} |
| 326 | 80 |
if(!(shape in builders)){ |
81 |
shape = "circle"; |
|
82 |
} |
|
83 |
return builders[shape]; |
|
84 |
}; |
|
|
435
e529b633c339
Add shape management, correction on shape manip[ulation on the client, correct 404 error on space creation, increment version
ymh <ymh.work@gmail.com>
parents:
328
diff
changeset
|
85 |
|
| 326 | 86 |
return ShapeBuilder; |
87 |
||
88 |
}); |