ソースを参照

Added boundary calculation for bounding box

Benjamin Giesinger 7 年 前
コミット
cb9f16fb94

+ 12 - 0
external/vexflow/vexflow.d.ts

@@ -110,6 +110,8 @@ declare namespace Vex {
 
             public getLineForY(y: number): number;
 
+            public getYForLine(y: number): number;
+
             public getModifiers(pos: any, cat: any): Clef[]; // FIXME
             public setContext(ctx: RenderContext): Stave;
 
@@ -221,6 +223,16 @@ declare namespace Vex {
 
             public setContext(ctx: RenderContext): StaveConnector;
 
+            public top_stave: Stave;
+            
+            public bottom_stave: Stave;
+            
+            public thickness: number;
+
+            public width: number;
+
+            public x_shift: number;
+
             public draw(): void;
         }
     }

+ 16 - 2
src/MusicalScore/Graphical/VexFlow/VexFlowInstrumentBracket.ts

@@ -3,6 +3,7 @@ import {GraphicalObject} from "../GraphicalObject";
 import {VexFlowStaffLine} from "./VexFlowStaffLine";
 import { BoundingBox } from "../BoundingBox";
 import { VexFlowMeasure } from "./VexFlowMeasure";
+import { unitInPixels } from "./VexFlowMusicSheetDrawer";
 
 /**
  * Class that defines a instrument bracket at the beginning of a line.
@@ -13,11 +14,11 @@ export class VexFlowInstrumentBracket extends GraphicalObject {
 
     constructor(firstVexFlowStaffLine: VexFlowStaffLine, lastVexFlowStaffLine: VexFlowStaffLine) {
         super();
-        // FIXME: B.Giesinger: Fill in sizes after calculation
-        this.boundingBox = new BoundingBox(this);
+        this.PositionAndShape = new BoundingBox(this);
         const firstVexMeasure: VexFlowMeasure = firstVexFlowStaffLine.Measures[0] as VexFlowMeasure;
         const lastVexMeasure: VexFlowMeasure = lastVexFlowStaffLine.Measures[0] as VexFlowMeasure;
         this.addConnector(firstVexMeasure.getVFStave(), lastVexMeasure.getVFStave(), Vex.Flow.StaveConnector.type.BRACE);
+
     }
 
     /**
@@ -25,7 +26,20 @@ export class VexFlowInstrumentBracket extends GraphicalObject {
      * @param ctx Render Vexflow context
      */
     public draw(ctx: Vex.Flow.RenderContext): void {
+        // Draw vexflow brace. This sets the positions inside the connector.
         this.vexflowConnector.setContext(ctx).draw();
+        // Set bounding box
+        const con: Vex.Flow.StaveConnector = this.vexflowConnector;
+        // First line in first stave
+        let topY: number = con.top_stave.getYForLine(0);
+        // Last line in last stave
+        let botY: number = con.bottom_stave.getYForLine(con.bottom_stave.getNumLines() - 1) + con.thickness;
+        // Set bounding box position and size in OSMD units
+        this.PositionAndShape.AbsolutePosition.x = (con.top_stave.getX() - 2 + con.x_shift) / unitInPixels;
+        this.PositionAndShape.AbsolutePosition.y = topY / unitInPixels;
+        this.PositionAndShape.Size.height = (botY - topY) / unitInPixels;
+        this.PositionAndShape.Size.width = 12 / unitInPixels; // width is always 12 -> vexflow implementation
+        console.log(this.PositionAndShape.AbsolutePosition, this.PositionAndShape.Size);
     }
 
     /**

+ 0 - 1
src/MusicalScore/Graphical/VexFlow/VexFlowStaffLine.ts

@@ -5,6 +5,5 @@ import {Staff} from "../../VoiceData/Staff";
 export class VexFlowStaffLine extends StaffLine {
     constructor(parentSystem: MusicSystem, parentStaff: Staff) {
         super(parentSystem, parentStaff);
-
     }
 }