| 1 | <html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" > |
| 2 | <head> |
| 3 | <title>Drawing Test</title> |
| 4 | <style> |
| 5 | @import url("../../../dijit/themes/dijit.css"); |
| 6 | @import url("../../../dojox/drawing/resources/drawing.css"); |
| 7 | @import url("../../../dojox/drawing/resources/toolbar.css"); |
| 8 | @import url("../../../dojox/drawing/resources/GreekPalette.css"); |
| 9 | href, body{ |
| 10 | } |
| 11 | .drawing{ |
| 12 | margin-left:52px; |
| 13 | width:800px; |
| 14 | height:500px; |
| 15 | border:1px solid #ccc; |
| 16 | cursor:crosshair; |
| 17 | } |
| 18 | #data{ |
| 19 | display:block; |
| 20 | height:100px; |
| 21 | width:855px; |
| 22 | margin-top:5px; |
| 23 | } |
| 24 | button{ |
| 25 | border:2px solid #ccc; |
| 26 | border-color:#D9E1F9 #B5BCD0 #878E9D #C6CEE4; |
| 27 | background-color:#CDDCF3; |
| 28 | cursor:pointer; |
| 29 | } |
| 30 | </style> |
| 31 | |
| 32 | <script src="../../../dojo/dojo.js" data-dojo-config="async:1"></script> |
| 33 | <script> |
| 34 | require(["dojo/parser", "dojox/drawing", |
| 35 | // custom Tools and Plugins need to be required |
| 36 | "dojox/drawing/tools/TextBlock", |
| 37 | "dojox/drawing/tools/Rect", |
| 38 | "dojox/drawing/tools/Ellipse", |
| 39 | "dojox/drawing/tools/Line", |
| 40 | "dojox/drawing/tools/Path", |
| 41 | "dojox/drawing/tools/Pencil", |
| 42 | "dojox/drawing/tools/custom/Vector", |
| 43 | "dojox/drawing/tools/custom/Axes", |
| 44 | "dojox/drawing/tools/Arrow", |
| 45 | "dojox/drawing/plugins/tools/Pan", |
| 46 | "dojox/drawing/plugins/tools/Zoom", |
| 47 | "dojox/drawing/plugins/tools/Iconize", |
| 48 | "dojox/drawing/plugins/drawing/GreekPalette", |
| 49 | "dojox/drawing/plugins/drawing/Grid", |
| 50 | "dojox/drawing/ui/dom/Toolbar", |
| 51 | "dojox/drawing/ui/dom/Pan", |
| 52 | "dojox/drawing/ui/dom/Zoom", |
| 53 | "dojo/domReady!"], function(parser){ |
| 54 | parser.parse(); |
| 55 | |
| 56 | var doExport = function(){ |
| 57 | var o = myDrawing.exporter(); |
| 58 | console.log("EXPORT:") |
| 59 | console.dir(o) |
| 60 | console.log(dojo.toJson(o)); |
| 61 | dojo.byId("data").value = dojo.toJson(o, true); |
| 62 | } |
| 63 | |
| 64 | var doImport = function(){ |
| 65 | myDrawing.importer(dojo.fromJson(dojo.byId("data").value)); |
| 66 | } |
| 67 | |
| 68 | var doClear = function(){ |
| 69 | myDrawing.removeAll(); |
| 70 | } |
| 71 | |
| 72 | // myDrawing referenced by data-dojo-id |
| 73 | dojo.connect(myDrawing, "onSurfaceReady", function(){ |
| 74 | |
| 75 | var rect = myDrawing.addStencil("rect", {data:{x:50, y:275, width:100, height:100}}); |
| 76 | |
| 77 | |
| 78 | var json = '[{"color":"#0000FF","style":"Solid","cap":"round","fill":{"r":256,"g":0,"b":0,"a":0.5},"borderWidth":1,"x":413,"y":366,"width":100,"height":32,"type":"textBlock","text":"DojoX Drawing is Mike","pad":3,"size":"12px","family":"sans-serif","weight":"normal"},{"color":"#0000FF","style":"Solid","cap":"round","fill":{"r":256,"g":0,"b":0,"a":0.5},"borderWidth":1,"cx":732.5,"cy":197.54166412353516,"rx":54.5,"ry":187.54166412353516,"type":"ellipse"},{"color":"#000000","style":"Solid","cap":"round","fill":"#CCCCCC","borderWidth":1,"x1":430,"y1":342.0833282470703,"x2":675.4108328989848,"y2":143.3535541923843,"type":"line"},{"color":"#000000","style":"Solid","cap":"round","fill":"#CCCCCC","borderWidth":1,"x":499,"y":199.0833282470703,"width":100,"height":103,"type":"rect"},{"color":"#0000FF","style":"Solid","cap":"round","fill":{"r":256,"g":0,"b":0,"a":0.5},"borderWidth":1,"x":395,"y":354,"width":269,"height":19,"type":"textBlock","text":"DojoX Rocks with Socks","pad":3,"size":"24px","family":"sans-serif","weight":"bold"},{"color":"#0000FF","style":"Solid","cap":"round","fill":{"r":256,"g":0,"b":0,"a":0.5},"borderWidth":1,"cx":510.5,"cy":167.04166412353516,"rx":89.5,"ry":17.041664123535156,"type":"ellipse"}]'; |
| 79 | dojo.byId("data").value = json; |
| 80 | |
| 81 | |
| 82 | var textBlock = myDrawing.addStencil("textBlock", {data:{x:20, y:30, width:200, text:"DojoX Drawing Rocks"}}); |
| 83 | textBlock.attr({fill:{r:256,g:0,b:0,a:.5}, width:10, color:"#0000FF", size:"24px", weight:"bold"}); |
| 84 | |
| 85 | |
| 86 | var ellipse = myDrawing.addStencil("ellipse", {data:{cx:200, cy:200, rx:100, ry:50}}); |
| 87 | ellipse.attr({fill:{r:256,g:0,b:0,a:.5}, width:500, height:200, color:"#0000FF"}); |
| 88 | |
| 89 | |
| 90 | var arrow = myDrawing.addStencil("arrow", {data:{x1:400, y1:200, x2:500, y2:300}, arrowStart:true}); |
| 91 | arrow.attr({angle:210, radius:200, borderWidth:3, label:"My Arrow"}) |
| 92 | |
| 93 | var text = myDrawing.addStencil("text", {data:{x:300, y:260, width:200, text:"This is just text"}}); |
| 94 | |
| 95 | myDrawing.addStencil("path", {points:[{x:700, y:20},{x:650, y:150},{x:750,y:150}, {t:"Z", x:700, y:20}, {t:"M", x:700, y:40},{x:680, y:120},{x:720,y:120} ], shadow:{place:"C", size:4, mult:4, color:"#00ff00"}});// |
| 96 | |
| 97 | }); |
| 98 | |
| 99 | dojo.connect(dojo.byId("import"), "click", doImport); |
| 100 | dojo.connect(dojo.byId("export"), "click", doExport); |
| 101 | dojo.connect(dojo.byId("clear"), "click", doClear); |
| 102 | dojo.connect(dojo.byId("selectall"), "click", function(){ |
| 103 | myDrawing.selectAll(); |
| 104 | }); |
| 105 | |
| 106 | dojo.connect(dojo.byId("red"), "click", function(){ |
| 107 | myDrawing.changeDefaults({ |
| 108 | norm:{ |
| 109 | fill:"#ff0000", |
| 110 | width:5, |
| 111 | color:"#ff00ff" |
| 112 | } |
| 113 | }); |
| 114 | }); |
| 115 | dojo.connect(dojo.byId("blue"), "click", function(){ |
| 116 | myDrawing.changeDefaults({ |
| 117 | norm:{ |
| 118 | fill:"#0000ff", |
| 119 | width:5, |
| 120 | color:"#ffff00" |
| 121 | } |
| 122 | }); |
| 123 | }); |
| 124 | dojo.connect(dojo.byId("yellow"), "click", function(){ |
| 125 | myDrawing.toSelected("attr", { |
| 126 | fill:"#ffff00" |
| 127 | }); |
| 128 | }); |
| 129 | }); |
| 130 | |
| 131 | |
| 132 | </script> |
| 133 | |
| 134 | </head> |
| 135 | <body> |
| 136 | <h2>Drawing Test</h2> |
| 137 | <div id="conEdit" contenteditable="true"></div> |
| 138 | <div id="wrapper"> |
| 139 | <div dojoType="dojox.drawing.ui.dom.Toolbar" drawingId="drawingNode" class="drawingToolbar vertical"> |
| 140 | <div tool="dojox.drawing.tools.Line" selected="false">Line</div> |
| 141 | <div tool="dojox.drawing.tools.Rect" selected="false">Rect</div> |
| 142 | <div tool="dojox.drawing.tools.Ellipse" selected="false">Ellipse</div> |
| 143 | <div tool="dojox.drawing.tools.Path" selected="true">Path</div> |
| 144 | <div tool="dojox.drawing.tools.TextBlock" selected="false">Text</div> |
| 145 | <div tool="dojox.drawing.tools.Arrow" selected="false">Arrow</div> |
| 146 | <div tool="dojox.drawing.tools.custom.Vector" selected="false">Vector</div> |
| 147 | <div tool="dojox.drawing.tools.custom.Axes" selected="false">Axes</div> |
| 148 | <div plugin="dojox.drawing.ui.dom.Pan" options="{}">Pan</div> |
| 149 | <div plugin="dojox.drawing.ui.dom.Zoom" options="{zoomInc:.1,minZoom:.5,maxZoom:2}">Zoom</div> |
| 150 | |
| 151 | </div> |
| 152 | |
| 153 | <div dojoType="dojox.drawing.Drawing" id="drawingNode" data-dojo-id="myDrawing" drawingType="canvas" class="drawing" |
| 154 | plugins="[{'name':'dojox.drawing.plugins.drawing.Grid', 'options':{gap:100}}]"> |
| 155 | |
| 156 | </div> |
| 157 | </div> |
| 158 | |
| 159 | <br/> |
| 160 | <br/> |
| 161 | <button id="import">Import</button> |
| 162 | <button id="export">Export</button> |
| 163 | <button id="selectall">Select All</button> |
| 164 | <button id="clear">Clear Drawing</button> |
| 165 | |
| 166 | <button id="blue">Change defaults to Blue</button> |
| 167 | <button id="red">Change defaults to Red</button> |
| 168 | <button id="yellow">Change selected to Yellow</button> |
| 169 | <br/> |
| 170 | <br/> |
| 171 | |
| 172 | <textarea id="data"></textarea> |
| 173 | <div dojoType="dojox.drawing.plugins.drawing.GreekPalette" id="greekPalette"></div> |
| 174 | </body> |
| 175 | </html> |