Commit 2778389ad5b0c18e24e7e2635116c85a8ff58c1d
1 parent
f0b1890f
Exists in
master
and in
7 other branches
Validação com JSLint
Showing
1 changed file
with
38 additions
and
35 deletions
Show diff stats
classesjs/classe_desenho.js
| 1 | +/*jslint white:false,undef: false, rhino: true, onevar: true, evil: false */ | ||
| 1 | /* | 2 | /* |
| 2 | Title: Desenho de elementos gráficos | 3 | Title: Desenho de elementos gráficos |
| 3 | 4 | ||
| @@ -27,7 +28,7 @@ GNU junto com este programa; se não, escreva para a | @@ -27,7 +28,7 @@ GNU junto com este programa; se não, escreva para a | ||
| 27 | Free Software Foundation, Inc., no endereço | 28 | Free Software Foundation, Inc., no endereço |
| 28 | 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA. | 29 | 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA. |
| 29 | */ | 30 | */ |
| 30 | -if(typeof(i3GEO) == 'undefined'){ | 31 | +if (typeof(i3GEO) === 'undefined'){ |
| 31 | i3GEO = []; | 32 | i3GEO = []; |
| 32 | } | 33 | } |
| 33 | /* | 34 | /* |
| @@ -85,9 +86,9 @@ i3GEO.desenho = { | @@ -85,9 +86,9 @@ i3GEO.desenho = { | ||
| 85 | linhas: [] | 86 | linhas: [] |
| 86 | }; | 87 | }; |
| 87 | try{ | 88 | try{ |
| 88 | - var divgeo = i3GEO.desenho.criaDivContainer(); | 89 | + var divgeo,renderer; |
| 90 | + divgeo = i3GEO.desenho.criaDivContainer(); | ||
| 89 | divgeo.innerHTML = ""; | 91 | divgeo.innerHTML = ""; |
| 90 | - var renderer; | ||
| 91 | // | 92 | // |
| 92 | //cria o objeto renderer conforme o browser em uso | 93 | //cria o objeto renderer conforme o browser em uso |
| 93 | //esse objeto será utilizado nas funções de desenho | 94 | //esse objeto será utilizado nas funções de desenho |
| @@ -98,7 +99,7 @@ i3GEO.desenho = { | @@ -98,7 +99,7 @@ i3GEO.desenho = { | ||
| 98 | renderer = new VMLRenderer(); | 99 | renderer = new VMLRenderer(); |
| 99 | i3GEO.desenho.richdraw = new RichDrawEditor(divgeo, renderer); | 100 | i3GEO.desenho.richdraw = new RichDrawEditor(divgeo, renderer); |
| 100 | } | 101 | } |
| 101 | - catch(e){ | 102 | + catch(erro){ |
| 102 | renderer = new SVGRenderer(); | 103 | renderer = new SVGRenderer(); |
| 103 | i3GEO.desenho.richdraw = new RichDrawEditor(divgeo, renderer); | 104 | i3GEO.desenho.richdraw = new RichDrawEditor(divgeo, renderer); |
| 104 | } | 105 | } |
| @@ -117,7 +118,7 @@ i3GEO.desenho = { | @@ -117,7 +118,7 @@ i3GEO.desenho = { | ||
| 117 | // | 118 | // |
| 118 | i3GEO.eventos.ativa(divgeo); | 119 | i3GEO.eventos.ativa(divgeo); |
| 119 | } | 120 | } |
| 120 | - catch(e){alert("Erro ao tentar criar container richdraw");} | 121 | + catch(erro){alert("Erro ao tentar criar container richdraw");} |
| 121 | }, | 122 | }, |
| 122 | /* | 123 | /* |
| 123 | Function: criaDivContainer | 124 | Function: criaDivContainer |
| @@ -133,17 +134,18 @@ i3GEO.desenho = { | @@ -133,17 +134,18 @@ i3GEO.desenho = { | ||
| 133 | */ | 134 | */ |
| 134 | criaDivContainer: function(){ | 135 | criaDivContainer: function(){ |
| 135 | if (!$i("divGeometriasTemp")){ | 136 | if (!$i("divGeometriasTemp")){ |
| 137 | + var pos,novoel,ne; | ||
| 136 | // | 138 | // |
| 137 | //pega a posição da imagem do mapa para posicionar corretamente o container | 139 | //pega a posição da imagem do mapa para posicionar corretamente o container |
| 138 | // | 140 | // |
| 139 | - var pos = [0,0]; | ||
| 140 | - var pos = i3GEO.util.pegaPosicaoObjeto($i(i3GEO.Interface.IDCORPO)); | 141 | + pos = [0,0]; |
| 142 | + pos = i3GEO.util.pegaPosicaoObjeto($i(i3GEO.Interface.IDCORPO)); | ||
| 141 | // | 143 | // |
| 142 | //cria o container | 144 | //cria o container |
| 143 | // | 145 | // |
| 144 | - var novoel = document.createElement("div"); | 146 | + novoel = document.createElement("div"); |
| 145 | novoel.id = "divGeometriasTemp"; | 147 | novoel.id = "divGeometriasTemp"; |
| 146 | - var ne = novoel.style; | 148 | + ne = novoel.style; |
| 147 | ne.cursor="crosshair"; | 149 | ne.cursor="crosshair"; |
| 148 | ne.zIndex=0; | 150 | ne.zIndex=0; |
| 149 | ne.position="absolute"; | 151 | ne.position="absolute"; |
| @@ -173,72 +175,73 @@ i3GEO.desenho = { | @@ -173,72 +175,73 @@ i3GEO.desenho = { | ||
| 173 | texto {string} - texto que será inserido no tipo "insereTexto" | 175 | texto {string} - texto que será inserido no tipo "insereTexto" |
| 174 | */ | 176 | */ |
| 175 | aplica: function(tipo,objeto,n,texto){ | 177 | aplica: function(tipo,objeto,n,texto){ |
| 178 | + var pos,r,elemento,elementos,dy,dx,w; | ||
| 176 | if(i3GEO.desenho.richdraw && $i(i3GEO.Interface.IDCORPO)){ | 179 | if(i3GEO.desenho.richdraw && $i(i3GEO.Interface.IDCORPO)){ |
| 177 | - var pos = i3GEO.util.pegaPosicaoObjeto($i(i3GEO.Interface.IDCORPO)); | 180 | + pos = i3GEO.util.pegaPosicaoObjeto($i(i3GEO.Interface.IDCORPO)); |
| 178 | // | 181 | // |
| 179 | //faz o reposicionamento de linhas quando o mouse é movido e a linha está ativa | 182 | //faz o reposicionamento de linhas quando o mouse é movido e a linha está ativa |
| 180 | // | 183 | // |
| 181 | - if((tipo=="resizeLinha") || (tipo=="resizePoligono") && navn){ | 184 | + if((tipo==="resizeLinha") || (tipo==="resizePoligono") && navn){ |
| 182 | try | 185 | try |
| 183 | {i3GEO.desenho.richdraw.renderer.resize(objeto,0,0,objposicaocursor.imgx,objposicaocursor.imgy);} | 186 | {i3GEO.desenho.richdraw.renderer.resize(objeto,0,0,objposicaocursor.imgx,objposicaocursor.imgy);} |
| 184 | - catch(e){window.status=n+" erro ao movimentar a linha ";} | 187 | + catch(erro){window.status=n+" erro ao movimentar a linha ";} |
| 185 | } | 188 | } |
| 186 | - if((tipo=="resizeLinha") && navm){ | 189 | + if((tipo==="resizeLinha") && navm){ |
| 187 | try{ | 190 | try{ |
| 188 | // | 191 | // |
| 189 | //no caso do ie, a linha tem de ser removida e desenhada novamente | 192 | //no caso do ie, a linha tem de ser removida e desenhada novamente |
| 190 | // | 193 | // |
| 191 | - var r = $i(i3GEO.desenho.richdraw.container.id); | 194 | + r = $i(i3GEO.desenho.richdraw.container.id); |
| 192 | //verifica se o elemento é do tipo texto, se for, pega o anterior a ele | 195 | //verifica se o elemento é do tipo texto, se for, pega o anterior a ele |
| 193 | - var elemento = r.lastChild; | ||
| 194 | - if(elemento.innerHTML != ""){ | ||
| 195 | - var elementos = r.childNodes; | 196 | + elemento = r.lastChild; |
| 197 | + if(elemento.innerHTML !== ""){ | ||
| 198 | + elementos = r.childNodes; | ||
| 196 | if(elementos.length > 3) | 199 | if(elementos.length > 3) |
| 197 | - var elemento = elementos[elementos.length - 3]; | 200 | + {elemento = elementos[elementos.length - 3];} |
| 198 | else | 201 | else |
| 199 | - var elemento = elementos[elementos.length - 2]; | 202 | + {elemento = elementos[elementos.length - 2];} |
| 200 | } | 203 | } |
| 201 | r.removeChild(elemento); | 204 | r.removeChild(elemento); |
| 202 | - var dy = objposicaocursor.imgy; | ||
| 203 | - var dx = objposicaocursor.imgx - (i3GEO.parametros.w/2); | 205 | + dy = objposicaocursor.imgy; |
| 206 | + dx = objposicaocursor.imgx - (i3GEO.parametros.w/2); | ||
| 204 | i3GEO.desenho.richdraw.renderer.create(i3GEO.desenho.richdraw.mode, i3GEO.desenho.richdraw.fillColor, i3GEO.desenho.richdraw.lineColor, i3GEO.desenho.richdraw.lineWidth, (pontosdistobj.ximg[n-1])-(i3GEO.parametros.w/2)-1,pontosdistobj.yimg[n-1]-3,dx,dy-3); | 207 | i3GEO.desenho.richdraw.renderer.create(i3GEO.desenho.richdraw.mode, i3GEO.desenho.richdraw.fillColor, i3GEO.desenho.richdraw.lineColor, i3GEO.desenho.richdraw.lineWidth, (pontosdistobj.ximg[n-1])-(i3GEO.parametros.w/2)-1,pontosdistobj.yimg[n-1]-3,dx,dy-3); |
| 205 | } | 208 | } |
| 206 | - catch(e){window.status=n+" erro ao movimentar a linha ";} | 209 | + catch(erro){window.status=n+" erro ao movimentar a linha ";} |
| 207 | } | 210 | } |
| 208 | - if((tipo=="resizePoligono") && navm){ | 211 | + if((tipo==="resizePoligono") && navm){ |
| 209 | try{ | 212 | try{ |
| 210 | - var r = $i(i3GEO.desenho.richdraw.container.id); | 213 | + r = $i(i3GEO.desenho.richdraw.container.id); |
| 211 | r.removeChild(r.lastChild); | 214 | r.removeChild(r.lastChild); |
| 212 | r.removeChild(r.lastChild); | 215 | r.removeChild(r.lastChild); |
| 213 | - var dy = objposicaocursor.imgy; | ||
| 214 | - var dx = objposicaocursor.imgx - (i3GEO.parametros.w/2); | 216 | + dy = objposicaocursor.imgy; |
| 217 | + dx = objposicaocursor.imgx - (i3GEO.parametros.w/2); | ||
| 215 | i3GEO.desenho.richdraw.renderer.create(i3GEO.desenho.richdraw.mode, i3GEO.desenho.richdraw.fillColor, i3GEO.desenho.richdraw.lineColor, i3GEO.desenho.richdraw.lineWidth, (pontosdistobj.ximg[n-1])-(i3GEO.parametros.w/2)-1,pontosdistobj.yimg[n-1]-3,dx,dy-3); | 218 | i3GEO.desenho.richdraw.renderer.create(i3GEO.desenho.richdraw.mode, i3GEO.desenho.richdraw.fillColor, i3GEO.desenho.richdraw.lineColor, i3GEO.desenho.richdraw.lineWidth, (pontosdistobj.ximg[n-1])-(i3GEO.parametros.w/2)-1,pontosdistobj.yimg[n-1]-3,dx,dy-3); |
| 216 | i3GEO.desenho.richdraw.renderer.create(i3GEO.desenho.richdraw.mode, i3GEO.desenho.richdraw.fillColor, i3GEO.desenho.richdraw.lineColor, i3GEO.desenho.richdraw.lineWidth, (pontosdistobj.ximg[0])-(i3GEO.parametros.w/2)-1,pontosdistobj.yimg[0]-3,dx,dy-3); | 219 | i3GEO.desenho.richdraw.renderer.create(i3GEO.desenho.richdraw.mode, i3GEO.desenho.richdraw.fillColor, i3GEO.desenho.richdraw.lineColor, i3GEO.desenho.richdraw.lineWidth, (pontosdistobj.ximg[0])-(i3GEO.parametros.w/2)-1,pontosdistobj.yimg[0]-3,dx,dy-3); |
| 217 | } | 220 | } |
| 218 | - catch(e){window.status=n+" erro ao movimentar a linha ";} | 221 | + catch(erro){window.status=n+" erro ao movimentar a linha ";} |
| 219 | } | 222 | } |
| 220 | - if(tipo=="insereCirculo"){ | ||
| 221 | - var dx = Math.pow(((pontosdistobj.xtela[n])*1) - ((pontosdistobj.xtela[n-1])*1),2); | ||
| 222 | - var dy = Math.pow(((pontosdistobj.ytela[n])*1) - ((pontosdistobj.ytela[n-1])*1),2); | ||
| 223 | - var w = Math.sqrt(dx + dy); | 223 | + if(tipo==="insereCirculo"){ |
| 224 | + dx = Math.pow(((pontosdistobj.xtela[n])*1) - ((pontosdistobj.xtela[n-1])*1),2); | ||
| 225 | + dy = Math.pow(((pontosdistobj.ytela[n])*1) - ((pontosdistobj.ytela[n-1])*1),2); | ||
| 226 | + w = Math.sqrt(dx + dy); | ||
| 224 | if (navn){ | 227 | if (navn){ |
| 225 | try{ | 228 | try{ |
| 226 | i3GEO.desenho.richdraw.renderer.create('circ', '', 'rgb(250,250,250)', i3GEO.desenho.richdraw.lineWidth, pontosdistobj.ximg[n-1],pontosdistobj.yimg[n-1],w,w); | 229 | i3GEO.desenho.richdraw.renderer.create('circ', '', 'rgb(250,250,250)', i3GEO.desenho.richdraw.lineWidth, pontosdistobj.ximg[n-1],pontosdistobj.yimg[n-1],w,w); |
| 227 | } | 230 | } |
| 228 | - catch(e){} | 231 | + catch(erro){} |
| 229 | } | 232 | } |
| 230 | else{ | 233 | else{ |
| 231 | try{ | 234 | try{ |
| 232 | i3GEO.desenho.richdraw.renderer.create('circ', '', 'rgb(250,250,250)', i3GEO.desenho.richdraw.lineWidth, pontosdistobj.ximg[n-1]-w,pontosdistobj.yimg[n-1]-w,w*2,w*2); | 235 | i3GEO.desenho.richdraw.renderer.create('circ', '', 'rgb(250,250,250)', i3GEO.desenho.richdraw.lineWidth, pontosdistobj.ximg[n-1]-w,pontosdistobj.yimg[n-1]-w,w*2,w*2); |
| 233 | } | 236 | } |
| 234 | - catch(e){} | 237 | + catch(erro){} |
| 235 | } | 238 | } |
| 236 | } | 239 | } |
| 237 | - if(tipo=="insereTexto"){ | 240 | + if(tipo==="insereTexto"){ |
| 238 | try{ | 241 | try{ |
| 239 | i3GEO.desenho.richdraw.renderer.create('text', '', 'rgb(250,250,250)', i3GEO.desenho.richdraw.lineWidth, pontosdistobj.ximg[n-1],pontosdistobj.yimg[n-1],"","",texto); | 242 | i3GEO.desenho.richdraw.renderer.create('text', '', 'rgb(250,250,250)', i3GEO.desenho.richdraw.lineWidth, pontosdistobj.ximg[n-1],pontosdistobj.yimg[n-1],"","",texto); |
| 240 | } | 243 | } |
| 241 | - catch(e){} | 244 | + catch(erro){} |
| 242 | } | 245 | } |
| 243 | } | 246 | } |
| 244 | } | 247 | } |