From 4b83774cdbfbf30add9a8fa2f11b1c4ff35179fa Mon Sep 17 00:00:00 2001 From: hwc487 Date: Thu, 26 Apr 2012 12:50:57 -0700 Subject: canvas interaction --- assets/canvas-runtime.js | 110 +++++++++++++++++++++++------------ js/document/html-document.js | 16 ++--- js/helper-classes/3D/snap-manager.js | 10 ++-- js/lib/drawing/world.js | 2 +- js/tools/ShapeTool.js | 18 +++++- 5 files changed, 104 insertions(+), 52 deletions(-) diff --git a/assets/canvas-runtime.js b/assets/canvas-runtime.js index ee9f24a4..b2db2cbd 100644 --- a/assets/canvas-runtime.js +++ b/assets/canvas-runtime.js @@ -116,7 +116,8 @@ NinjaCvsRt.GLRuntime = function ( canvas, jObj, assetPath ) this._aspect = canvas.width/canvas.height; - this._geomRoot = null; + //this._geomRoot = null; + this._rootChildren = []; // all "live" materials this._materials = []; @@ -152,26 +153,36 @@ NinjaCvsRt.GLRuntime = function ( canvas, jObj, assetPath ) this.loadScene = function() { var jObj = this._jObj; - if (!jObj.children || (jObj.children.length != 1)) + if (!jObj.children) // || (jObj.children.length != 1)) throw new Error( "ill-formed JSON for runtime load: " + jObj ); - var root = jObj.children[0]; + var nChildren = jObj.children.length; // parse the data + var child; if (jObj.scenedata) { this._useWebGL = true; var rdgeStr = jObj.scenedata; this.myScene.importJSON( rdgeStr ); - this.importObjects( root ); - this.linkMaterials( this._geomRoot ); + for (var i=0; i 0.001) - ctx.quadraticCurveTo( inset, height-inset, inset+rad, height-inset ); + ctx.quadraticCurveTo( inset+xOff, height-inset+yOff, inset+rad+xOff, height-inset+yOff ); // do the bottom of the rectangle pt = [width - inset, height - inset]; rad = brRad - inset; if (rad < 0) rad = 0; pt[0] -= rad; - ctx.lineTo( pt[0], pt[1] ); + ctx.lineTo( pt[0]+xOff, pt[1]+yOff ); // get the bottom right arc if (rad > 0.001) - ctx.quadraticCurveTo( width-inset, height-inset, width-inset, height-inset-rad ); + ctx.quadraticCurveTo( width-inset+xOff, height-inset+yOff, width-inset+xOff, height-inset-rad+yOff ); // get the right of the rectangle pt = [width - inset, inset]; rad = trRad - inset; if (rad < 0) rad = 0; pt[1] += rad; - ctx.lineTo( pt[0], pt[1] ); + ctx.lineTo( pt[0]+xOff, pt[1]+yOff ); // do the top right corner if (rad > 0.001) - ctx.quadraticCurveTo( width-inset, inset, width-inset-rad, inset ); + ctx.quadraticCurveTo( width-inset+xOff, inset+yOff, width-inset-rad+xOff, inset+yOff ); // do the top of the rectangle pt = [inset, inset]; rad = tlRad - inset; if (rad < 0) rad = 0; pt[0] += rad; - ctx.lineTo( pt[0], pt[1] ); + ctx.lineTo( pt[0]+xOff, pt[1]+yOff); // do the top left corner if (rad > 0.001) - ctx.quadraticCurveTo( inset, inset, inset, inset+rad ); + ctx.quadraticCurveTo( inset+xOff, inset+yOff, inset+xOff, inset+rad+yOff ); else - ctx.lineTo( inset, 2*inset ); + ctx.lineTo( inset+xOff, 2*inset+yOff ); } }; diff --git a/js/document/html-document.js b/js/document/html-document.js index ff5192b3..454b7154 100755 --- a/js/document/html-document.js +++ b/js/document/html-document.js @@ -207,16 +207,16 @@ exports.HTMLDocument = Montage.create(TextDocument, { var elt = this.documentRoot; if (elt) { + /* + // Use this code to test the runtime version of WebGL + var cdm = new NinjaCvsRt.CanvasDataManager(); + cdm.loadGLData(elt, value, null ); + */ + + // /* var nWorlds= value.length; for (var i=0; i= 1)) { this.rebuildTree(this._geomRoot); this.restartRenderLoop(); } diff --git a/js/tools/ShapeTool.js b/js/tools/ShapeTool.js index b2948fe7..74e692b6 100755 --- a/js/tools/ShapeTool.js +++ b/js/tools/ShapeTool.js @@ -69,6 +69,7 @@ exports.ShapeTool = Montage.create(DrawingTool, { drawData.planeMat, drawData.midPt, canvas, true); canvas.elementModel.isShape = true; + this.application.ninja.elementMediator.addElements(canvas, elementModel.data); } else { canvas = this._targetedElement; if (!canvas.getAttribute( "data-RDGE-id" )) @@ -77,8 +78,8 @@ exports.ShapeTool = Montage.create(DrawingTool, { if(!canvas.elementModel.shapeModel) { canvas.elementModel.shapeModel = Montage.create(ShapeModel); } + this.application.ninja.elementMediator.addElements(canvas, canvas.elementModel.data); } - this.application.ninja.elementMediator.addElements(canvas, canvas.elementModel.data); } this.endDraw(event); @@ -213,7 +214,20 @@ exports.ShapeTool = Montage.create(DrawingTool, { _useExistingCanvas: { value: function() { - return (this._targetedElement && !ShapesController.isElementAShape(this._targetedElement)); + var target; + if (this._targetedElement && (this._targetedElement.nodeName === "CANVAS") && !ShapesController.isElementAShape(this._targetedElement)) + target = this._targetedElement; + else + { + var container = this.application.ninja.currentSelectedContainer; + if (container && (container.nodeName === "CANVAS")) + { + target = container; + this._targetedElement = target; + } + } + + return target; } } -- cgit v1.2.3