| 633 | } |
| 634 | |
| 635 | public static drawBendSlur( |
| 636 | canvas: ICanvas, |
| 637 | x1: number, |
| 638 | y1: number, |
| 639 | x2: number, |
| 640 | y2: number, |
| 641 | down: boolean, |
| 642 | bendSlurHeight: number, |
| 643 | slurText?: string |
| 644 | ): void { |
| 645 | let normalVectorX: number = y2 - y1; |
| 646 | let normalVectorY: number = x2 - x1; |
| 647 | const length: number = Math.sqrt(normalVectorX * normalVectorX + normalVectorY * normalVectorY); |
| 648 | if (down) { |
| 649 | normalVectorX *= -1; |
| 650 | } else { |
| 651 | normalVectorY *= -1; |
| 652 | } |
| 653 | // make to unit vector |
| 654 | normalVectorX /= length; |
| 655 | normalVectorY /= length; |
| 656 | // center of connection |
| 657 | const centerX: number = (x2 + x1) / 2; |
| 658 | const centerY: number = (y2 + y1) / 2; |
| 659 | let offset: number = bendSlurHeight; |
| 660 | if (x2 - x1 < 20) { |
| 661 | offset /= 2; |
| 662 | } |
| 663 | const cp1X: number = centerX + offset * normalVectorX; |
| 664 | const cp1Y: number = centerY + offset * normalVectorY; |
| 665 | canvas.beginPath(); |
| 666 | canvas.moveTo(x1, y1); |
| 667 | canvas.lineTo(cp1X, cp1Y); |
| 668 | canvas.lineTo(x2, y2); |
| 669 | canvas.stroke(); |
| 670 | if (slurText) { |
| 671 | const w: number = canvas.measureText(slurText).width; |
| 672 | const textOffset: number = down ? 0 : -canvas.font.size; |
| 673 | canvas.fillText(slurText, cp1X - w / 2, cp1Y + textOffset); |
| 674 | } |
| 675 | } |
| 676 | } |
| 677 | |
| 678 | /** |