]> git.proxmox.com Git - sencha-touch.git/blame - src/examples/kitchensink/app/view/XRay.js
import Sencha Touch 2.4.2 source
[sencha-touch.git] / src / examples / kitchensink / app / view / XRay.js
CommitLineData
c4685c84
TL
1//<feature charts>
2Ext.define('Kitchensink.view.XRay', {
3 alias: 'sprite.xray',
4 extend: 'Ext.draw.sprite.Path',
5 render: function (surface, ctx) {
6 var attr = this.attr,
7 mat = attr.matrix,
8 imat = attr.inverseMatrix,
9 path = attr.path,
10 size = imat.x(2, 0) - imat.x(0, 0);
11 if (attr.path.coords.length === 0) {
12 return;
13 }
14 mat.toContext(ctx);
15 var i = 0, j = 0,
16 types = path.types,
17 coords = path.coords,
18 ln = path.types.length;
19
20 ctx.beginPath();
21 for (; i < ln; i++) {
22 switch (types[i]) {
23 case "M":
24 ctx.moveTo(coords[j], coords[j + 1]);
25 j += 2;
26 break;
27 case "L":
28 ctx.lineTo(coords[j], coords[j + 1]);
29 j += 2;
30 break;
31 case "C":
32 ctx.bezierCurveTo(
33 coords[j], coords[j + 1],
34 coords[j + 2], coords[j + 3],
35 coords[j + 4], coords[j + 5]
36 );
37 j += 6;
38 break;
39 case "Z":
40 ctx.closePath();
41 break;
42 default:
43 }
44 }
45 ctx.fillStroke(attr);
46
47 mat.toContext(ctx);
48 ctx.beginPath();
49 for (i = 0, j = 0; i < ln; i++) {
50 switch (types[i]) {
51 case "M":
52 ctx.moveTo(coords[j] - size, coords[j + 1] - size);
53 ctx.rect(coords[j] - size, coords[j + 1] - size, size * 2, size * 2);
54 j += 2;
55 break;
56 case "L":
57 ctx.moveTo(coords[j] - size, coords[j + 1] - size);
58 ctx.rect(coords[j] - size, coords[j + 1] - size, size * 2, size * 2);
59 j += 2;
60 break;
61 case "C":
62 ctx.moveTo(coords[j] + size, coords[j + 1]);
63 ctx.arc(coords[j], coords[j + 1], size, 0, Math.PI * 2, true);
64 j += 2;
65 ctx.moveTo(coords[j] + size, coords[j + 1]);
66 ctx.arc(coords[j], coords[j + 1], size, 0, Math.PI * 2, true);
67 j += 2;
68 ctx.moveTo(coords[j] + size * 2, coords[j + 1]);
69 ctx.rect(coords[j] - size, coords[j + 1] - size, size * 2, size * 2);
70 j += 2;
71 break;
72 default:
73 }
74 }
75 imat.toContext(ctx);
76 ctx.strokeStyle = "black";
77 ctx.strokeOpacity = 1;
78 ctx.lineWidth = 1;
79 ctx.stroke();
80
81 mat.toContext(ctx);
82 ctx.beginPath();
83 for (i = 0, j = 0; i < ln; i++) {
84 switch (types[i]) {
85 case "M":
86 ctx.moveTo(coords[j], coords[j + 1]);
87 j += 2;
88 break;
89 case "L":
90 ctx.moveTo(coords[j], coords[j + 1]);
91 j += 2;
92 break;
93 case "C":
94 ctx.lineTo(coords[j], coords[j + 1]);
95 j += 2;
96 ctx.moveTo(coords[j], coords[j + 1]);
97 j += 2;
98 ctx.lineTo(coords[j], coords[j + 1]);
99 j += 2;
100 break;
101 default:
102 }
103 }
104 imat.toContext(ctx);
105 ctx.lineWidth = 1 / 2;
106 ctx.stroke();
107 }
108});
109//</feature>