2150 |
mathias |
1 |
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
|
|
|
2 |
<head>
|
|
|
3 |
<title>Create DojoX GFX JSON</title>
|
|
|
4 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
|
5 |
<style type="text/css">
|
|
|
6 |
@import "../../../dojo/resources/dojo.css";
|
|
|
7 |
@import "../../../dijit/tests/css/dijitTests.css";
|
|
|
8 |
td.cell { padding: 1em 1em 0em 0em; }
|
|
|
9 |
</style>
|
|
|
10 |
<!--
|
|
|
11 |
The next line should include Microsoft's Silverligth.js, if you plan to use the silverlight backend
|
|
|
12 |
<script type="text/javascript" src="Silverlight.js"></script>
|
|
|
13 |
-->
|
|
|
14 |
<script type="text/javascript" src="../../../dojo/dojo.js"></script>
|
|
|
15 |
<script type="text/javascript">
|
|
|
16 |
dojo.require("dojox.gfx");
|
|
|
17 |
dojo.require("dojox.gfx.utils");
|
|
|
18 |
|
|
|
19 |
surface = null;
|
|
|
20 |
grid_size = 500;
|
|
|
21 |
grid_step = 50;
|
|
|
22 |
|
|
|
23 |
init = function(){
|
|
|
24 |
// initialize graphics
|
|
|
25 |
var container = dojo.byId("gfx");
|
|
|
26 |
surface = dojox.gfx.createSurface(container, 500, 500);
|
|
|
27 |
// create a picture
|
|
|
28 |
|
|
|
29 |
// make a grid
|
|
|
30 |
var grid = surface.createGroup();
|
|
|
31 |
for(var i = 0; i <= grid_size; i += grid_step){
|
|
|
32 |
grid.createLine({x1: 0, x2: grid_size, y1: i, y2: i}).setStroke("black");
|
|
|
33 |
grid.createLine({y1: 0, y2: grid_size, x1: i, x2: i}).setStroke("black");
|
|
|
34 |
}
|
|
|
35 |
|
|
|
36 |
// make a checkerboard
|
|
|
37 |
var board = surface.createGroup(), gs2 = grid_step * 2;
|
|
|
38 |
for(var i = 0; i < grid_size; i += grid_step){
|
|
|
39 |
for(var j = 0; j < grid_size; j += grid_step){
|
|
|
40 |
if(i % gs2 == j % gs2) {
|
|
|
41 |
board.createRect({x: i, y: j, width: grid_step, height: grid_step}).setFill([255, 0, 0, 0.1]);
|
|
|
42 |
}
|
|
|
43 |
}
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
// draw test_transform shapes
|
|
|
47 |
var g1 = surface.createGroup();
|
|
|
48 |
var r1 = g1.createShape({type: "rect", x: 200, y: 200})
|
|
|
49 |
.setFill("green")
|
|
|
50 |
.setStroke({})
|
|
|
51 |
;
|
|
|
52 |
var r2 = surface.createShape({type: "rect"}).setStroke({})
|
|
|
53 |
.setFill({type: "linear", to: {x: 50, y: 100},
|
|
|
54 |
colors: [{offset: 0, color: "green"}, {offset: 0.5, color: "red"}, {offset: 1, color: "blue"}] })
|
|
|
55 |
.setTransform({dx: 100, dy: 100})
|
|
|
56 |
;
|
|
|
57 |
var r3 = surface.createRect().setStroke({})
|
|
|
58 |
.setFill({ type: "linear" })
|
|
|
59 |
;
|
|
|
60 |
var r4 = g1.createShape({type: "rect"})
|
|
|
61 |
.setFill("blue")
|
|
|
62 |
.setTransform([dojox.gfx.matrix.rotategAt(-30, 350, 250), { dx: 300, dy: 200 }])
|
|
|
63 |
;
|
|
|
64 |
var p1 = g1.createShape({type: "path"})
|
|
|
65 |
.setStroke({})
|
|
|
66 |
.moveTo(300, 100)
|
|
|
67 |
.lineTo(400, 200)
|
|
|
68 |
.lineTo(400, 300)
|
|
|
69 |
.lineTo(300, 400)
|
|
|
70 |
.curveTo(400, 300, 400, 200, 300, 100)
|
|
|
71 |
.setTransform({})
|
|
|
72 |
;
|
|
|
73 |
var p2 = g1.createShape(p1.getShape())
|
|
|
74 |
.setStroke({color: "red", width: 2})
|
|
|
75 |
.setTransform({dx: 100})
|
|
|
76 |
;
|
|
|
77 |
var p3 = g1.createShape({type: "path"})
|
|
|
78 |
.setStroke({color: "blue", width: 2})
|
|
|
79 |
.moveTo(300, 100)
|
|
|
80 |
.setAbsoluteMode(false)
|
|
|
81 |
.lineTo ( 100, 100)
|
|
|
82 |
.lineTo ( 0, 100)
|
|
|
83 |
.lineTo (-100, 100)
|
|
|
84 |
.curveTo( 100, -100, 100, -200, 0, -300)
|
|
|
85 |
//.setTransform(dojox.gfx.matrix.rotategAt(135, 250, 250))
|
|
|
86 |
.setTransform(dojox.gfx.matrix.rotategAt(180, 250, 250))
|
|
|
87 |
;
|
|
|
88 |
g1.moveToFront();
|
|
|
89 |
g1.setTransform(dojox.gfx.matrix.rotategAt(-15, 250, 250));
|
|
|
90 |
|
|
|
91 |
// dump everything
|
|
|
92 |
dump();
|
|
|
93 |
};
|
|
|
94 |
|
|
|
95 |
dump = function(){
|
|
|
96 |
var objects = dojox.gfx.utils.serialize(surface);
|
|
|
97 |
// name top-level objects
|
|
|
98 |
for(var i = 0; i < objects.length; ++i){
|
|
|
99 |
objects[i].name = "shape" + i;
|
|
|
100 |
}
|
|
|
101 |
// format and show
|
|
|
102 |
dojo.byId("io").value = dojo.toJson(objects, dojo.byId("pprint").checked);
|
|
|
103 |
};
|
|
|
104 |
|
|
|
105 |
dojo.addOnLoad(init);
|
|
|
106 |
</script>
|
|
|
107 |
</head>
|
|
|
108 |
<body>
|
|
|
109 |
<h1>Create DojoX GFX JSON</h1>
|
|
|
110 |
<p>This is a helper file, which serves as a template to generate static pictures.</p>
|
|
|
111 |
<table>
|
|
|
112 |
<tr>
|
|
|
113 |
<td align="left" valign="top" class="cell">
|
|
|
114 |
<div id="gfx" style="width: 500px; height: 500px; border: solid 1px black;">
|
|
|
115 |
</div>
|
|
|
116 |
</td>
|
|
|
117 |
</tr>
|
|
|
118 |
</table>
|
|
|
119 |
<p><textarea id="io" cols="80" rows="10" wrap="off"></textarea></p>
|
|
|
120 |
<p><button onclick="dump()">Dump!</button>
|
|
|
121 |
<input type="checkbox" id="pprint" checked="checked" /> <label for="pprint">Pretty-print JSON</label></p>
|
|
|
122 |
</body>
|
|
|
123 |
</html>
|