Mercurial > laserkard
diff onlypaths/js/onlypaths_mini.js @ 46:26c2b3ad21c7 laserkard
[svn r47] saving progresswww.cinemassacre.com/new/?page_id=30
author | rlm |
---|---|
date | Sun, 31 Jan 2010 12:33:33 -0500 |
parents | |
children |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/onlypaths/js/onlypaths_mini.js Sun Jan 31 12:33:33 2010 -0500 1.3 @@ -0,0 +1,1188 @@ 1.4 +/*---------------------------------------------------------------------------- 1.5 + ONLYPATHS 0.1 1.6 + from 1.7 + RICHDRAW 1.0 1.8 + Vector Graphics Drawing Script 1.9 + ----------------------------------------------------------------------------- 1.10 + Created by Mark Finkle (mark.finkle@gmail.com) 1.11 + Implementation of simple vector graphic drawing control using SVG or VML. 1.12 + ----------------------------------------------------------------------------- 1.13 + Copyright (c) 2006 Mark Finkle 1.14 + 2008 Antimatter15 1.15 + 2008 Josep_ssv 1.16 + 1.17 + This program is free software; you can redistribute it and/or modify it 1.18 + under the terms of the MIT License. 1.19 + 1.20 + Permission is hereby granted, free of charge, to any person obtaining a 1.21 + copy of this software and associated documentation files (the "Software"), 1.22 + to deal in the Software without restriction, including without limitation 1.23 + the rights to use, copy, modify, merge, publish, distribute, sublicense, 1.24 + and/or sell copies of the Software, and to permit persons to whom the 1.25 + Software is furnished to do so, subject to the following conditions: 1.26 + The above copyright notice and this permission notice shall be included in 1.27 + all copies or substantial portions of the Software. 1.28 + 1.29 + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1.30 + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1.31 + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 1.32 + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 1.33 + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 1.34 + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 1.35 + DEALINGS IN THE SOFTWARE. 1.36 + ----------------------------------------------------------------------------- 1.37 + Dependencies: (SVG or VML rendering implementations) 1.38 + History: 1.39 + 2006-04-05 | Created richdraw.js 1.40 + 2008 | Update content and added framework ExtJS 1.41 + 2008-06-08 | Rename onlypaths.js 1.42 + --------------------------------------------------------------------------*/ 1.43 + 1.44 +var xpArray=new Array(); 1.45 +var ypArray=new Array(); 1.46 +var setPoints=new Array(); 1.47 + 1.48 +var inout='';//true; 1.49 +var typeTransform=''; 1.50 + 1.51 +var contmove=0; 1.52 +var zoomx=0; 1.53 +var zoomy=0; 1.54 +var zoomscale=1; 1.55 +var zoommode='frame'; //more minus frame 1.56 + 1.57 +// 1.58 + 1.59 +var data_path_close=true; 1.60 +var data_text_family=''; 1.61 +var data_text_size=19 1.62 +var data_text_messaje=''; 1.63 +var data_image_href=''; 1.64 + 1.65 +var numClics=0; 1.66 + 1.67 +//////////// 1.68 + 1.69 +function RichDrawEditor(elem, renderer) { 1.70 + this.container = elem; 1.71 + this.gridX = 10; 1.72 + this.gridY = 10; 1.73 + this.mouseDownX = 0; 1.74 + this.mouseDownY = 0; 1.75 + this.clicX = 0; 1.76 + this.clicY = 0; 1.77 + this.nowDraw=false; 1.78 + this.mode = ''; 1.79 + this.fillColor = ''; 1.80 + this.lineColor = ''; 1.81 + this.lineWidth = ''; 1.82 + this.selected = null; 1.83 + this.squareSelect = null; 1.84 + this.focusin = null; 1.85 + this.lineOpac = 1; 1.86 + this.fillOpac = 1; 1.87 + this.gridWidth = 1; 1.88 + this.opac = 1; 1.89 + //++ ; 1.90 + this.text_messaje=""; 1.91 + this.text_size=19; 1.92 + this.text_family="Arial"; 1.93 + 1.94 + this.pathsEdit = false; 1.95 + this.previusBox=null; 1.96 + this.initialPath=''; 1.97 + this.clipboard=null; 1.98 + this.moveNow=true; 1.99 + 1.100 + this.selectedBounds = { x:0, y:0, width:0, height: 0 }; 1.101 + this.onselect = function() {} 1.102 + this.onunselect = function() {} 1.103 + 1.104 + this.logtext = ""; 1.105 + 1.106 + this.renderer = renderer; 1.107 + this.renderer.init(this.container); 1.108 + this.renderer.editor = this; 1.109 + this.inputxy = []; 1.110 + this.onInputXY = function(){}; 1.111 + Ext.get(this.container).on('keypress', function(e){alert(e.keyCode);}); 1.112 + 1.113 + Ext.get(this.container).on( "mousedown", this.onMouseDown,this); 1.114 + Ext.get(this.container).on( "mouseup", this.onMouseUp,this); 1.115 + //Ext.get(this.container).on( "mouseout", this.outShape,this); 1.116 + //Ext.get(this.container).on( "mouseover", this.overShape,this); 1.117 + Ext.get(this.container).on( "mousemove", this.onTranslate,this); 1.118 + Ext.get(this.container).on( "dblclick", this.onEndLine,this); 1.119 + Ext.get(this.container).on( "selectstart", this.onSelectStart,this); 1.120 + 1.121 + 1.122 + //Ext.get(this.container).on("keydown", keypresshandler, this); 1.123 + //Event.observe(this.container).on( "keydown", keypresshandler,this); 1.124 + //Ext.get(this.container).on( "keypress", this.onKeyPress,this); 1.125 + //Ext.get(this.container).on('keydown',this.onKeyPress,this); 1.126 + 1.127 +} 1.128 + 1.129 +RichDrawEditor.prototype.log = function(logtext){ 1.130 + //this.logtext = logtext 1.131 + if(document.forms[0].code){ 1.132 + document.forms[0].code.value = logtext 1.133 + } 1.134 +} 1.135 + 1.136 + 1.137 +RichDrawEditor.prototype.getshapes = function(){ 1.138 + return this.renderer.getshapes(); 1.139 +} 1.140 + 1.141 +RichDrawEditor.prototype.info = function(shape){ 1.142 + return this.renderer.info(shape) 1.143 +} 1.144 + 1.145 + 1.146 +RichDrawEditor.prototype.clearWorkspace = function() { 1.147 + this.container.innerHTML = ''; 1.148 +}; 1.149 + 1.150 +RichDrawEditor.prototype.deleteSelection = function() { 1.151 + if (this.selected) { 1.152 + this.renderer.remove(this.container.ownerDocument.getElementById('tracker')); 1.153 + this.renderer.remove(this.selected); 1.154 + this.selected = null; 1.155 + } 1.156 +}; 1.157 + 1.158 +RichDrawEditor.prototype.toFront = function(order) { 1.159 + if (this.selected) { 1.160 + this.renderer.index(this.selected, order); 1.161 + } 1.162 +}; 1.163 + 1.164 +RichDrawEditor.prototype.deleteAll = function() { 1.165 + this.renderer.removeAll(); 1.166 +}; 1.167 + 1.168 + 1.169 +RichDrawEditor.prototype.select = function(elem) { 1.170 + if (elem == this.selected){ return; } 1.171 + this.selected = elem; 1.172 + this.renderer.showTracker(this.selected,this.pathsEdit); 1.173 + this.onselect(this); 1.174 +}; 1.175 + 1.176 + 1.177 +RichDrawEditor.prototype.unselect = function() { 1.178 + if (this.selected) { 1.179 + this.renderer.remove(this.container.ownerDocument.getElementById('tracker')); 1.180 + this.selected = null; 1.181 + this.onunselect(this); 1.182 + } 1.183 +}; 1.184 + 1.185 +RichDrawEditor.prototype.getSelectedElement = function() { 1.186 + return this.selected; 1.187 +}; 1.188 + 1.189 +RichDrawEditor.prototype.toCurve = function() { 1.190 + this.renderer.tocurve(); 1.191 +} 1.192 + 1.193 +RichDrawEditor.prototype.submitShape = function(data) { 1.194 + if (this.mode != 'select') { 1.195 + setMode('path', 'Path'); 1.196 + this.actualStyle(); 1.197 + onColorChange(); 1.198 + //shape, fillColor, lineColor, fillOpac, lineOpac, lineWidth, left, top, width, height, textMessaje, textSize, textFamily, imageHref, points, transform, parent 1.199 + //this.selected = this.renderer.datacreate(this.fillColor, this.lineColor, this.fillOpac, this.lineOpac, this.lineWidth, this.mouseDownX, this.mouseDownY, 1, 1,data); 1.200 + this.selected = this.renderer.create(this.mode, this.fillColor, this.lineColor, this.fillOpac, this.lineOpac, this.lineWidth, this.mouseDownX, this.mouseDownY, 1, 1,this.textMessaje,this.textSize,this.textFamily,this.imageHref, data, '', ''); 1.201 + 1.202 + this.selected.id = 'shape:' + createUUID(); 1.203 + Ext.get(this.selected).on("mousedown", this.onHit,this); 1.204 + setMode('select', 'Select'); 1.205 + } else { 1.206 + this.renderer.transformShape(this.selected,data,null); 1.207 + this.renderer.remove(this.container.ownerDocument.getElementById('tracker')); 1.208 + this.renderer.showTracker(this.selected,this.pathsEdit); 1.209 + } 1.210 +}; 1.211 + 1.212 +RichDrawEditor.prototype.setGrid = function(horizontal, vertical) { 1.213 + this.gridX = horizontal; 1.214 + this.gridY = vertical; 1.215 + this.gridWidth = (vertical+horizontal)/2; //average. ideally, it should be the same 1.216 +}; 1.217 + 1.218 + 1.219 +// ++ 1.220 +RichDrawEditor.prototype.actualStyle = function() 1.221 +{ 1.222 + this.textMessaje=$('option_text_message').value; 1.223 + this.textSize=parseFloat($('option_text_size').value); 1.224 + this.textFamily=$('option_text_family').value; 1.225 + this.pathClose = $('option_path_close').checked; 1.226 + this.imageHref = $('option_image_href').value; 1.227 + 1.228 + return; 1.229 +}; 1.230 + 1.231 + 1.232 +RichDrawEditor.prototype.editCommand = function(cmd, value) 1.233 +{ 1.234 + if (cmd == 'mode') 1.235 + { 1.236 + this.mode = value; 1.237 + } 1.238 + else if (this.selected == null) 1.239 + { 1.240 + if (cmd == 'fillcolor') 1.241 + { 1.242 + this.fillColor = value; 1.243 + } 1.244 + else if (cmd == 'linecolor') 1.245 + { 1.246 + this.lineColor = value; 1.247 + } 1.248 + else if (cmd == 'linewidth') 1.249 + { 1.250 + this.lineWidth = parseInt(value) + 'px'; 1.251 + } 1.252 + else if (cmd == 'fillopacity') { 1.253 + this.fillOpac = parseInt(value); 1.254 + } 1.255 + else if (cmd == 'lineopacity') { 1.256 + this.lineOpac = parseInt(value); 1.257 + } 1.258 + } 1.259 + else 1.260 + { 1.261 + this.renderer.editCommand(this.selected, cmd, value); 1.262 + } 1.263 +} 1.264 + 1.265 + 1.266 +RichDrawEditor.prototype.queryCommand = function(cmd) 1.267 +{ 1.268 + if (cmd == 'mode') 1.269 + { 1.270 + return this.mode; 1.271 + } 1.272 + else if (this.selected == null) 1.273 + { 1.274 + if (cmd == 'fillcolor') 1.275 + { 1.276 + return this.fillColor; 1.277 + } 1.278 + else if (cmd == 'linecolor') 1.279 + { 1.280 + return this.lineColor; 1.281 + } 1.282 + else if (cmd == 'linewidth') 1.283 + { 1.284 + return this.lineWidth; 1.285 + } 1.286 + else if (cmd == 'fillopacity') 1.287 + { 1.288 + return this.fillOpac; 1.289 + } 1.290 + else if (cmd == 'lineopacity') 1.291 + { 1.292 + return this.fillOpac; 1.293 + } 1.294 + } 1.295 + else 1.296 + { 1.297 + return this.renderer.queryCommand(this.selected, cmd); 1.298 + } 1.299 +} 1.300 + 1.301 + 1.302 + 1.303 + 1.304 +RichDrawEditor.prototype.onSelectStart = function(event) { 1.305 + return false 1.306 +} 1.307 + 1.308 + 1.309 +///////////////////////////// 1.310 + 1.311 + 1.312 + /* 1.313 + 1.314 +Event.observe(window, 'load', function() { 1.315 +Event.observe(document, 'keypress', function(e){ 1.316 +var code; 1.317 +if (!e) var e = window.event; 1.318 +if (e.keyCode) code = e.keyCode; 1.319 +else if (e.which) code = e.which; 1.320 +var character = String.fromCharCode(code); 1.321 +alert('Character was ' + character); 1.322 +}); 1.323 +}); 1.324 +*/ 1.325 + 1.326 +//////////////////////// 1.327 +/*RichDrawEditor.prototype.outShape = function(event) { 1.328 + if(typeTransform=='Translate') 1.329 + { 1.330 + typeTransform=''; 1.331 + } 1.332 +} 1.333 +RichDrawEditor.prototype.overShape = function(event) { 1.334 + typeTransform='Translate'; 1.335 + 1.336 +} 1.337 +*/ 1.338 +RichDrawEditor.prototype.onMouseDown = function(event) { 1.339 + 1.340 + clockdata(); 1.341 + 1.342 + //MODE NO SELECT 1.343 + if (this.mode != 'select') 1.344 + { 1.345 + var modeUsed=0; 1.346 + if (this.mode == 'zoom') 1.347 + { 1.348 + var offset = Ext.get(this.container).getXY(); 1.349 + var snappedX = Math.round((event.getXY()[0] - offset[0]) / this.gridX) * this.gridX; 1.350 + var snappedY = Math.round((event.getXY()[1] - offset[1]) / this.gridY) * this.gridY; 1.351 + //snappedX*=proporDiagonal; 1.352 + //snappedY*=proporDiagonal; 1.353 + 1.354 + //snappedX+=marginx; 1.355 + //snappedY+=marginy; 1.356 + var width=this.gridWidth; 1.357 + contmove=0; 1.358 + this.setGrid(width, width); 1.359 + this.unselect(); 1.360 + xpArray=new Array(); 1.361 + ypArray=new Array(); 1.362 + this.mouseDownX = zoomx+snappedX; 1.363 + this.mouseDownY = zoomy+snappedY; 1.364 + xpArray.push(this.mouseDownX); 1.365 + ypArray.push(this.mouseDownY); 1.366 + if(zoommode=='window'){ 1.367 + this.squareSelect= this.renderer.create('rect', 'none', "#000000", 1, 1, 1, this.mouseDownX, this.mouseDownY, 1, 1,this.textMessaje,this.textSize,this.textFamily,this.imageHref,'M0,0 1,1', '', ''); 1.368 + this.squareSelect.id = 'squareSelectID'; 1.369 + Ext.get(this.squareSelect).on( "mousedown", this.onHit,this); 1.370 + Ext.get(this.squareSelect).on( "mousemove", this.onDraw,this); 1.371 + 1.372 + }else{ 1.373 + this.renderer.zoom(this.mouseDownX, this.mouseDownY); 1.374 + } 1.375 + modeUsed=1; 1.376 + } //end zoom 1.377 + if (this.mode == 'controlpath') 1.378 + { 1.379 + this.actualStyle(); 1.380 + onColorChange(); 1.381 + if(numClics<=0) 1.382 + { 1.383 + this.nowDraw=true; 1.384 + setPoints=new Array(); 1.385 + var offset = Ext.get(this.container).getXY(); 1.386 + var snappedX = Math.round((event.getXY()[0] - offset[0]) / this.gridX) * this.gridX; 1.387 + var snappedY = Math.round((event.getXY()[1] - offset[1]) / this.gridY) * this.gridY; 1.388 + //snappedX*=proporDiagonal; 1.389 + //snappedY*=proporDiagonal; 1.390 + //snappedX+=marginx; 1.391 + //snappedY+=marginy; 1.392 + var width=this.gridWidth; 1.393 + contmove=0; 1.394 + this.setGrid(width, width); 1.395 + this.unselect(); 1.396 + xpArray=new Array(); 1.397 + ypArray=new Array(); 1.398 + this.mouseDownX = zoomx+snappedX; 1.399 + this.mouseDownY = zoomy+snappedY; 1.400 + xpArray.push(this.mouseDownX); 1.401 + ypArray.push(this.mouseDownY); 1.402 + setPoints.push(this.mouseDownX+','+this.mouseDownY); 1.403 + // ++ ; 1.404 + onColorChange(); 1.405 + this.actualStyle(); 1.406 + // ++ ; 1.407 + //shape, fillColor, lineColor, fillOpac, lineOpac, lineWidth, left, top, width, height, textMessaje, textSize, textFamily, imageHref, points, transform, parent 1.408 + //this.selected = this.renderer.create(this.mode, this.fillColor, this.lineColor, this.fillOpac, this.lineOpac, this.lineWidth, this.mouseDownX, this.mouseDownY, 1, 1,this.textMessaje,this.textSize,this.textFamily,this.imageHref, ''); 1.409 + 1.410 + this.selected = this.renderer.create(this.mode, this.fillColor, this.lineColor, this.fillOpac, this.lineOpac, this.lineWidth, this.mouseDownX, this.mouseDownY, 1, 1,this.textMessaje,this.textSize,this.textFamily,this.imageHref, 'M0,0 1,1', '', ''); 1.411 + 1.412 + this.selected.id = 'shape:' + createUUID(); 1.413 + Ext.get(this.selected).on( "mousedown", this.onHit,this); 1.414 + this.log(this.selected.id); 1.415 + 1.416 + Ext.get(this.selected).on( "dblclick", this.onEndLine,this); 1.417 + Ext.get(this.container).on( "mousemove", this.onDraw,this); 1.418 + numClics++; 1.419 + } 1.420 + else 1.421 + { 1.422 + var coord=this.inputxy; 1.423 + var X=parseFloat(coord[0]); 1.424 + var Y=parseFloat(coord[1]); 1.425 + setPoints.push(X+','+Y); 1.426 + this.renderer.clic(this.selected); 1.427 + numClics++; 1.428 + } 1.429 + modeUsed=1; 1.430 + } //end mode controlpath 1.431 + if (modeUsed == 0) 1.432 + { 1.433 + var offset = Ext.get(this.container).getXY(); 1.434 + var snappedX = Math.round((event.getXY()[0] - offset[0]) / this.gridX) * this.gridX; 1.435 + var snappedY = Math.round((event.getXY()[1] - offset[1]) / this.gridY) * this.gridY; 1.436 + //snappedX*=proporDiagonal; 1.437 + //snappedY*=proporDiagonal; 1.438 + //snappedX+=marginx; 1.439 + //snappedY+=marginy; 1.440 + 1.441 + var width=this.gridWidth; 1.442 + contmove=0; 1.443 + this.setGrid(width, width); 1.444 + this.unselect(); 1.445 + xpArray=new Array(); 1.446 + ypArray=new Array(); 1.447 + this.mouseDownX = zoomx+snappedX; 1.448 + this.mouseDownY = zoomy+snappedY; 1.449 + xpArray.push(this.mouseDownX); 1.450 + ypArray.push(this.mouseDownY); 1.451 + this.unselect(); 1.452 + onColorChange(); 1.453 + this.actualStyle(); 1.454 + //this.selected = this.renderer.create(this.mode, this.fillColor, this.lineColor, this.fillOpac, this.lineOpac, this.lineWidth, this.mouseDownX, this.mouseDownY, 1, 1,this.textMessaje,this.textSize,this.textFamily,this.imageHref,''); 1.455 + 1.456 + this.selected = this.renderer.create(this.mode, this.fillColor, this.lineColor, this.fillOpac, this.lineOpac, this.lineWidth, this.mouseDownX, this.mouseDownY, 1, 1,this.textMessaje,this.textSize,this.textFamily,this.imageHref,'M0,0 1,1', '', ''); 1.457 + 1.458 + this.selected.id = 'shape:' + createUUID(); 1.459 + //-- this.selected.id = this.mode+':' + createUUID(); 1.460 + Ext.get(this.selected).on( "mousedown", this.onHit,this); 1.461 + Ext.get(this.container).on( "mousemove", this.onDraw,this); 1.462 + //Ext.get(this.container).on( "mouseover", this.overShape,this); 1.463 + //Ext.get(this.container).on( "mouseout", this.outShape,this); 1.464 + } 1.465 + } 1.466 + else //----- MODE SELECT 1.467 + { 1.468 + 1.469 + var offset = Ext.get(this.container).getXY(); 1.470 + var snappedX = Math.round((event.getXY()[0] - offset[0]) / this.gridX) * this.gridX; 1.471 + var snappedY = Math.round((event.getXY()[1] - offset[1]) / this.gridY) * this.gridY; 1.472 + 1.473 + //snappedX*=proporDiagonal; 1.474 + //snappedY*=proporDiagonal; 1.475 + //snappedX+=marginx; 1.476 + //snappedY+=marginy; 1.477 + 1.478 + // if ((this.mouseDownX != snappedX && this.mouseDownY != snappedY) || typeTransform=='') 1.479 + if (this.mouseDownX != snappedX || this.mouseDownY != snappedY) 1.480 + { 1.481 + if(this.selected!=null && typeTransform=='Translate' ) 1.482 + { 1.483 + 1.484 + Ext.get(this.container).un("mousemove", this.onDrag); 1.485 + this.unselect(); 1.486 + } 1.487 + //typeTransform=''; 1.488 + } 1.489 + 1.490 + // if (typeTransform=='' && (this.mouseDownX != snappedX || this.mouseDownY != snappedY) ) 1.491 + // { 1.492 + //if(typeTransform=='Rotate' || typeTransform=='Translate'){ }else{ 1.493 + 1.494 + //this.unselect(); 1.495 + // } 1.496 + // } 1.497 + //else 1.498 + //{ 1.499 + // if(this.nowDraw==true){ alert('Double click, please'); this.onEndLineListener(event); return true;} 1.500 + //Ext.get(this.container).on( "mouseout", this.onRotate,this); 1.501 + 1.502 + 1.503 + // if (this.mouseDownX != snappedX || this.mouseDownY != snappedY) 1.504 + //{ 1.505 + if(typeTransform=='Translate') 1.506 + { 1.507 + inout='move';//true; 1.508 + //Event.observe(this.selected, "mousedown", this.onHit,this); 1.509 + //Ext.get(this.container).on( "mousemove", this.onDrag,this); 1.510 + this.renderer.remove(this.container.ownerDocument.getElementById('tracker')); 1.511 + 1.512 + } 1.513 + if(typeTransform=='Scale' || typeTransform=='Rotate') 1.514 + { 1.515 + inout='rotate_escale';//false 1.516 + Ext.get(this.container).on( "mousemove", this.onDrag,this); 1.517 + Ext.get(this.selected).on( "mousedown", this.onHit,this); 1.518 + this.renderer.remove(this.container.ownerDocument.getElementById('tracker')); 1.519 + 1.520 + //Ext.get(this.container).on( "mouseover", this.onTranslate,this); 1.521 + //Ext.get(this.container).on( "mouseout", this.onRotate,this); 1.522 + //this.unselect(); 1.523 + } 1.524 + //} //end typeTransform=='' 1.525 + } //end mode select 1.526 + return false; 1.527 +}; 1.528 + 1.529 + 1.530 +RichDrawEditor.prototype.onMouseUp = function(event) 1.531 +{ 1.532 + //Ext.get(this.selected).un("mousemove",this.onDrag) 1.533 + 1.534 + //MODE NO SELECT 1.535 + if (this.mode != 'select') 1.536 + { 1.537 + //this.renderer.restruct(this.selected); 1.538 + if(this.mode == 'controlpath') 1.539 + { 1.540 + //Event.observe(this.selected, "mousemove", this.onClic,this); 1.541 + //this.renderer.info(this.selected); 1.542 + } 1.543 + else 1.544 + { 1.545 + //ZOOM 1.546 + if (this.mode == 'zoom') 1.547 + { 1.548 + var offset = Ext.get(this.container).getXY() 1.549 + var snappedX = Math.round(zoomx+((event.getXY()[0] - offset[0]) / this.gridX) * this.gridX); 1.550 + var snappedY = Math.round(zoomy+((event.getXY()[1] - offset[1]) / this.gridY) * this.gridY); 1.551 + 1.552 + //snappedX*=proporDiagonal; 1.553 + //snappedY*=proporDiagonal; 1.554 + //snappedX+=marginx; 1.555 + //snappedY+=marginy; 1.556 + this.renderer.zoom(snappedX, snappedY); 1.557 + this.renderer.remove(this.container.ownerDocument.getElementById('squareSelectID')); 1.558 + Ext.get(this.container).un("mousemove", this.onDraw); 1.559 + this.squareSelect = null; 1.560 + this.selected = null; 1.561 + }else{ 1.562 + Ext.get(this.container).un("mousemove", this.onDraw); 1.563 + this.selected = null; 1.564 + } 1.565 + } 1.566 + } 1.567 + else //MODE SELECT 1.568 + { 1.569 + Ext.get(this.container).un("mousemove", this.onDraw); //or drag 1.570 + //Ext.get(this.container).un("mousemove", this.onDrag); 1.571 + Ext.get(this.container).un("mousemove", this.onDrag); 1.572 + 1.573 + moveNow=false; 1.574 + contmove=0; 1.575 + // if(inout=='move' || inout=='rotate_scale' ){ 1.576 + if(typeTransform=="Rotate" || typeTransform=="Scale" ) 1.577 + { 1.578 + //this.renderer.remove(this.container.ownerDocument.getElementById('tracker')); 1.579 + this.renderer.showTracker(this.selected,this.pathsEdit); 1.580 + 1.581 + //inout='move';//true; 1.582 + //this.renderer.restruct(this.selected); 1.583 + typeTransform==''; 1.584 + } 1.585 + if(typeTransform=="Translate" ) 1.586 + { 1.587 + 1.588 + this.renderer.showTracker(this.selected,this.pathsEdit); 1.589 + //Ext.get(this.container).un("mousemove", this.renderer.move); 1.590 + //Ext.get(this.container).un("mousemove", this.onDrag); 1.591 + typeTransform==''; 1.592 + //this.renderer.restruct(this.selected); 1.593 + //this.unselect(); 1.594 + contmove=0; 1.595 + 1.596 + } 1.597 + if(inout=='multiSelect') 1.598 + { 1.599 + 1.600 + //inout='move';//true; 1.601 + } 1.602 + 1.603 + typeTransform==''; 1.604 + } 1.605 + //Event.stopObserving(this.container, "mousemove", this.onDraw,this); 1.606 +}; 1.607 + 1.608 + 1.609 +RichDrawEditor.prototype.onDrag = function(event) { 1.610 + 1.611 + moveNow=true; 1.612 + var offset = Ext.get(this.container).getXY(); 1.613 + var snappedX = Math.round((event.getXY()[0] - offset[0]) / this.gridX) * this.gridX; 1.614 + var snappedY = Math.round((event.getXY()[1] - offset[1]) / this.gridY) * this.gridY; 1.615 + //snappedX*=proporDiagonal; 1.616 + //snappedY*=proporDiagonal; 1.617 + //snappedX+=marginx; 1.618 + //snappedY+=marginy; 1.619 + 1.620 + var deltaX = snappedX - this.mouseDownX; 1.621 + var deltaY = snappedY - this.mouseDownY; 1.622 + 1.623 + var modeUsed=0; 1.624 + if(this.mode == 'zoom') 1.625 + { 1.626 + Ext.get(this.container).getXY(); 1.627 + this.renderer.resize(this.squareSelect, this.clicX,this.clicY, zoomx+(this.selectedBounds.x + deltaX), zoomy+(this.selectedBounds.y +deltaY)); 1.628 + //this.renderer.zoom(this.selectedBounds.x + deltaX, this.selectedBounds.y + deltaY); 1.629 + //this.renderer.zoom(this.mouseDownX, this.mouseDownY); 1.630 + 1.631 + modeUsed=1; 1.632 + } 1.633 + if(this.mode == 'controlpath') 1.634 + { 1.635 + modeUsed=1; 1.636 + } 1.637 + if(modeUsed==0) 1.638 + { 1.639 + if(inout=='multiSelect'){ 1.640 + this.renderer.showMultiSelect(this.mouseDownX, this.mouseDownY); 1.641 + } 1.642 + 1.643 + 1.644 + if(typeTransform=="Translate") 1.645 + { 1.646 + Ext.get(this.container).getXY(); 1.647 + 1.648 + 1.649 + //var coord=this.inputxy; 1.650 + //var moveX=parseFloat(coord[0]); 1.651 + //var moveY=parseFloat(coord[1]); 1.652 + this.log(this.mouseDownX+' '+event.getXY()[0]+' '+ this.selectedBounds.x +'contmove'+contmove); 1.653 + this.renderer.move(this.selected, zoomx+(this.selectedBounds.x + deltaX), zoomy+(this.selectedBounds.y +deltaY),this.clicX,this.clicY); 1.654 + //this.renderer.showTracker(this.selected,this.pathsEdit); 1.655 + 1.656 + } 1.657 + 1.658 + 1.659 + if(typeTransform=="Rotate") 1.660 + { 1.661 + this.renderer.rotateShape(this.selected, this.previusBox,deltaX, deltaY); 1.662 + //this.renderer.showTracker(this.selected,this.pathsEdit); 1.663 + } 1.664 + 1.665 + //if(typeTransform=="Scale") {this.renderer.scale(this.selected, this.previusBox, deltaX, deltaY); } 1.666 + if(typeTransform=="Scale") 1.667 + { 1.668 + this.renderer.scaleShape(this.selected, this.previusBox, this.selectedBounds.x + deltaX, this.selectedBounds.y + deltaY); 1.669 + //this.renderer.showTracker(this.selected,this.pathsEdit); 1.670 + } 1.671 + //if(typeTransform=="Scale") {this.renderer.scale(this.selected, this.previusBox, this.selectedBounds.width + deltaX, this.selectedBounds.height + deltaY); } 1.672 + 1.673 + //RichDrawEditor.prototype.onTransform(event); 1.674 + 1.675 + 1.676 + //} 1.677 + 1.678 + } 1.679 + // Update selection tracker 1.680 + //this.renderer.remove(this.container.ownerDocument.getElementById('tracker')); 1.681 + 1.682 + //this.renderer.remove(this.container.ownerDocument.getElementById('tracker')); 1.683 + 1.684 +// hide_tracker(); 1.685 +}; 1.686 + 1.687 + 1.688 +RichDrawEditor.prototype.onResize = function(event) { 1.689 + var offset = Ext.get(this.container).getXY(); 1.690 + var snappedX = Math.round((event.getXY()[0] - offset[0]) / this.gridX) * this.gridX; 1.691 + var snappedY = Math.round((event.getXY()[1] - offset[1]) / this.gridY) * this.gridY; 1.692 + //snappedX*=proporDiagonal; 1.693 + //snappedY*=proporDiagonal; 1.694 + //snappedX+=marginx; 1.695 + //snappedY+=marginy; 1.696 + var deltaX = snappedX - this.mouseDownX; 1.697 + var deltaY = snappedY - this.mouseDownY; 1.698 + 1.699 + this.renderer.track(handle, deltaX, deltaY); 1.700 + 1.701 + // Update selection tracker 1.702 + show_tracker(); 1.703 +// hide_tracker(); 1.704 +}; 1.705 + 1.706 + 1.707 +RichDrawEditor.prototype.onDraw = function(event) { 1.708 + if (this.selected == null) 1.709 + { 1.710 + if(this.squareSelect != null) 1.711 + { 1.712 + var offset = Ext.get(this.container).getXY() 1.713 + var snappedX = Math.round(zoomx+((event.getXY()[0] - offset[0]) / this.gridX) * this.gridX); 1.714 + var snappedY = Math.round(zoomy+((event.getXY()[1] - offset[1]) / this.gridY) * this.gridY); 1.715 + 1.716 + //snappedX*=proporDiagonal; 1.717 + //snappedY*=proporDiagonal; 1.718 + //snappedX+=marginx; 1.719 + //snappedY+=marginy; 1.720 + 1.721 + this.renderer.resize(this.squareSelect, this.mouseDownX, this.mouseDownY, snappedX, snappedY); 1.722 + 1.723 + }else{ 1.724 + return; 1.725 + } 1.726 + }else{ 1.727 + var offset = Ext.get(this.container).getXY() 1.728 + var snappedX = Math.round(zoomx+((event.getXY()[0] - offset[0]) / this.gridX) * this.gridX); 1.729 + var snappedY = Math.round(zoomy+((event.getXY()[1] - offset[1]) / this.gridY) * this.gridY); 1.730 + 1.731 + //snappedX*=proporDiagonal; 1.732 + //snappedY*=proporDiagonal; 1.733 + //snappedX+=marginx; 1.734 + //snappedY+=marginy; 1.735 + 1.736 + this.renderer.resize(this.selected, this.mouseDownX, this.mouseDownY, snappedX, snappedY); 1.737 + } 1.738 +}; 1.739 + 1.740 +RichDrawEditor.prototype.onRotate = function(event) { 1.741 + if (this.selected == null) 1.742 + { 1.743 + 1.744 + }else{ 1.745 + // this.renderer.remove(this.container.ownerDocument.getElementById('tracker')); 1.746 + //document.getElementById('richdraw').style.cursor='e-resize'; 1.747 + 1.748 + //alert('chao'); 1.749 + //inout=false; 1.750 + 1.751 + //return; 1.752 + } 1.753 +}; 1.754 + 1.755 +RichDrawEditor.prototype.onScale = function(event) { 1.756 + if (this.selected == null) 1.757 + { 1.758 + 1.759 + }else{ 1.760 + //document.getElementById('richdraw').style.cursor='e-resize'; 1.761 + //alert('chao'); 1.762 + //inout=false; 1.763 + 1.764 + //return; 1.765 + } 1.766 +}; 1.767 + 1.768 +RichDrawEditor.prototype.onTransform = function(event) { 1.769 + if (this.selected == null) 1.770 + { 1.771 + 1.772 + }else{ 1.773 + //if(typeTransform=="rotate") {this.renderer.rotate(this.selected, this.selectedBounds.x + deltaX, this.selectedBounds.y + deltaY);} 1.774 + //if(typeTransform=="scale") {this.renderer.scale(this.selected, this.selectedBounds.x + deltaX, this.selectedBounds.y + deltaY); } 1.775 + 1.776 + } 1.777 +}; 1.778 + 1.779 +RichDrawEditor.prototype.onTranslate = function(event) { 1.780 + if (this.selected == null) 1.781 + { 1.782 + 1.783 + }else{ 1.784 + // document.getElementById('richdraw').style.cursor='move'; 1.785 + //alert('hello'); 1.786 + //inout=true; 1.787 + 1.788 + //return; 1.789 + } 1.790 + var offset = Ext.get(this.container).getXY() 1.791 + // var offset = Ext.get(this.container).getXY(); 1.792 + var x = zoomx+Math.round(event.getXY()[0] - offset[0]); 1.793 + var y = zoomy+Math.round(event.getXY()[1] - offset[1]); 1.794 + 1.795 + //var x= parseFloat(event.getXY()[0]); 1.796 + //var y= parseFloat(event.getXY()[1]); 1.797 + 1.798 + 1.799 + this.inputxy = [x,y] 1.800 + this.onInputXY(x,y); 1.801 + 1.802 + //Ext.get(this.container).getXY(); ;// 1.803 +}; 1.804 + 1.805 + 1.806 +RichDrawEditor.prototype.onHit = function(event) { 1.807 +//console.log("AAH HIT!!!!") 1.808 + if(this.mode == 'select') 1.809 + { 1.810 + 1.811 + //event.cancelBubble =false; 1.812 + // We've handled this event. Don't let anybody else see it. 1.813 + if (event.stopPropagation) event.stopPropagation(); // DOM Level 2 1.814 + else event.cancelBubble = true; // IE 1.815 + // Now prevent any default action. 1.816 + if (event.preventDefault) event.preventDefault(); // DOM Level 2 1.817 + else event.returnValue = false; // IE 1.818 + 1.819 + if(inout=='multiSelect') 1.820 + { 1.821 + //Ext.get(this.container).on( "mousemove", this.onDrag,this); 1.822 + //Ext.get(this.container).on( "mouseup", this.onMouseUp,this); 1.823 + 1.824 + } 1.825 + else 1.826 + { 1.827 + 1.828 + Ext.get(this.container).un("mousemove", this.onDrag); 1.829 + //this.unselect(); 1.830 + typeTransform="Translate"; 1.831 + 1.832 + /* //this.previusBox=this.selected; 1.833 + this.select(Event.element(event)); 1.834 + this.selectedBounds = this.renderer.bounds(this.selected); 1.835 + //document.forms[0].code.value=shape(c,this.selected); 1.836 + var offset = Ext.get(this.container).getXY(); 1.837 + this.mouseDownX = Math.round((event.getXY()[0] - offset[0]) / this.gridX) * this.gridX; 1.838 + this.mouseDownY = Math.round((event.getXY()[1] - offset[1]) / this.gridY) * this.gridY; 1.839 + this.renderer.info(this.selected); 1.840 + Ext.get(this.container).on( "mousemove", this.onDrag,this); 1.841 + //Ext.get(this.container).on( "mouseover", noselect); 1.842 + Ext.get(this.container).on( "mouseout", this.onMouseUp,this); 1.843 + //Ext.get(this.container).on( "mouseup", this.onMouseUp,this); 1.844 + //typeTransform=="Translate"; 1.845 + //if(typeTransform=="Rotate") {this.renderer.rotate(this.selected, this.previusBox,2, 2);} 1.846 + */ 1.847 + //var width = parseFloat(widths.options[widths.selectedIndex].value); 1.848 + 1.849 + contmove=0; 1.850 + //this.setGrid(this.lineWidth, width); 1.851 + var width=this.gridWidth; 1.852 + 1.853 + this.setGrid(width, width); 1.854 + 1.855 + this.select(event.getTarget()); 1.856 + this.previusBox=this.selected; 1.857 + 1.858 + //++ 1.859 + this.renderer.getProperties(this.selected); 1.860 + var offset = Ext.get(this.container).getXY(); 1.861 + 1.862 + this.selectedBounds = this.renderer.bounds(this.selected); 1.863 + //document.forms[0].code.value=shape(c,this.selected); 1.864 + //var snappedX = Math.round((event.getXY()[0] - offset[0])); 1.865 + //var snappedY = Math.round((event.getXY()[1] - offset[1])); 1.866 + 1.867 + //offset[0]-=marginx; 1.868 + //offset[1]-=marginy; 1.869 + var x =offset[0];//parseInt(this.selected.offsetLeft);//this.selectedBounds.x-event.getXY()[0];//this.inputxy[0]+ offset[0];//Math.round(event.getXY()[0] - offset[0]); 1.870 + var y =offset[1];//$(this.selected.id).offsetTop;;//parseInt(this.selected.offsetTop);//this.selectedBounds.y-event.getXY()[1];//this.inputxy[1]+ offset[1];//+Math.round(event.getXY()[1] - offset[1]); 1.871 + //alert(x+' '+y) 1.872 + this.mouseDownX =x;// offset[0];//zoomx+snappedX; 1.873 + this.mouseDownY =y;// offset[1];//zoomy+snappedY; 1.874 + //objectOffset(this.selected) 1.875 + // this.mouseDownX = Math.round(zoomx+((event.getXY()[0] - offset[0]) / this.gridX) * this.gridX); 1.876 + //this.mouseDownY = Math.round(zoomy+((event.getXY()[1] - offset[1]) / this.gridY) * this.gridY); 1.877 + this.log(this.gridX); 1.878 + this.renderer.info(this.selected); 1.879 + if(this.container.ownerDocument.getElementById('tracker')) 1.880 + { 1.881 + this.renderer.remove(this.container.ownerDocument.getElementById('tracker')); 1.882 + } 1.883 + Ext.get(this.container).on( "mousemove", this.onDrag,this); 1.884 + 1.885 + 1.886 + } 1.887 + } 1.888 + else 1.889 + { 1.890 + //this.selectedBounds = this.renderer.bounds(this.selected); 1.891 + var offset = Ext.get(this.container).getXY(); 1.892 + 1.893 + this.mouseDownX = Math.round(zoomx+((event.getXY()[0] - offset[0]) / this.gridX) * this.gridX); 1.894 + this.mouseDownY = Math.round(zoomy+((event.getXY()[1] - offset[1]) / this.gridY) * this.gridY); 1.895 + Ext.get(this.container).on( "mousemove", this.onDrag,this); 1.896 + 1.897 + } 1.898 +}; 1.899 + 1.900 + 1.901 +RichDrawEditor.prototype.onClic = function(event) { 1.902 + if(this.mode == 'controlpath') 1.903 + { 1.904 + 1.905 + //Ext.get(this.container).on( "mouseout", this.onMouseUp,this); 1.906 + 1.907 + //Ext.get(this.container).on( "mousemove", this.onDrag,this); 1.908 + 1.909 + //Ext.get(this.container).on( "mouseout", this.onDrag,this); 1.910 + } 1.911 + else 1.912 + { 1.913 + 1.914 + } 1.915 +}; 1.916 + 1.917 +RichDrawEditor.prototype.reflect = function(HorV) { 1.918 + this.selected=this.renderer.reflect(HorV); 1.919 + this.selected.id = 'shape:' + createUUID(); 1.920 + Ext.get(this.selected).on( "mousedown", this.onHit,this); 1.921 +} 1.922 + 1.923 +RichDrawEditor.prototype.onEndLine = function(event) { 1.924 + 1.925 + if(this.mode == 'controlpath') 1.926 + { // alert('hello'); 1.927 + numClics=0; 1.928 + //this.selected = null; 1.929 + 1.930 + //Event.stopObserving(this.container, "mousemove", this.onDraw,this); 1.931 + 1.932 + 1.933 + 1.934 + //Event.observe(this.selected, "mousedown", this.onHit,this); 1.935 + //Ext.get(this.container).on( "mousemove", this.onDraw,this); 1.936 + 1.937 + //Event.stopObserving(this.selected, "dblclick", this.onEndLine,this); 1.938 + //Event.stopObserving(this.container, "mousemove", this.onDraw,this); 1.939 + 1.940 + this.selected = null; 1.941 + 1.942 + 1.943 + //this.unselect(); 1.944 + 1.945 + } 1.946 + else 1.947 + { 1.948 + this.nowDraw=false; 1.949 + } 1.950 +}; 1.951 +function noselect(){ 1.952 + //typeTransform=""; 1.953 +} 1.954 + 1.955 +function createUUID() 1.956 +{ 1.957 + return [4, 2, 2, 2, 6].map(function(length) { 1.958 + var uuidpart = ""; 1.959 + for (var i=0; i<length; i++) { 1.960 + var uuidchar = parseInt((Math.random() * 256)).toString(16); 1.961 + if (uuidchar.length == 1) 1.962 + uuidchar = "0" + uuidchar; 1.963 + uuidpart += uuidchar; 1.964 + } 1.965 + return uuidpart; 1.966 + }).join('-'); 1.967 +} 1.968 + 1.969 + 1.970 +//---------------------------------------------------------------------------- 1.971 +// AbstractRenderer 1.972 +// 1.973 +// Abstract base class defining the drawing API. Can not be used directly. 1.974 +//---------------------------------------------------------------------------- 1.975 + 1.976 +function AbstractRenderer() { 1.977 + 1.978 +}; 1.979 + 1.980 +AbstractRenderer.prototype.init = function(elem) {}; 1.981 +AbstractRenderer.prototype.bounds = function(shape) { return { x:0, y:0, width:0, height: 0 }; }; 1.982 +AbstractRenderer.prototype.create = function(shape, fillColor, lineColor, lineWidth, left, top, width, height, textMessaje, textSize, textFamily, imageHref, transform) {}; 1.983 +AbstractRenderer.prototype.datacreate = function(fillColor, lineColor, lineWidth, fillOpac, strokeOpac, left, top, width, height,data) {}; 1.984 +AbstractRenderer.prototype.index = function(shape, order) {}; 1.985 +AbstractRenderer.prototype.remove = function(shape) {}; 1.986 +AbstractRenderer.prototype.copy = function(shape) {}; 1.987 +AbstractRenderer.prototype.paste = function(left,top) {}; 1.988 +AbstractRenderer.prototype.duplicate = function(shape) {}; 1.989 +AbstractRenderer.prototype.move = function(shape, left, top) {}; 1.990 +AbstractRenderer.prototype.endmove = function(shape) {}; 1.991 +AbstractRenderer.prototype.transform= function(shape, left, top) {}; 1.992 +AbstractRenderer.prototype.scale = function(shape, left, top) {}; 1.993 +AbstractRenderer.prototype.rotate = function(shape, left, top) {}; 1.994 +AbstractRenderer.prototype.track = function(shape) {}; 1.995 +AbstractRenderer.prototype.restruct = function(shape) {}; 1.996 +AbstractRenderer.prototype.resize = function(shape, fromX, fromY, toX, toY) {}; 1.997 +AbstractRenderer.prototype.editCommand = function(shape, cmd, value) {}; 1.998 +AbstractRenderer.prototype.queryCommand = function(shape, cmd) {}; 1.999 +AbstractRenderer.prototype.showTracker = function(shape,value) {}; 1.1000 +AbstractRenderer.prototype.getMarkup = function() { return null; }; 1.1001 +AbstractRenderer.prototype.info = function(shape){}; 1.1002 +AbstractRenderer.prototype.editShape = function(shape,data){}; 1.1003 +AbstractRenderer.prototype.onKeyPress = function(){}; 1.1004 + 1.1005 +AbstractRenderer.prototype.getshapes = function(){}; 1.1006 + 1.1007 + 1.1008 +//----------------------------- 1.1009 +// Geometry - string functions 1.1010 +//----------------------------- 1.1011 + 1.1012 +//two point angle deg 1.1013 +function ang2v(x1,y1,x2,y2) 1.1014 +{ 1.1015 + /* 1.1016 + var k=0; 1.1017 + 1.1018 + var sum1=u1+v1; 1.1019 + var sum2=u2+v2; 1.1020 + 1.1021 + var res1=u1-v1; 1.1022 + var res2=u2-v2; 1.1023 + 1.1024 + var ku1=k*u1; 1.1025 + var ku2=k*u2; 1.1026 + 1.1027 + var mu= Math.sqrt(u1*u1+u2*u2); 1.1028 + var mv= Math.sqrt(v1*v1+v2*v2); 1.1029 + 1.1030 + var pesc= u1*v1+u2*v2; 1.1031 + //var ang=Math.acos(pesc/(mu*mv))*180/Math.PI; 1.1032 + var ang=Math.acos(pesc/(mu*mv)); 1.1033 + */ 1.1034 + var resx=x2-x1; 1.1035 + var resy=y2-y1; 1.1036 + var ang=Math.atan2(resy,resx); 1.1037 + //alert(ang); 1.1038 + return ang; 1.1039 +} 1.1040 + 1.1041 +function dist2p(a,b,c,d) 1.1042 + { 1.1043 + with (Math) 1.1044 + { 1.1045 + //var d2p=sqrt(abs(((d-b)*(d-b) )+((c-a)*(c-a)))); //decimas(d2p,3); return d2p; 1.1046 + return sqrt(abs((d-b)*(d-b)+ (c-a)*(c-a))); 1.1047 + 1.1048 + } 1.1049 + } 1.1050 +function pmd2pb(a,b,c,d,q) { 1.1051 + pmdx= (1-q)*a+c*q; 1.1052 + pmdy= (1-q)*b+d*q; 1.1053 +//pmdx=decimas(pmdx,3); 1.1054 +//pmdy=decimas(pmdy,3); 1.1055 +var cad=pmdx+','+pmdy; 1.1056 +var sol= new Array(); 1.1057 +sol= [cad,pmdx,pmdy]; 1.1058 +return sol 1.1059 + 1.1060 +} 1.1061 + 1.1062 +function getAngle(dx,dy) { 1.1063 + var angle = Math.atan2(dy, dx); 1.1064 + //angle *= 180 / Math.PI; 1.1065 + return angle; 1.1066 + 1.1067 +} 1.1068 + 1.1069 +/* 1.1070 + 1.1071 +A = y2-y1 1.1072 +B = x1-x2 1.1073 +C = A*x1+B*y1 1.1074 +Regardless of how the lines are specified, you should be able to generate two different points along the line, and then generate A, B and C. Now, lets say that you have lines, given by the equations: 1.1075 +A1x + B1y = C1 1.1076 +A2x + B2y = C2 1.1077 +To find the point at which the two lines intersect, we simply need to solve the two equations for the two unknowns, x and y. 1.1078 + 1.1079 + double det = A1*B2 - A2*B1 1.1080 + if(det == 0){ 1.1081 + //Lines are parallel 1.1082 + }else{ 1.1083 + double x = (B2*C1 - B1*C2)/det 1.1084 + double y = (A1*C2 - A2*C1)/det 1.1085 + } 1.1086 + 1.1087 + 1.1088 + 1.1089 + 1.1090 +*/ 1.1091 +// interseccion 2 rectas 1.1092 +function ntrsccn2rb(a,b,c,d,e,f,g,h){ 1.1093 + var solution= new Array(); 1.1094 + var i2rx=0;var i2ry=0; 1.1095 + var w= (c-a)*(f-h)-(e-g)*(d-b); 1.1096 + if(w==0){ 1.1097 + n=1; 1.1098 + i2rx= (1-n)*a+n*c; 1.1099 + i2ry= (1-n)*b+n*d; 1.1100 + solution= ['',i2rx,i2ry]; 1.1101 + //Lines are parallel 1.1102 + return solution 1.1103 + //return (i2rx+' '+i2ry); 1.1104 + } 1.1105 + var n = (((e-a)*(f-h))-((e-g)*(f-b)))/w; 1.1106 + i2rx=(1-n)*a+n*c; 1.1107 + i2ry=(1-n)*b+n*d; 1.1108 + //return (i2rx+' '+i2ry); 1.1109 + solution= ['',i2rx,i2ry]; 1.1110 + return solution 1.1111 + 1.1112 +} 1.1113 + 1.1114 +//ecuacion implicita de la recta 1.1115 +function ccnmplct(a,b,c,d) { 1.1116 + var solution= new Array(); 1.1117 + //a1 a2, b1 b2 vector direccion b1-a1 , b2-a2 1.1118 + var v1m=c-a; 1.1119 + var v1n=d-b; 1.1120 + var c1x= v1m; 1.1121 + var c1y= v1n; 1.1122 + // ecuacion continua (x - a) /c -a = (y - b)/d - b 1.1123 + //(x - a) * v1n = (y - b) * v1m 1.1124 + //x * v1n - v1n*a = y * v1m - b* v1m 1.1125 + eia= v1n ; 1.1126 + eib= - v1m; 1.1127 + eic= (b* v1m) - ( v1n*a) 1.1128 + solution= [eia,eib,eic]; 1.1129 + return solution 1.1130 +} 1.1131 +function GetString(source, start, end){ 1.1132 +var st = source.indexOf(start) + start.length; 1.1133 +var en = source.indexOf(end, start); 1.1134 + return source.substring(st, en);//trimAll(source.substring(st, en)); 1.1135 +} 1.1136 + 1.1137 +function deg2rad(angle){ 1.1138 +return (angle/180) * Math.PI; 1.1139 +} 1.1140 + 1.1141 +String.prototype.trim = function(){ return this.replace(/^\s+|\s+$/g,'') } 1.1142 + 1.1143 +function objectOffset(obj) 1.1144 +{ 1.1145 + var posX=0; 1.1146 + var posY=0; 1.1147 + if(typeof(obj.offsetParent) != "undefined") 1.1148 + { 1.1149 + for(var x=0, y=0;obj; obj=obj.offsetParent) 1.1150 + { 1.1151 + x += obj.offsetLeft; 1.1152 + y += obj.offsetTop; 1.1153 + } 1.1154 + posX=x; 1.1155 + posY=y; 1.1156 + } 1.1157 + else 1.1158 + { 1.1159 + posX=obj.offsetLeft; 1.1160 + posY=obj.offsetTop; 1.1161 + } 1.1162 + alert(obj.id+" "+"X: "+posX+" Y: "+posY); 1.1163 +} 1.1164 + 1.1165 +function generateJSON(cssEnv) 1.1166 +{ 1.1167 + //string=string.replace(/;/g,'",') ; 1.1168 + //string=string.replace(/:/g,':"') ; 1.1169 + //style="fill:#7e0000;fill-opacity:1" 1.1170 + 1.1171 + var css=cssEnv.split(';') 1.1172 + 1.1173 + var strJSON = '{'; 1.1174 + ch = ','; 1.1175 + for (i = 0 ; i < css.length; i++) 1.1176 + { 1.1177 + var data=css[i].split(':'); 1.1178 + if(data[0]!=''){ 1.1179 + //if(i == (css.length-2)){ ch = ''; } 1.1180 + strJSON += "'"+data[0].trim()+"':'"+data[1].trim()+"'"+","; 1.1181 + } 1.1182 + 1.1183 + 1.1184 + } 1.1185 + var num= strJSON.length; 1.1186 + strJSON=strJSON.substr(0, num-1); 1.1187 + 1.1188 + strJSON += '}'; 1.1189 + 1.1190 + return strJSON; 1.1191 +} 1.1192 \ No newline at end of file