D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
var
/
www
/
html
/
crsys
/
Filename :
testeimagemJSVersao3 - Copia (3).php
back
Copy
<!DOCTYPE html> <html lang="pt-BR"> <head> <meta charset="UTF-8"> <title>Gerador de Imagem</title> <style> .checkbox-azul input[type="checkbox"] { display: none; /* esconde o checkbox nativo */ } .checkbox-azul span { width: 14px; height: 14px; background-color: #87CEFA; border: 1px solid #106ebe; /* rosa escuro */ border-radius: 3px; position: relative; } .checkbox-azul { display: inline-flex; align-items: center; cursor: pointer; } .checkbox-azul input[type="checkbox"]:checked + span::after { content: ''; position: absolute; top: 2px; left: 5px; width: 4px; height: 8px; border: solid white; border-width: 0 2px 2px 0; transform: rotate(45deg); } .checkbox-rosa { display: inline-flex; align-items: center; cursor: pointer; } .checkbox-rosa input[type="checkbox"] { display: none; /* esconde o checkbox nativo */ } .checkbox-rosa span { width: 14px; height: 14px; background-color: #C76E7A; border: 1px solid #d63384; /* rosa escuro */ border-radius: 3px; position: relative; } /* check branco quando marcado */ .checkbox-rosa input[type="checkbox"]:checked + span::after { content: ''; position: absolute; top: 2px; left: 5px; width: 4px; height: 8px; border: solid white; border-width: 0 2px 2px 0; transform: rotate(45deg); } .checkbox-verde { display: inline-flex; align-items: center; cursor: pointer; } .checkbox-verde input[type="checkbox"] { display: none; /* esconde o checkbox nativo */ } .checkbox-verde span { width: 14px; height: 14px; background-color: #109010; border: 1px solid #009000; /* rosa escuro */ border-radius: 3px; position: relative; } /* check branco quando marcado */ .checkbox-verde input[type="checkbox"]:checked + span::after { content: ''; position: absolute; top: 2px; left: 5px; width: 4px; height: 8px; border: solid white; border-width: 0 2px 2px 0; transform: rotate(45deg); } /* Container flex para alinhar canvas e input lado a lado */ #HsaiaDir { width: 36px; text-align: center; } /* garante que o wrapper se posicione relativo ao canvas */ #canvasWrapper { position: relative !important;/* referência para o input absoluto */ } #inputSaiaDirWrapper { position: absolute !important; top: 10px; */ /* fixo */ left: calc(100% + 10px)!important; /* à direita do canvas */ display: flex !important; align-items: center !important; gap: 6px !important; z-index: 2147483647!important; pointer-events: auto !important; } body { font-family: Arial, sans-serif; padding: 20px; } .linha-campos { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; margin-bottom: 15px; } .campo-inline { display: flex; align-items: center; gap: 5px; } .campo-inline label { white-space: nowrap; } input[type="text"], input[type="number"], select { padding: 4px 6px; width: 100px; } .preview { display: inline-block; background: #f4f4f4; padding: 4px 8px; border: 1px solid #ccc; margin-left: 80px !important; } canvas { display: block; } </style> </head> <body> <h1>Gerador de Imagem com Saia e Frontões - JS</h1> <form id="formImagem"> <!-- Linha 1: cor, largura, altura --> <div class="linha-campos"> <div class="campo-inline"> <label for="cor">Cor (hex):</label> <input type="text" id="cor" value="#4169e1" required> </div> <div class="campo-inline"> <label for="largura">Largura:</label> <input type="number" id="largura" value="300" min="5" required> </div> <div class="campo-inline"> <label for="altura">Altura:</label> <input type="number" id="altura" value="16" min="5" required> </div> </div> <div class="campo-inline"> <label for="tpo_duplo">Tampo duplo</label> <input type="checkbox" id="tpo_duplo"> </div> </div> <div class="container-fluid"> <div class="sub-container-planta" style="min-height: 150px; border: 1px solid #ccc; width: 30%; margin-bottom: 10px; position: relative;"> <div style="position: absolute; top: 4px; left: 6px; font-size: 0.75rem; font-weight: bold;"> Planta </div> <!-- Input H acima do retângulo --> <div style="text-align: center; margin-bottom: 2px; margin-top: 10px; position: relative; left: 4px;"> <label for="HPlanta" style="font-size: 0.70rem;">H</label> <input id="HPlanta" type="text" value="0" style="width: 22px !important; font-size: 0.70rem;"> </div> <div style="display: flex; gap: 8px; justify-content: center; margin-bottom: 5px; position: relative; left: 12px;"> <label class="checkbox-azul" class="text-center" style="transform: scale(0.9);"> <input type="checkbox" id="acabSup" name="acabSup" value="1" title="Acabamento superior" class="text-center"> <span class="text-center"></span> </label> <label class="checkbox-rosa" style="transform: scale(0.9);"> <input type="checkbox" id="saiaSup" name="saiaSup" value="1" title="Saia 3 ativa"> <span></span> </label> <label class="checkbox-verde" style="transform: scale(0.9);"> <input type="checkbox" id="fronSup" name="fronS" value="1" title="Saia 3 ativa"> <span></span> </label> </div> <div style="display: flex; align-items: center; justify-content: center; margin-top: 5px;"> <!-- Input P + Checkboxes à esquerda, fora do retângulo --> <div style="margin-left: 75px; margin-right: 0px; display: flex; flex-direction: row; align-items: center;"> <!-- Input P à esquerda --> <div style="display: flex; flex-direction: column; align-items: center; margin-right: 4px;"> <label for="PPlanta" style="font-size: 0.70rem;">P</label> <input id="PPlanta" type="text" value="0" style="width: 22px !important; font-size: 0.70rem;"> </div> <!-- Checkboxes à esquerda --> <div style="display: flex; flex-direction: column; align-items: center;"> <label class="checkbox-azul" class="text-center" style="transform: scale(0.9);"> <input type="checkbox" id="acabEsq" name="acabEsq" value="1" title="Acabamento esquerdo" class="text-center"> <span class="text-center"></span> </label> <label class="checkbox-rosa" style="margin-top: 4px; transform: scale(0.9);"> <input type="checkbox" id="saiaEsq" name="saiaEsq" value="1" title="Saia 3 ativa"> <span></span> </label> <label class="checkbox-verde" style="margin-top: 4px; transform: scale(0.9);"> <input type="checkbox" id="fronEsq" name="fronEsq" value="1" title="Saia 3 ativa"> <span></span> </label> </div> </div> <!-- Retângulo com canvas --> <div style="position: relative; border: 1px solid blue; width: 40%; height: 55px; box-sizing: border-box; margin-left: 3px; margin-right: auto;"> <!--<div style="position: relative; border: 1px solid blue; width: 40%; height: 55px; box-sizing: border-box; margin-left: -10px; margin-right: auto;"> --> <canvas id="canvasPlanta" style="width: 100%; height: 100%; display: block;"></canvas> <!-- Checkboxes abaixo do retângulo, centralizados --> <div style="position: absolute; bottom: -28px; left: 45%; transform: translateX(-50%); display: flex; gap: 8px;"> <label class="checkbox-azul" class="text-center" style="transform: scale(0.9);"> <input type="checkbox" id="acabInf" name="acabInf" value="1" title="Acabamento inferior" class="text-center"> <span class="text-center"></span> </label> <label class="checkbox-rosa" style="transform: scale(0.9);"> <input type="checkbox" id="saiaInf" name="saiaInf" value="1" title="Saia 3 ativa"> <span></span> </label> <label class="checkbox-verde" style="transform: scale(0.9);"> <input type="checkbox" id="fronInf" name="fronInf" value="1" title="Saia 3 ativa"> <span></span> </label> </div> </div> <!-- Checkbox à direita, fora do retângulo --> <!-- <div style="margin-left: 8px; display: flex; flex-direction: column; align-items: center;"> --> <div style="position: relative; left: -80px; display: flex; flex-direction: column; align-items: center;"> <label class="checkbox-azul" class="text-center" style="margin-top: 4px; transform: scale(0.9);"> <input type="checkbox" id="acabDir" name="acabDir" value="1" title="Acabamento direito" class="text-center"> <span class="text-center"></span> </label> <label class="checkbox-rosa" style="margin-top: 4px; transform: scale(0.9);"> <input type="checkbox" id="saiaDir" name="saiaDir" value="1" title="Saia 3 ativa"> <span></span> </label> <label class="checkbox-verde" style="margin-top: 4px; transform: scale(0.9);"> <input type="checkbox" id="fronDir" name="fronDir" value="1" title="Saia 3 ativa"> <span></span> </label> </div> </div> </div> <div id="sub-container-aa" class="sub-container-planta"> <canvas id="canvasPreview-aa" width="300" height="200" style="border: 1px solid #ccc; margin-bottom: 10px"></canvas> </div> <div class="sub-container-bb" style="margin-top: 0; padding-top: 0; border: 1px solid #ccc; width: 30%;"> <div style="position: relative;"> <div style="position: absolute; top: 4px; left: 6px; font-size: 0.75rem; font-weight: bold;"> Corte BB </div> </div> <div class="preview"> <div id="canvasWrapper"> <canvas id="canvasPreview"></canvas> <!-- Input lateral opcional para a Saia Direita --> <div id="inputSaiaDirWrapper" > <label for="HsaiaDir" style="font-size: 0.75rem; margin-top: 40px;" >H</label> <input id="HsaiaDir" type="text" value="0" style="width: 25px !important; font-size: 0.75rem; margin-top: 40px;"> </div> <div id="inputFronEsqWrapper" style="display: flex; align-items: center; gap: 10px;"> <label for="HfronEsq" style="margin: 0; font-size: 0.75rem">H</label> <input id="HfronEsq" type="text" value="0" style="width: 25px !important; font-size: 0.75rem"> </div> </div> </div> </div> </div> <div class="linha-campos"> <div class="campo-inline"> <label for="meiaesquad">Meia esquadria (esq/dir)</label> <input type="checkbox" id="meiaesquad" > </div> </div> </form> <script> // Utilitário de parse seguro const n = (id, min, def) => { const v = Number(document.getElementById(id).value); return Number.isFinite(v) ? Math.max(min, v) : def; }; // HEX -> RGB (#RGB e #RRGGBB) function hexToRgb(hex){ let h = hex.replace(/^#/, '').toLowerCase(); if (/^[0-9a-f]{3}$/.test(h)) h = h.split('').map(c => c + c).join(''); if (!/^[0-9a-f]{6}$/.test(h)) return [65,105,225]; // royalblue fallback return [parseInt(h.slice(0,2),16), parseInt(h.slice(2,4),16), parseInt(h.slice(4,6),16)]; } function gerarImagem(){ const largura = 250; const altura = 9; // espessura do perfil const saiaEsq = document.getElementById('saiaEsq').checked; const saiaDir = document.getElementById('saiaDir').checked; const fronEsq = document.getElementById('fronEsq').checked; const fronDir = document.getElementById('fronDir').checked; const meia = document.getElementById('meiaesquad').checked; const tpoDuplo = document.getElementById('tpo_duplo').checked; // const corHexRaw = document.getElementById('cor').value.trim(); const corHexRaw = '#4169e1'; // Mostrar/ocultar input lateral da direita // document.getElementById('inputSaiaDirWrapper').style.display = saiaDir ? 'flex' : 'none'; // Mostrar/ocultar input lateral da direita se qualquer saia estiver ativa document.getElementById('inputSaiaDirWrapper').style.display = (saiaEsq || saiaDir) ? 'flex' : 'none'; const [r,g,b] = hexToRgb(corHexRaw); const cor = `rgb(${r},${g},${b})`; const esp = 2; // Dimensões auxiliares const wSaiaEsq = saiaEsq ? altura : 0; const hSaiaEsq = saiaEsq ? Math.floor(largura/6) : 0; const wSaiaDir = saiaDir ? altura : 0; const hSaiaDir = saiaDir ? Math.floor(largura/6) : 0; const wFronEsq = fronEsq ? Math.floor(altura*0.9) : 0; const hFronEsq = fronEsq ? Math.floor(largura/6) : 0; const wFronDir = fronDir ? Math.floor(altura*0.9) : 0; const hFronDir = fronDir ? Math.floor(largura/6) : 0; const extraTopo = Math.max(hFronEsq, hFronDir); const extraBaixo = Math.max(hSaiaEsq, hSaiaDir); const extraEsq = wSaiaEsq + (fronEsq ? altura : 0); const extraDir = wSaiaDir + (fronDir ? altura : 0); const alturaTampo = extraTopo + altura + extraBaixo + 2*esp; const espacoEntre = Math.floor(largura/6) + altura; const alturaTotal = alturaTampo + (tpoDuplo ? espacoEntre + alturaTampo : 0); // Canvas const canvas = document.getElementById('canvasPreview'); canvas.width = largura + extraEsq + extraDir + 3*esp; // canvas.height = alturaTotal; canvas.height = 120; const ctx = canvas.getContext('2d'); // Estilo ctx.fillStyle = '#fff'; ctx.fillRect(0, 0, canvas.width, canvas.height); ctx.lineWidth = esp; ctx.strokeStyle = cor; ctx.lineJoin = 'miter'; ctx.lineCap = 'butt'; const origX = esp + extraEsq; // Função que desenha um "tampo" (barra superior + saias/frontões quando includeExtras=true) function desenharTampo(offsetY, includeExtras = true){ const origY = esp + extraTopo + offsetY; const rightX = origX + largura; const baseY = origY + altura; // --- Saia ESQUERDA --- if (includeExtras && saiaEsq){ const xL = origX - wSaiaEsq + altura; // externo da saia const xR = origX + altura; // interno (encosta no corpo) const y1 = origY + altura; // começa abaixo da barra const y2 = y1 + hSaiaEsq; if (meia){ // bordas da saia (só abaixo da barra) ctx.beginPath(); ctx.moveTo(xL, y1); ctx.lineTo(xL, y2); ctx.stroke(); // linha horizontal inferior removida intencionalmente ctx.beginPath(); ctx.moveTo(xR, y1); ctx.lineTo(xR, y2); ctx.stroke(); // diagonal e risquinhos de fechamento (canto esquerdo) ctx.beginPath(); ctx.moveTo(origX, origY); ctx.lineTo(origX + altura, origY + altura); ctx.stroke(); ctx.beginPath(); ctx.moveTo(origX, origY); ctx.lineTo(origX + altura, origY); ctx.stroke(); ctx.beginPath(); ctx.moveTo(origX, origY); ctx.lineTo(origX, origY + altura); ctx.stroke(); // quando NÃO há tampo duplo, completar a linha horizontal inferior da saia esquerda if (!tpoDuplo){ ctx.beginPath(); ctx.moveTo(xL, y2); ctx.lineTo(xR, y2); ctx.stroke(); } } else { ctx.strokeRect(xL, y1, xR - xL, hSaiaEsq); } } // --- Retângulo principal (barra superior), recuando nos cantos com meia-esquadria --- const topStart = (saiaEsq && meia) ? (origX + altura) : origX; const topEnd = (saiaDir && meia) ? (rightX - altura) : rightX; const baseStart = topStart; const baseEnd = topEnd; // Topo ctx.beginPath(); ctx.moveTo(topStart, origY); ctx.lineTo(topEnd, origY); ctx.stroke(); // Direita (somente se NÃO houver meia-esquadria direita) if (!(saiaDir && meia)){ ctx.beginPath(); ctx.moveTo(rightX, origY); ctx.lineTo(rightX, baseY); ctx.stroke(); } // Base ctx.beginPath(); ctx.moveTo(baseStart, baseY); ctx.lineTo(baseEnd, baseY); ctx.stroke(); // Esquerda (parte visível do corpo) ctx.beginPath(); const leftTopY = (saiaEsq && meia) ? (origY + altura) : origY; ctx.moveTo(origX, leftTopY); ctx.lineTo(origX, baseY); ctx.stroke(); // --- Saia DIREITA --- if (includeExtras && saiaDir){ const xL = rightX - altura; // interno (encosta no corpo) const xR = rightX; // externo const y1 = origY + altura; // começa abaixo da barra const y2 = y1 + hSaiaDir; if (meia){ // bordas da saia (só abaixo da barra) ctx.beginPath(); ctx.moveTo(xR, y1); ctx.lineTo(xR, y2); ctx.stroke(); // linha horizontal inferior removida intencionalmente ctx.beginPath(); ctx.moveTo(xL, y1); ctx.lineTo(xL, y2); ctx.stroke(); // diagonal e risquinhos de fechamento (canto direito) ctx.beginPath(); ctx.moveTo(rightX, origY); ctx.lineTo(rightX - altura, origY + altura); ctx.stroke(); ctx.beginPath(); ctx.moveTo(rightX - altura, origY); ctx.lineTo(rightX, origY); ctx.stroke(); ctx.beginPath(); ctx.moveTo(rightX, origY); ctx.lineTo(rightX, origY + altura); ctx.stroke(); // quando NÃO há tampo duplo, completar a linha horizontal inferior da saia direita if (!tpoDuplo){ ctx.beginPath(); ctx.moveTo(xL, y2); ctx.lineTo(xR, y2); ctx.stroke(); } } else { ctx.strokeRect(xL, y1, altura, hSaiaDir); } } // --- Frontões (opcionais) --- if (includeExtras && fronEsq){ ctx.strokeRect(origX, origY - Math.floor(largura/6), Math.floor(altura*0.9), Math.floor(largura/6)); } if (includeExtras && fronDir){ ctx.strokeRect(rightX - Math.floor(altura*0.9), origY - Math.floor(largura/6), Math.floor(altura*0.9), Math.floor(largura/6)); } // Para o "tampo" de baixo no modo tampo duplo, só desenhamos as diagonais para referência if (!includeExtras && saiaDir && tpoDuplo && meia){ ctx.beginPath(); ctx.moveTo(rightX, origY + altura); ctx.lineTo(rightX - altura, origY); ctx.stroke(); ctx.beginPath(); ctx.moveTo(rightX, origY + altura); ctx.lineTo(rightX - altura, origY + altura); ctx.stroke(); ctx.beginPath(); ctx.moveTo(rightX, origY); ctx.lineTo(rightX, origY + altura); ctx.stroke(); } if (!includeExtras && saiaEsq && tpoDuplo && meia){ ctx.beginPath(); ctx.moveTo(origX, origY + altura); ctx.lineTo(origX + altura, origY); ctx.stroke(); ctx.beginPath(); ctx.moveTo(origX, origY + altura); ctx.lineTo(origX + altura, origY + altura); ctx.stroke(); ctx.beginPath(); ctx.moveTo(origX, origY); ctx.lineTo(origX, origY + altura); ctx.stroke(); } } // calcular deslocamento para colocar a barra superior centrada verticalmente no canvas const canvasCenterY = canvas.height / 2; const offsetSuperior = canvasCenterY - (altura / 2) - (esp + extraTopo); // Tampo superior centralizado verticalmente no canvas desenharTampo(offsetSuperior, true); // Tampo inferior (opcional) if (tpoDuplo){ const alturaTampo = extraTopo + altura + extraBaixo + 2*esp; const offsetSegundo = alturaTampo + (Math.floor(largura/6) + altura) - extraBaixo - altura - extraTopo - 4; desenharTampo(offsetSuperior + offsetSegundo, false); } // --- posicionamento fixo do input lateral: Y = 200 relativo ao topo do canvas --- (function positionInputFixedY200(){ const wrapper = document.getElementById('inputSaiaDirWrapper'); if (!wrapper || !canvas) return; // controlar visibilidade conforme checkboxes const mostrar = (saiaEsq || saiaDir); // forçar display inline com prioridade wrapper.style.setProperty('display', mostrar ? 'flex' : 'none', 'important'); if (!mostrar) return; // garantir que wrapper esteja no document.body para posicionamento absoluto em coordenadas de página if (wrapper.parentNode !== document.body) document.body.appendChild(wrapper); // estilos mínimos seguros com priority important para evitar sobrescrita por outros scripts/CSS wrapper.style.setProperty('position', 'absolute', 'important'); wrapper.style.setProperty('transform', 'none', 'important'); wrapper.style.setProperty('pointer-events', 'auto', 'important'); wrapper.style.setProperty('z-index', '2147483647', 'important'); wrapper.style.setProperty('align-items', 'center', 'important'); wrapper.style.setProperty('gap', '6px', 'important'); const rect = canvas.getBoundingClientRect(); const canvasTopPage = rect.top + window.scrollY; const canvasRightPage = rect.right + window.scrollX; // aplicar left (à direita do canvas) e calcular top para Y=200 no canvas (centrando verticalmente o wrapper sobre esse Y) wrapper.style.setProperty('left', (canvasRightPage + 10) + 'px', 'important'); // colocar o centro do wrapper em Y = canvasTop + 200 // const desiredCenterY = canvasTopPage + 200; const desiredCenterY = canvasTopPage + (canvas.offsetHeight / 2); // medir e ajustar para centralizar verticalmente o wrapper sobre desiredCenterY // garantir render antes de medir const wrapperRect = wrapper.getBoundingClientRect(); const wrapperHeight = wrapperRect.height || 0; const topAdjusted = desiredCenterY - (wrapperHeight / 2); wrapper.style.setProperty('top', Math.max(0, topAdjusted) + 'px', 'important'); // reaplicar uma vez após pequeno atraso para neutralizar outros scripts que possam sobrescrever setTimeout(() => { wrapper.style.setProperty('left', (canvasRightPage + 10) + 'px', 'important'); // wrapper.style.setProperty('top', Math.max(0, desiredCenterY - (wrapperHeight * 5)) + 'px', 'important'); // wrapper.style.setProperty('top', Math.max(0, desiredCenterY - wrapperHeight) + 'px', 'important'); //wrapper.style.setProperty('top', Math.max(0, desiredCenterY - (wrapperHeight / 2)) + 'px', 'important'); // wrapper.style.setProperty('top', Math.max(0, desiredCenterY - 275) + 'px', 'important'); wrapper.style.setProperty('top', Math.max(0, topAdjusted) + 'px', 'important'); wrapper.style.setProperty('transform', 'none', 'important'); }, 120); // reforço final em caso de alteração posterior (uma única reaplicação) setTimeout(() => { const wr = document.getElementById('inputSaiaDirWrapper'); if (!wr) return; wr.style.setProperty('left', (canvasRightPage + 10) + 'px', 'important'); // recalcular altura real caso tenha mudado const newRect = wr.getBoundingClientRect(); const newH = newRect.height || wrapperHeight; wr.style.setProperty('top', Math.max(0, desiredCenterY - (newH / 2)) + 'px', 'important'); wr.style.setProperty('transform', 'none', 'important'); }, 400); })(); } (function () { function updateInputSaiaPosition() { const wrapper = document.getElementById('inputSaiaDirWrapper'); const fronWrapper = document.getElementById('inputFronEsqWrapper'); const canvas = document.getElementById('canvasPreview'); const canvasWrapper = document.getElementById('canvasWrapper'); if (!wrapper || !canvas || !canvasWrapper || !fronWrapper) return; const saiaEsq = document.getElementById('saiaEsq')?.checked; const saiaDir = document.getElementById('saiaDir')?.checked; const fronEsq = document.getElementById('fronEsq')?.checked; const fronDir = document.getElementById('fronDir')?.checked; // só mostra ou esconde inputSaiaDirWrapper const shouldShowSaia = saiaEsq || saiaDir; wrapper.style.display = shouldShowSaia ? 'flex' : 'none'; // só mostra ou esconde inputFronEsqWrapper const shouldShowFron = fronEsq || fronDir; fronWrapper.style.display = shouldShowFron ? 'flex' : 'none'; // garantir que estejam dentro do wrapper if (!canvasWrapper.contains(wrapper)) { canvasWrapper.appendChild(wrapper); } if (!canvasWrapper.contains(fronWrapper)) { canvasWrapper.appendChild(fronWrapper); } // fixa posição única vez - inputSaiaDirWrapper wrapper.style.position = 'absolute'; wrapper.style.top = '45px'; wrapper.style.left = (canvas.offsetWidth + 12) + 'px'; wrapper.style.transform = 'none'; wrapper.style.visibility = 'visible'; wrapper.style.opacity = '1'; // fixa posição única vez - inputFronEsqWrapper fronWrapper.style.position = 'absolute'; fronWrapper.style.top = '15px'; // fixo fronWrapper.style.left = (canvas.offsetLeft - fronWrapper.offsetWidth + 8 ) + 'px'; fronWrapper.style.width = '30%'; // metade da largura fronWrapper.style.transform = 'none'; fronWrapper.style.visibility = 'visible'; fronWrapper.style.opacity = '1'; } updateInputSaiaPosition(); window.addEventListener('resize', updateInputSaiaPosition); ['saiaDir', 'saiaEsq', 'fronEsq', 'fronDir', 'tpo_duplo'].forEach(id => { const el = document.getElementById(id); if (el) el.addEventListener('change', updateInputSaiaPosition); }); })(); // Redesenha ao mudar qualquer controle ['cor','largura','altura','saiaEsq','saiaDir','fronEsq','fronDir','meiaesquad','tpo_duplo'].forEach(id => { document.getElementById(id).addEventListener('input', gerarImagem); document.getElementById(id).addEventListener('change', gerarImagem); }); // Gera ao carregar window.addEventListener('load', gerarImagem); </script> <script> function hexToRgb(hex) { const bigint = parseInt(hex.replace('#', ''), 16); return [(bigint >> 16) & 255, (bigint >> 8) & 255, bigint & 255]; } function desenharImagemNoCanvasAA() { const largura = 250; const altura = 9; const corHexRaw = '#4169e1'; const [r, g, b] = hexToRgb(corHexRaw); const cor = `rgb(${r},${g},${b})`; const esp = 2; const meia = document.getElementById('meiaesquad')?.checked; const saiaSupAtiva = document.getElementById('saiaSup')?.checked; const saiaInfAtiva = document.getElementById('saiaInf')?.checked; const canvas = document.getElementById('canvasPreview-aa'); canvas.width = 390; canvas.height = largura - 100; const ctx = canvas.getContext('2d'); ctx.fillStyle = '#fff'; ctx.fillRect(0, 0, canvas.width, canvas.height); ctx.strokeStyle = cor; ctx.lineWidth = esp; ctx.lineJoin = 'miter'; ctx.lineCap = 'butt'; const x = (canvas.width - largura) / 2; const y = (canvas.height - altura) / 2; // === Barra horizontal principal === ctx.beginPath(); let inicioX = x; let fimX = x + largura; if (meia && (saiaSupAtiva || saiaInfAtiva)) { if (saiaSupAtiva) inicioX = x; if (meia && saiaInfAtiva) fimX = x + largura; } ctx.moveTo(inicioX, y); ctx.lineTo(fimX, y); ctx.stroke(); // Base horizontal com recuo à esquerda se meiaesquad e saiaSup ativos ctx.beginPath(); let baseInicioX = x; let baseFimX = x + largura; // sempre reta até a ponta direita if (meia && saiaSupAtiva) { baseInicioX = x + altura; // recuo só na esquerda } ctx.moveTo(baseInicioX, y + altura); ctx.lineTo(baseFimX, y + altura); ctx.stroke(); // 🔹 Fechamento ponta direita da barra horizontal com ângulo reto if (meia && saiaSupAtiva) { ctx.beginPath(); ctx.moveTo(x + largura, y); // topo da ponta direita ctx.lineTo(x + largura, y + altura); // vertical até a base ctx.stroke(); } // Laterais barra horizontal if (!(meia && (saiaSupAtiva || saiaInfAtiva))) { ctx.beginPath(); ctx.moveTo(x, y); ctx.lineTo(x, y + altura); ctx.stroke(); ctx.beginPath(); ctx.moveTo(x + largura, y); ctx.lineTo(x + largura, y + altura); ctx.stroke(); } // 🔹 Diagonais (corrigido: sem corte direito se saiaSup && meia) if (meia && (saiaSupAtiva || saiaInfAtiva)) { ctx.beginPath(); ctx.moveTo(x, y); ctx.lineTo(x + altura, y + altura); ctx.stroke(); if (!(saiaSupAtiva && meia)) { ctx.beginPath(); ctx.moveTo(x + largura, y); ctx.lineTo(x + largura - altura, y + altura); ctx.stroke(); } } // === Saia Superior (vertical esquerda) === if (saiaSupAtiva) { const hVertical = largura / 4; const xV = x; const yV = meia ? y : y + altura; if (meia) { ctx.beginPath(); ctx.moveTo(xV, yV); ctx.lineTo(xV, yV + hVertical); ctx.stroke(); const innerX = xV + altura; const innerEnd = yV + hVertical; const bottomBar = y + altura; if (innerEnd > bottomBar) { ctx.beginPath(); ctx.moveTo(innerX, bottomBar); ctx.lineTo(innerX, innerEnd); ctx.stroke(); } ctx.beginPath(); ctx.moveTo(xV, yV + hVertical); ctx.lineTo(xV + altura, yV + hVertical); ctx.stroke(); } else { ctx.strokeRect(xV, yV, altura, hVertical); } } // === Saia Inferior (vertical direita) === if (saiaInfAtiva) { const hVertical = largura / 4; const xV = x + largura - altura; let yV = meia ? y : y + altura; if (!meia) yV = y + altura; if (meia) { ctx.beginPath(); ctx.moveTo(xV, yV + altura); ctx.lineTo(xV, yV + hVertical); ctx.stroke(); ctx.beginPath(); ctx.moveTo(xV + altura, yV); ctx.lineTo(xV + altura, yV + hVertical); ctx.stroke(); ctx.beginPath(); ctx.moveTo(xV + altura, yV); ctx.lineTo(xV, yV + altura); ctx.stroke(); if (saiaSupAtiva) { ctx.beginPath(); ctx.moveTo(xV, yV + hVertical); ctx.lineTo(xV + altura, yV + hVertical); ctx.stroke(); } } else { ctx.strokeRect(xV, yV, altura, hVertical); } } } // Atualiza meiaesquad automaticamente function atualizarMeiaEsquad() { const saiaSup = document.getElementById('saiaSup').checked; const saiaInf = document.getElementById('saiaInf').checked; if (!saiaSup && !saiaInf) { document.getElementById('meiaesquad').checked = false; } } // Listeners window.addEventListener('load', desenharImagemNoCanvasAA); ['meiaesquad', 'saiaSup', 'saiaInf'].forEach(id => document.getElementById(id)?.addEventListener('change', desenharImagemNoCanvasAA) ); // Atualiza meiaesquad ['saiaSup', 'saiaInf'].forEach(id => document.getElementById(id)?.addEventListener('change', () => { atualizarMeiaEsquad(); desenharImagemNoCanvasAA(); }) ); </script> </body> </html>