Skip to content

Commit

Permalink
feat(Multi-Measure Rest): Improve bounding box for staffentry in mult…
Browse files Browse the repository at this point in the history
…i-measure rest (MultiRestMeasure) (opensheetmusicdisplay#506). Helps click events.
  • Loading branch information
sschmidTU committed Apr 4, 2024
1 parent d62ae24 commit a9cad37
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/MusicalScore/Graphical/VexFlow/VexFlowMultiRestMeasure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {Tuplet} from "../../VoiceData/Tuplet";
import {GraphicalVoiceEntry} from "../GraphicalVoiceEntry";
import {Voice} from "../../VoiceData/Voice";
import {VexFlowMeasure} from "./VexFlowMeasure";
import { BoundingBox } from "../BoundingBox";

// type StemmableNote = VF.StemmableNote;

Expand Down Expand Up @@ -70,7 +71,22 @@ export class VexFlowMultiRestMeasure extends VexFlowMeasure {
}

public format(): void {
// like most of the following methods, not necessary / can be simplified for MultiRestMeasure.
// like most of the following methods, generally not necessary / can be simplified for MultiRestMeasure.
// but making a sensible bounding box for the StaffEntry / VoiceEntry / GraphicalNote helps click detection: (see #506)
for (const staffEntry of this.staffEntries) {
// place virtual position in middle
const measureWidthExInstructions: number = this.PositionAndShape.Size.width - this.beginInstructionsWidth;
staffEntry.PositionAndShape.RelativePosition.x = this.PositionAndShape.Size.width / 2 + this.beginInstructionsWidth / 3;
staffEntry.PositionAndShape.RelativePosition.y = 0; // alternative: this.PositionAndShape.Size.height / 2;
// but seems like most staffentries are anchored to top line
// BorderLeft etc will be set by child elements -> note (also for VoiceEntry)
const noteBbox: BoundingBox = staffEntry.graphicalVoiceEntries[0]?.notes[0]?.PositionAndShape;
noteBbox.BorderLeft = -measureWidthExInstructions / 3;
noteBbox.BorderRight = measureWidthExInstructions / 3;
noteBbox.BorderTop = 2;
noteBbox.BorderBottom = 4;
staffEntry.PositionAndShape.calculateBoundingBox();
}
}

/**
Expand Down

0 comments on commit a9cad37

Please sign in to comment.