From: <ma...@us...> - 2014-06-08 22:10:36
|
Revision: 2203 http://sourceforge.net/p/openautomation/code/2203 Author: mayerch Date: 2014-06-08 22:10:32 +0000 (Sun, 08 Jun 2014) Log Message: ----------- A bit better Bg positioning Modified Paths: -------------- GrAF/trunk/GrAFd/editor2/lib/gle.connection.js GrAF/trunk/GrAFd/editor2/lib/gle.js GrAF/trunk/GrAFd/editor2/lib/gle.settings.js GrAF/trunk/GrAFd/editor2/lib/gle.view.js Modified: GrAF/trunk/GrAFd/editor2/lib/gle.connection.js =================================================================== --- GrAF/trunk/GrAFd/editor2/lib/gle.connection.js 2014-06-08 12:38:02 UTC (rev 2202) +++ GrAF/trunk/GrAFd/editor2/lib/gle.connection.js 2014-06-08 22:10:32 UTC (rev 2203) @@ -35,6 +35,7 @@ // private: var self = this, worker = (typeof Worker !== 'undefined') ? new Worker("lib/autorouter.js") : undefined, + bottomRightPos, // bounding box /** * Remove double waypoints. * If the @param currentIndex gets a new number it's @returned. @@ -91,7 +92,13 @@ thisGLE.invalidateHandlers(); return newIndex; - }; + }, + updateBoundingBox = function() { + bottomRightPos = new Vec2D( 0, 0 ); + for( var i = self.waypoints.length - 1; i >= 0; i-- ) + bottomRightPos.cmax( self.waypoints[i] ); + console.log( 'update bounding box [' + self.name + ']:', bottomRightPos.print() ); + }; this.name = parameters.name; this.start = parameters.start; // object where the connection begins @@ -101,7 +108,10 @@ this.GLE = thisGLE; this.getBottomRight = function() { - return new Vec2D(-1,-1); + if( undefined === bottomRightPos ) + updateBoundingBox(); + + return bottomRightPos; } /** @@ -201,6 +211,9 @@ maxIdx = 'number' === typeof index ? index : index[1], maxPos = Array.isArray( newPos ) ? newPos[newPos.length-1] : newPos, myIdx = maxIdx; + + bottomRightPos = undefined; // invalidate current bounding box + //console.log( 'moveWaypoint', index, minIdx, maxIdx, newPos, absolute, waypoints.length ); // move prev point if( minIdx > 0 ) Modified: GrAF/trunk/GrAFd/editor2/lib/gle.js =================================================================== --- GrAF/trunk/GrAFd/editor2/lib/gle.js 2014-06-08 12:38:02 UTC (rev 2202) +++ GrAF/trunk/GrAFd/editor2/lib/gle.js 2014-06-08 22:10:32 UTC (rev 2203) @@ -329,6 +329,8 @@ newScale = self.settings.minScale; else if( newScale > self.settings.maxScale ) newScale = self.settings.maxScale; + else if( isNaN( newScale ) ) + newScale = scale; var zoomAnimation = function(){ var zoomStep = 0.05; @@ -359,9 +361,13 @@ var selectArea = function() { console.log( 'selecting ' + prevScreenPos.print() + ' -> ' + lastScreenPos.print() ); var - minPos = view.screen2canvas( prevScreenPos.copy().cmin( lastScreenPos ) ), - maxPos = view.screen2canvas( prevScreenPos.copy().cmax( lastScreenPos ) ), - indices = view.area2id( minPos, maxPos, 1, elementList.length ); + //minPos = view.screen2canvas( prevScreenPos.copy().cmin( lastScreenPos ) ), + //maxPos = view.screen2canvas( prevScreenPos.copy().cmax( lastScreenPos ) ), + minScreenPos = prevScreenPos.copy().cmin( lastScreenPos ), + maxScreenPos = prevScreenPos.copy().cmax( lastScreenPos ), + minPos = view.screen2canvas( minScreenPos ), + maxPos = view.screen2canvas( maxScreenPos ), + indices = view.area2id( minScreenPos, maxScreenPos, 1, elementList.length ); for( var i = 0; i < indices.length; i++ ) { var thisElement = elementList[ indices[i] ][0]; @@ -701,8 +707,10 @@ mouseState = mouseStateDrag; else { mouseState = mouseStateSelectDrag; - prevScreenPos = getMouseScreenPos( eventObject ); - self.startGesture( getMouseScreenPos( eventObject ), scale ); + //prevScreenPos = getMouseScreenPos( eventObject ); + prevScreenPos = getTouchScreenPos( eventObject )[0]; + //self.startGesture( getMouseScreenPos( eventObject ), scale ); + self.startGesture( prevScreenPos, scale ); } break; Modified: GrAF/trunk/GrAFd/editor2/lib/gle.settings.js =================================================================== --- GrAF/trunk/GrAFd/editor2/lib/gle.settings.js 2014-06-08 12:38:02 UTC (rev 2202) +++ GrAF/trunk/GrAFd/editor2/lib/gle.settings.js 2014-06-08 22:10:32 UTC (rev 2203) @@ -46,8 +46,8 @@ fontFamiliy : 'sans-serif', fontStyle : '', // e.g. 'italic' // the maximum sizes not to push the browser too hard - maxCanvasSize: new Vec2D( 1400, 1400 ), - maxCanvasArea: 3*1024*1024, + maxCanvasSize: new Vec2D( 2048, 2048 ), + maxCanvasArea: 5*1024*1024, // 5 MPix = limit for iOS with >256MB RAM // dummy element to catch the last ',' of the line above end:true }, Modified: GrAF/trunk/GrAFd/editor2/lib/gle.view.js =================================================================== --- GrAF/trunk/GrAFd/editor2/lib/gle.view.js 2014-06-08 12:38:02 UTC (rev 2202) +++ GrAF/trunk/GrAFd/editor2/lib/gle.view.js 2014-06-08 22:10:32 UTC (rev 2203) @@ -79,6 +79,13 @@ obj.height = vec.y + (postfix||0); }, /** + * Little helper to test if an object does not have a given size. + */ + neqSize = function( obj, vec, postfix ) { + return (obj.width !== (vec.x+(postfix||0))) || + (obj.height !== (vec.y+(postfix||0))); + }, + /** * Little helper function that returns a Vec2D with the current * scroll postion. */ @@ -118,6 +125,7 @@ makeIdDataValid(); //var idxPos = (Math.round(thisScreenPos.x*scale*scaleInternal) + drawSize.x * Math.round(thisScreenPos.y*scale*scaleInternal))|0; var idxPos = (Math.round(thisScreenPos.x*scaleInternal) + drawSize.x * Math.round(thisScreenPos.y*scaleInternal))|0; + //console.log( 'position2id', thisScreenPos.print(), thisScreenPos.copy().scale(scaleInternal).round(1).print() ); return ( (idData[ idxPos*4 ] << 16) + (idData[ idxPos*4+1 ] << 8) + idData[ idxPos*4+2 ] )|0; }, /** @@ -125,11 +133,12 @@ * The allowed index range is passed by minIndex and endIndex-1 */ area2id = function( pScreenMin, pScreenMax, minIndex, endIndex ) { - makeIdDataValid(); var - minPos = pScreenMin.copy().scale(scale*scaleInternal).round(1), - maxPos = pScreenMax.copy().scale(scale*scaleInternal).round(1), + //minPos = pScreenMin.copy().scale(scale*scaleInternal).round(1), + //maxPos = pScreenMax.copy().scale(scale*scaleInternal).round(1), + minPos = pScreenMin.copy().scale(scaleInternal).round(1), + maxPos = pScreenMax.copy().scale(scaleInternal).round(1), buffer = new ArrayBuffer( endIndex ), idxSet = new Int8Array(buffer), // preassign all loop variables for speed up @@ -159,7 +168,7 @@ for( x = minIndex; x < endIndex; x++ ) if( idxSet[x] === 1 ) retVal.push( x ); - console.log('area2id', retVal ); + //console.log('area2id', retVal, pScreenMin.print(), pScreenMax.print(),';',minPos.print(),maxPos.print() ); return retVal; //Object.keys( idxSet ); }, @@ -199,6 +208,10 @@ layersClamped = true; self.invalidateForeground(); // only the FG needs a redraw + + // move foreground out of the way + //$canvasFg[0].style.left = '0px'; + //$canvasFg[0].style.top = '0px'; }, /** * @@ -217,13 +230,47 @@ */ fixBackgroundPosition = function() { drawOffset = viewOffset.copy(); - //drawOffset = viewOffset.copy().minus( drawSize.copy().minus(screenSize).scale(0.5) ); + drawOffset = viewOffset.copy().minus( drawSize.copy().scale(1/scaleInternal).minus(screenSize).scale(0.5) ); + drawOffset.cmin( contentSize.copy().scale(scale).minus(drawSize.copy().scale(1/scaleInternal)) ); // no need to draw empty space in the bottom right + //drawOffset = ( contentSize.copy().scale(scale).minus(drawSize.copy().scale(1/scaleInternal)) ); // no need to draw empty space in the bottom right + drawOffset.cmax( new Vec2D( 0, 0 ) ); // no need to draw in the negative region + + console.log( 'fixBackgroundPosition:', + scale, scaleInternal, + 'drawOffset', drawOffset.print(), + 'viewOffset', viewOffset.print(), + 'drawSize', drawSize.print(), + 'contentSize', contentSize.print(), + 'screenSize', screenSize.print() + ); $canvasBg.css( cssTransform, 'matrix3d(1,0,0,0, 0,1,0,0, 0,0,1,0, '+drawOffset.x+','+drawOffset.y+',0,1)' ); // redraw: self.updateBg = true; self.invalidateContext(); }, + /** + * Resize background for optimal fix, e.g. after a zoom or resize event. + */ + fixBackgroundSize = function() { + var + clientSize = screenSize.copy().plus( viewOffset ) + .cmax( contentSize.copy().scale(scale) ) + .cmin( thisGLE.settings.maxCanvasSize.copy().scale(1/scaleInternal) ).floor(); + console.log( 'fixBackgroundSize', clientSize.print() ); + + if( !drawSize.equal( clientSize.copy().scale(scaleInternal).round(1) ) || + neqSize( $canvasBg[0].style, clientSize, 'px' ) ) + { + drawSize = clientSize.copy().scale(scaleInternal).round(1); + + applySize( $drawingPl[0].style, contentSize.copy().scale(scale), 'px' ); + //applySize( $drawingPl[0].style, clientSize, 'px' ); + applySize( $canvasBg[0], drawSize ); + applySize( $canvasBg[0].style, clientSize, 'px' ); + } + fixBackgroundPosition(); // put it on the correct position + }, foo = 0; @@ -344,6 +391,7 @@ */ this.draw = function() { clearCanvas( ctxId ); + ctxId.setTransform( 1, 0, 0, 1, 0.5 - 1*viewOffset.x*scaleInternal, 0.5 - 1*viewOffset.y*scaleInternal ); clearCanvas( ctxBg ); //console.log( 'draw ---------------------------------------------' ); $('#extra').text( 'Draw:' + (new Date().getTime()) ); @@ -392,10 +440,11 @@ this.drawFg = function() { var thisCtx = layersClamped ? ctxBg : ctxFg; //console.log( 'drawFg -------------------------------------------' ); - $('#extra').text( 'DrawFg:' + (new Date().getTime()) ); + //$('#extra').text( 'DrawFg:' + (new Date().getTime()) ); clearCanvas( ctxFg ); //ctxFg.setTransform( 1, 0, 0, 1, 0.5 - 1*$canvasContainer.scrollLeft()*scaleInternal, 0.5 - 1*$canvasContainer.scrollTop()*scaleInternal ); - ctxFg.setTransform( 1, 0, 0, 1, 0.5 - 1*drawOffset.x*scaleInternal, 0.5 - 1*drawOffset.y*scaleInternal ); + //ctxFg.setTransform( 1, 0, 0, 1, 0.5 - 1*drawOffset.x*scaleInternal, 0.5 - 1*drawOffset.y*scaleInternal ); + ctxFg.setTransform( 1, 0, 0, 1, 0.5 - 1*viewOffset.x*scaleInternal, 0.5 - 1*viewOffset.y*scaleInternal ); thisGLE.drawActive( thisCtx, ctxDummy, scale * scaleInternal ); // draw selection rectangle when defined @@ -502,14 +551,15 @@ viewOffset = contentPos.copy().scale(newScale).minus(screenPos).round(1). cmax( new Vec2D(0,0) ); applySize( $drawingPl[0].style, contentSize.copy().scale(newScale), 'px' ); - $canvasContainer.scrollLeft( viewOffset.x ); - $canvasContainer.scrollTop( viewOffset.y ); + //$canvasContainer.scrollLeft( viewOffset.x ); + //$canvasContainer.scrollTop( viewOffset.y ); + $canvasContainer[0].scrollLeft = viewOffset.x; + $canvasContainer[0].scrollTop = viewOffset.y; //viewOffset = getScroll(); // TODO really needed here? if( isTemporary ) { scale = newScale; - clampLayers(); var tS = newScale / oldScale; var thisScale = '' + (newScale / oldScale); // store already as string var trans = 'matrix3d(' + thisScale + ',0,0,0, 0,' + thisScale + ',0,0, 0,0,' + thisScale + ',0, '+tS*drawOffset.x+','+tS*drawOffset.y+',0,1)'; @@ -518,7 +568,7 @@ scale = oldScale = newScale; unclampLayers(); - fixBackgroundPosition(); + fixBackgroundSize(); self.draw(); // draw NOW, don't wait for the next animation frame } @@ -547,7 +597,8 @@ this.resizeSpace = function( newSpaceSize ) { contentSize = newSpaceSize.copy(); - self.resizeView(); + //self.resizeView(); + fixBackgroundSize(); }; /** @@ -588,11 +639,7 @@ //clientSize = screenSize.copy().plus( getScroll() ).cmax( contentSize.copy().scale(scale) ).cmin( thisGLE.settings.maxCanvasSize.copy().scale(1/scaleInternal) ).floor(), clientSize = screenSize.copy().plus( viewOffset ).cmax( contentSize.copy().scale(scale) ).cmin( thisGLE.settings.maxCanvasSize.copy().scale(1/scaleInternal) ).floor(), isFgViewResized = false, - isViewResized = false, - neqSize = function( obj, vec, postfix ) { - return (obj.width !== (vec.x+(postfix||0))) || - (obj.height !== (vec.y+(postfix||0))); - }; + isViewResized = false; // thisGLE.settings.maxCanvasSize // thisGLE.settings.maxCanvasArea @@ -610,8 +657,15 @@ applySize( $canvasFg[0], screenSize.copy().scale(scaleInternal).round(1) ); applySize( $canvasFg[0].style, screenSize, 'px' ); isFgViewResized = true; + + idBuffer.width = $canvasFg[0].width; + idBuffer.height = $canvasFg[0].height; + idBuffer.style.width = $canvasFg[0].style.width; // for debug FIXME + idBuffer.style.height = $canvasFg[0].style.height; // for debug FIXME } + fixBackgroundSize(); + /* if( !drawSize.equal( clientSize.copy().scale(scaleInternal).round(1) ) || neqSize( $canvasBg[0].style, clientSize, 'px' ) ) { @@ -622,11 +676,11 @@ applySize( $canvasBg[0].style, clientSize, 'px' ); isViewResized = true; - idBuffer.width = $canvasBg[0].width; - idBuffer.height = $canvasBg[0].height; - idBuffer.style.width = $canvasBg[0].style.width; // for debug FIXME - idBuffer.style.height = $canvasBg[0].style.height; // for debug FIXME - } + //idBuffer.width = $canvasBg[0].width; + //idBuffer.height = $canvasBg[0].height; + //idBuffer.style.width = $canvasBg[0].style.width; // for debug FIXME + //idBuffer.style.height = $canvasBg[0].style.height; // for debug FIXME + }*/ $('#extra').text(drawSize.x+'/'+drawSize.y+' ['+(drawSize.x*drawSize.y/1000000)+']'); showProps([ @@ -654,8 +708,11 @@ */ this.scroll = function( force ) { + if( layersClamped ) + return; + var currentScroll = getScroll(); - if( force || (!layersClamped && !viewOffset.equal( currentScroll ) ) ) { + if( force || !viewOffset.equal( currentScroll ) ) { viewOffset = currentScroll; $canvasFg[0].style.left = currentScroll.x + 'px'; $canvasFg[0].style.top = currentScroll.y + 'px'; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |