[483] | 1 | <html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office"> |
---|
| 2 | <head> |
---|
| 3 | <title>dojox.gfx: 2 draggable circles</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 | </style> |
---|
| 9 | <script type="text/javascript" src="../../../dojo/dojo.js"></script> |
---|
| 10 | <script type="text/javascript"> |
---|
| 11 | |
---|
| 12 | dojo.require("dojox.gfx"); |
---|
| 13 | dojo.require("dojox.gfx.move"); |
---|
| 14 | |
---|
| 15 | var container = null, |
---|
| 16 | surface = null, |
---|
| 17 | surface_size = null; |
---|
| 18 | |
---|
| 19 | function makeCircles(){ |
---|
| 20 | // our geometry |
---|
| 21 | var x1 = 100, y1 = 100, x2 = 400, y2 = 400, r = 50; |
---|
| 22 | |
---|
| 23 | // our shapes |
---|
| 24 | var line = surface.createLine({x1: x1, y1: y1, x2: x2, y2: y2}).setStroke("red"), |
---|
| 25 | circle1 = surface.createCircle({cx: x1, cy: y1, r: r}).setStroke("red").setFill("white"), |
---|
| 26 | circle2 = surface.createCircle({cx: x2, cy: y2, r: r}).setStroke("red").setFill("white"); |
---|
| 27 | |
---|
| 28 | // circle movers |
---|
| 29 | var m1 = new dojox.gfx.Moveable(circle1), |
---|
| 30 | m2 = new dojox.gfx.Moveable(circle2); |
---|
| 31 | |
---|
| 32 | // custom event processing |
---|
| 33 | dojo.connect(m1, "onMoved", function(mover, shift){ |
---|
| 34 | var o = line.getShape(); |
---|
| 35 | line.setShape({x1: o.x1 + shift.dx, y1: o.y1 + shift.dy, x2: o.x2, y2: o.y2}); |
---|
| 36 | }); |
---|
| 37 | dojo.connect(m2, "onMoved", function(mover, shift){ |
---|
| 38 | var o = line.getShape(); |
---|
| 39 | line.setShape({x1: o.x1, y1: o.y1, x2: o.x2 + shift.dx, y2: o.y2 + shift.dy}); |
---|
| 40 | }); |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | function initGfx(){ |
---|
| 44 | container = dojo.byId("gfx_holder"); |
---|
| 45 | surface = dojox.gfx.createSurface(container, 500, 500); |
---|
| 46 | surface_size = {width: 500, height: 500}; |
---|
| 47 | |
---|
| 48 | makeCircles(); |
---|
| 49 | |
---|
| 50 | // cancel text selection and text dragging |
---|
| 51 | dojo.connect(container, "ondragstart", dojo, "stopEvent"); |
---|
| 52 | dojo.connect(container, "onselectstart", dojo, "stopEvent"); |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | dojo.addOnLoad(initGfx); |
---|
| 56 | |
---|
| 57 | </script> |
---|
| 58 | |
---|
| 59 | <style type="text/css"> |
---|
| 60 | .movable { cursor: pointer; } |
---|
| 61 | </style> |
---|
| 62 | |
---|
| 63 | </head> |
---|
| 64 | <body> |
---|
| 65 | <h1>dojox.gfx: 2 draggable circles</h1> |
---|
| 66 | <p>Warning: Canvas renderer doesn't implement event handling.</p> |
---|
| 67 | <div id="gfx_holder" style="width: 500px; height: 500px;"></div> |
---|
| 68 | </body> |
---|
| 69 | </html> |
---|