quando eu clicar em aplicar texto, o texto deve ser colocado diretamnete dentro do balão. e faça mais estilos de balões, se possivel use alguma biblioteca para isso para faciloitar
Browse files- index.html +134 -15
index.html
CHANGED
|
@@ -89,7 +89,7 @@
|
|
| 89 |
<!-- Adicionar Balão -->
|
| 90 |
<div class="mb-6">
|
| 91 |
<h3 class="font-semibold mb-2 text-gray-700">Adicionar Balão</h3>
|
| 92 |
-
|
| 93 |
<button id="addSpeech" class="bg-blue-500 hover:bg-blue-600 text-white p-2 rounded flex flex-col items-center">
|
| 94 |
<i data-feather="message-circle" class="mb-1"></i>
|
| 95 |
<span class="text-xs">Fala</span>
|
|
@@ -110,8 +110,24 @@
|
|
| 110 |
<i data-feather="square" class="mb-1"></i>
|
| 111 |
<span class="text-xs">Narração</span>
|
| 112 |
</button>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
</div>
|
| 114 |
-
|
| 115 |
|
| 116 |
<!-- Editar Texto -->
|
| 117 |
<div class="mb-6">
|
|
@@ -407,9 +423,82 @@
|
|
| 407 |
strokeWidth: 2
|
| 408 |
});
|
| 409 |
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 410 |
}
|
| 411 |
-
|
| 412 |
-
group.add(balloonShape);
|
| 413 |
group.add(text);
|
| 414 |
|
| 415 |
// Adicionar transformador para redimensionamento
|
|
@@ -514,23 +603,55 @@ saveState();
|
|
| 514 |
document.getElementById('addWhisper').addEventListener('click', () => {
|
| 515 |
createBalloon('whisper');
|
| 516 |
});
|
| 517 |
-
|
| 518 |
document.getElementById('addRect').addEventListener('click', () => {
|
| 519 |
createBalloon('rect');
|
| 520 |
});
|
| 521 |
|
| 522 |
-
document.getElementById('
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 523 |
if (selectedBalloon) {
|
| 524 |
selectedBalloon.text(document.getElementById('textInput').value);
|
| 525 |
-
const balloonShape = selectedBalloon.parent.
|
| 526 |
-
|
| 527 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 528 |
layer.batchDraw();
|
| 529 |
saveState();
|
| 530 |
}
|
| 531 |
});
|
| 532 |
-
|
| 533 |
-
document.getElementById('fontSelect').addEventListener('change', (e) => {
|
| 534 |
if (selectedBalloon) {
|
| 535 |
selectedBalloon.fontFamily(e.target.value);
|
| 536 |
layer.batchDraw();
|
|
@@ -557,17 +678,15 @@ saveState();
|
|
| 557 |
saveState();
|
| 558 |
}
|
| 559 |
});
|
| 560 |
-
|
| 561 |
document.getElementById('balloonColor').addEventListener('input', (e) => {
|
| 562 |
if (selectedBalloon) {
|
| 563 |
-
const balloonShape = selectedBalloon.parent.
|
| 564 |
balloonShape.fill(e.target.value);
|
| 565 |
layer.batchDraw();
|
| 566 |
saveState();
|
| 567 |
}
|
| 568 |
});
|
| 569 |
-
|
| 570 |
-
document.getElementById('alignLeft').addEventListener('click', () => {
|
| 571 |
if (selectedBalloon) {
|
| 572 |
selectedBalloon.align('left');
|
| 573 |
layer.batchDraw();
|
|
|
|
| 89 |
<!-- Adicionar Balão -->
|
| 90 |
<div class="mb-6">
|
| 91 |
<h3 class="font-semibold mb-2 text-gray-700">Adicionar Balão</h3>
|
| 92 |
+
<div class="grid grid-cols-3 gap-2">
|
| 93 |
<button id="addSpeech" class="bg-blue-500 hover:bg-blue-600 text-white p-2 rounded flex flex-col items-center">
|
| 94 |
<i data-feather="message-circle" class="mb-1"></i>
|
| 95 |
<span class="text-xs">Fala</span>
|
|
|
|
| 110 |
<i data-feather="square" class="mb-1"></i>
|
| 111 |
<span class="text-xs">Narração</span>
|
| 112 |
</button>
|
| 113 |
+
<button id="addCloud" class="bg-yellow-500 hover:bg-yellow-600 text-white p-2 rounded flex flex-col items-center">
|
| 114 |
+
<i data-feather="cloud" class="mb-1"></i>
|
| 115 |
+
<span class="text-xs">Nuvem</span>
|
| 116 |
+
</button>
|
| 117 |
+
<button id="addStar" class="bg-pink-500 hover:bg-pink-600 text-white p-2 rounded flex flex-col items-center">
|
| 118 |
+
<i data-feather="star" class="mb-1"></i>
|
| 119 |
+
<span class="text-xs">Estrela</span>
|
| 120 |
+
</button>
|
| 121 |
+
<button id="addHeart" class="bg-red-400 hover:bg-red-500 text-white p-2 rounded flex flex-col items-center">
|
| 122 |
+
<i data-feather="heart" class="mb-1"></i>
|
| 123 |
+
<span class="text-xs">Coração</span>
|
| 124 |
+
</button>
|
| 125 |
+
<button id="addExplosion" class="bg-orange-500 hover:bg-orange-600 text-white p-2 rounded flex flex-col items-center">
|
| 126 |
+
<i data-feather="zap" class="mb-1"></i>
|
| 127 |
+
<span class="text-xs">Explosão</span>
|
| 128 |
+
</button>
|
| 129 |
</div>
|
| 130 |
+
</div>
|
| 131 |
|
| 132 |
<!-- Editar Texto -->
|
| 133 |
<div class="mb-6">
|
|
|
|
| 423 |
strokeWidth: 2
|
| 424 |
});
|
| 425 |
break;
|
| 426 |
+
case 'cloud':
|
| 427 |
+
balloonShape = new Konva.Rect({
|
| 428 |
+
width: 220,
|
| 429 |
+
height: text.height() + 20,
|
| 430 |
+
fill: '#ffffff',
|
| 431 |
+
stroke: '#000000',
|
| 432 |
+
strokeWidth: 2,
|
| 433 |
+
cornerRadius: [30, 30, 30, 30, 30, 30, 30, 30]
|
| 434 |
+
});
|
| 435 |
+
break;
|
| 436 |
+
case 'star':
|
| 437 |
+
balloonShape = new Konva.Star({
|
| 438 |
+
numPoints: 5,
|
| 439 |
+
innerRadius: 30,
|
| 440 |
+
outerRadius: 60,
|
| 441 |
+
fill: '#ffffff',
|
| 442 |
+
stroke: '#000000',
|
| 443 |
+
strokeWidth: 2
|
| 444 |
+
});
|
| 445 |
+
break;
|
| 446 |
+
case 'heart':
|
| 447 |
+
// Criar coração usando paths
|
| 448 |
+
balloonShape = new Konva.Shape({
|
| 449 |
+
sceneFunc: function(context, shape) {
|
| 450 |
+
const width = 80;
|
| 451 |
+
const height = 70;
|
| 452 |
+
context.beginPath();
|
| 453 |
+
context.moveTo(40, 15);
|
| 454 |
+
context.bezierCurveTo(40, 10, 20, 0, 10, 15);
|
| 455 |
+
context.bezierCurveTo(0, 30, 20, 50, 40, 65);
|
| 456 |
+
context.bezierCurveTo(60, 50, 80, 30, 70, 15);
|
| 457 |
+
context.bezierCurveTo(60, 0, 40, 10, 40, 15);
|
| 458 |
+
context.closePath();
|
| 459 |
+
context.fillStrokeShape(shape);
|
| 460 |
+
},
|
| 461 |
+
fill: '#ffffff',
|
| 462 |
+
stroke: '#000000',
|
| 463 |
+
strokeWidth: 2,
|
| 464 |
+
width: 80,
|
| 465 |
+
height: 70
|
| 466 |
+
});
|
| 467 |
+
break;
|
| 468 |
+
case 'explosion':
|
| 469 |
+
balloonShape = new Konva.Shape({
|
| 470 |
+
sceneFunc: function(context, shape) {
|
| 471 |
+
const spikes = 8;
|
| 472 |
+
const outerRadius = 40;
|
| 473 |
+
const innerRadius = 20;
|
| 474 |
+
|
| 475 |
+
context.beginPath();
|
| 476 |
+
for (let i = 0; i < spikes; i++) {
|
| 477 |
+
const angle = (i * 2 * Math.PI) / spikes;
|
| 478 |
+
const x1 = outerRadius * Math.cos(angle);
|
| 479 |
+
const y1 = outerRadius * Math.sin(angle);
|
| 480 |
+
const x2 = innerRadius * Math.cos(angle + Math.PI / spikes);
|
| 481 |
+
const y2 = innerRadius * Math.sin(angle + Math.PI / spikes);
|
| 482 |
+
|
| 483 |
+
if (i === 0) {
|
| 484 |
+
context.moveTo(x1, y1);
|
| 485 |
+
} else {
|
| 486 |
+
context.lineTo(x1, y1);
|
| 487 |
+
}
|
| 488 |
+
context.lineTo(x2, y2);
|
| 489 |
+
}
|
| 490 |
+
context.closePath();
|
| 491 |
+
context.fillStrokeShape(shape);
|
| 492 |
+
},
|
| 493 |
+
fill: '#ffffff',
|
| 494 |
+
stroke: '#000000',
|
| 495 |
+
strokeWidth: 2,
|
| 496 |
+
width: 80,
|
| 497 |
+
height: 80
|
| 498 |
+
});
|
| 499 |
+
break;
|
| 500 |
}
|
| 501 |
+
group.add(balloonShape);
|
|
|
|
| 502 |
group.add(text);
|
| 503 |
|
| 504 |
// Adicionar transformador para redimensionamento
|
|
|
|
| 603 |
document.getElementById('addWhisper').addEventListener('click', () => {
|
| 604 |
createBalloon('whisper');
|
| 605 |
});
|
|
|
|
| 606 |
document.getElementById('addRect').addEventListener('click', () => {
|
| 607 |
createBalloon('rect');
|
| 608 |
});
|
| 609 |
|
| 610 |
+
document.getElementById('addCloud').addEventListener('click', () => {
|
| 611 |
+
createBalloon('cloud');
|
| 612 |
+
});
|
| 613 |
+
|
| 614 |
+
document.getElementById('addStar').addEventListener('click', () => {
|
| 615 |
+
createBalloon('star');
|
| 616 |
+
});
|
| 617 |
+
|
| 618 |
+
document.getElementById('addHeart').addEventListener('click', () => {
|
| 619 |
+
createBalloon('heart');
|
| 620 |
+
});
|
| 621 |
+
|
| 622 |
+
document.getElementById('addExplosion').addEventListener('click', () => {
|
| 623 |
+
createBalloon('explosion');
|
| 624 |
+
});
|
| 625 |
+
document.getElementById('applyText').addEventListener('click', () => {
|
| 626 |
if (selectedBalloon) {
|
| 627 |
selectedBalloon.text(document.getElementById('textInput').value);
|
| 628 |
+
const balloonShape = selectedBalloon.parent.children[0]; // Primeiro elemento é o balão
|
| 629 |
+
|
| 630 |
+
// Ajustar tamanho do balão baseado no tipo
|
| 631 |
+
if (balloonShape instanceof Konva.Rect) {
|
| 632 |
+
balloonShape.width(selectedBalloon.width() + 20);
|
| 633 |
+
balloonShape.height(selectedBalloon.height() + 20);
|
| 634 |
+
} else if (balloonShape instanceof Konva.Star) {
|
| 635 |
+
// Para estrela, ajustar tamanho baseado no texto
|
| 636 |
+
const textHeight = selectedBalloon.height();
|
| 637 |
+
const newSize = Math.max(textHeight + 40, 60);
|
| 638 |
+
balloonShape.innerRadius(newSize * 0.5);
|
| 639 |
+
balloonShape.outerRadius(newSize);
|
| 640 |
+
} else if (balloonShape instanceof Konva.Shape) {
|
| 641 |
+
// Para formas customizadas, ajustar escala baseado no texto
|
| 642 |
+
const textWidth = selectedBalloon.width();
|
| 643 |
+
const textHeight = selectedBalloon.height();
|
| 644 |
+
const scaleX = Math.max((textWidth + 20) / balloonShape.width(), 1);
|
| 645 |
+
const scaleY = Math.max((textHeight + 20) / balloonShape.height(), 1);
|
| 646 |
+
balloonShape.scaleX(scaleX);
|
| 647 |
+
balloonShape.scaleY(scaleY);
|
| 648 |
+
}
|
| 649 |
+
|
| 650 |
layer.batchDraw();
|
| 651 |
saveState();
|
| 652 |
}
|
| 653 |
});
|
| 654 |
+
document.getElementById('fontSelect').addEventListener('change', (e) => {
|
|
|
|
| 655 |
if (selectedBalloon) {
|
| 656 |
selectedBalloon.fontFamily(e.target.value);
|
| 657 |
layer.batchDraw();
|
|
|
|
| 678 |
saveState();
|
| 679 |
}
|
| 680 |
});
|
|
|
|
| 681 |
document.getElementById('balloonColor').addEventListener('input', (e) => {
|
| 682 |
if (selectedBalloon) {
|
| 683 |
+
const balloonShape = selectedBalloon.parent.children[0]; // Primeiro elemento é o balão
|
| 684 |
balloonShape.fill(e.target.value);
|
| 685 |
layer.batchDraw();
|
| 686 |
saveState();
|
| 687 |
}
|
| 688 |
});
|
| 689 |
+
document.getElementById('alignLeft').addEventListener('click', () => {
|
|
|
|
| 690 |
if (selectedBalloon) {
|
| 691 |
selectedBalloon.align('left');
|
| 692 |
layer.batchDraw();
|