Browse Source

Replaced UnitInPixels numbers with constant.

Matthias 9 years ago
parent
commit
4bb5d00222

+ 13 - 12
src/MusicalScore/Graphical/VexFlow/VexFlowMeasure.ts

@@ -15,6 +15,7 @@ import {GraphicalStaffEntry} from "../GraphicalStaffEntry";
 import StaveConnector = Vex.Flow.StaveConnector;
 import StaveNote = Vex.Flow.StaveNote;
 import {Logging} from "../../../Common/Logging";
+import {UnitInPixels} from "./VexFlowMusicSheetDrawer";
 
 export class VexFlowMeasure extends StaffMeasure {
     constructor(staff: Staff, staffLine: StaffLine = undefined, sourceMeasure: SourceMeasure = undefined) {
@@ -51,8 +52,8 @@ export class VexFlowMeasure extends StaffMeasure {
     public resetLayout(): void {
         // Take into account some space for the begin and end lines of the stave
         // Will be changed when repetitions will be implemented
-        //this.beginInstructionsWidth = 20 / 10.0;
-        //this.endInstructionsWidth = 20 / 10.0;
+        //this.beginInstructionsWidth = 20 / UnitInPixels;
+        //this.endInstructionsWidth = 20 / UnitInPixels;
         this.stave = new Vex.Flow.Stave(0, 0, 0, {
             space_above_staff_ln: 0,
             space_below_staff_ln: 0,
@@ -78,9 +79,9 @@ export class VexFlowMeasure extends StaffMeasure {
         let vfline: any = VexFlowConverter.line(line);
         switch (vfline) {
             case Vex.Flow.StaveConnector.type.SINGLE:
-                return 1.0 / 10.0;
+                return 1.0 / UnitInPixels;
             case Vex.Flow.StaveConnector.type.DOUBLE:
-                return 3.0 / 10.0;
+                return 3.0 / UnitInPixels;
             default:
                 return 0;
         }
@@ -146,14 +147,14 @@ export class VexFlowMeasure extends StaffMeasure {
     public setWidth(width: number): void {
         super.setWidth(width);
         // Set the width of the Vex.Flow.Stave
-        this.stave.setWidth(width * 10.0);
+        this.stave.setWidth(width * UnitInPixels);
         // Force the width of the Begin Instructions
-        //this.stave.setNoteStartX(this.beginInstructionsWidth * 10.0);
+        //this.stave.setNoteStartX(this.beginInstructionsWidth * UnitInPixels);
         // If this is the first stave in the vertical measure, call the format
         // method to set the width of all the voices
         if (this.formatVoices) {
             // The width of the voices does not include the instructions (StaveModifiers)
-            this.formatVoices((width - this.beginInstructionsWidth - this.endInstructionsWidth) * 10.0);
+            this.formatVoices((width - this.beginInstructionsWidth - this.endInstructionsWidth) * UnitInPixels);
         }
     }
 
@@ -181,7 +182,7 @@ export class VexFlowMeasure extends StaffMeasure {
      */
     public draw(ctx: Vex.Flow.CanvasContext): void {
         // Force the width of the Begin Instructions
-        this.stave.setNoteStartX(this.stave.getX() + 10.0 * this.beginInstructionsWidth);
+        this.stave.setNoteStartX(this.stave.getX() + UnitInPixels * this.beginInstructionsWidth);
         // Draw stave lines
         this.stave.setContext(ctx).draw();
         // Draw all voices
@@ -300,7 +301,7 @@ export class VexFlowMeasure extends StaffMeasure {
     //    //let padding: number = modifier.getCategory() === "keysignatures" ? modifier.getPadding(2) : 0;
     //    let padding: number = modifier.getPadding(20);
     //    let width: number = modifier.getWidth();
-    //    this.beginInstructionsWidth += (padding + width) / 10.0;
+    //    this.beginInstructionsWidth += (padding + width) / UnitInPixels;
     //}
     //
     //private increaseEndInstructionWidth(): void {
@@ -308,13 +309,13 @@ export class VexFlowMeasure extends StaffMeasure {
     //    let modifier: StaveModifier = modifiers[modifiers.length - 1];
     //    let padding: number = 0;
     //    let width: number = modifier.getWidth();
-    //    this.endInstructionsWidth += (padding + width) / 10.0;
+    //    this.endInstructionsWidth += (padding + width) / UnitInPixels;
     //
     //}
 
     private updateInstructionWidth(): void {
         //this.stave.format();
-        this.beginInstructionsWidth = (this.stave.getNoteStartX() - this.stave.getX()) / 10.0;
-        this.endInstructionsWidth = (this.stave.getNoteEndX() - this.stave.getX()) / 10.0;
+        this.beginInstructionsWidth = (this.stave.getNoteStartX() - this.stave.getX()) / UnitInPixels;
+        this.endInstructionsWidth = (this.stave.getNoteEndX() - this.stave.getX()) / UnitInPixels;
     }
 }

+ 2 - 1
src/MusicalScore/Graphical/VexFlow/VexFlowMusicSheetCalculator.ts

@@ -27,6 +27,7 @@ import {VexFlowTextMeasurer} from "./VexFlowTextMeasurer";
 
 import Vex = require("vexflow");
 import {Logging} from "../../../Common/Logging";
+import {UnitInPixels} from "./VexFlowMusicSheetDrawer";
 
 export class VexFlowMusicSheetCalculator extends MusicSheetCalculator {
     constructor() {
@@ -86,7 +87,7 @@ export class VexFlowMusicSheetCalculator extends MusicSheetCalculator {
         let firstMeasure: VexFlowMeasure = measures[0] as VexFlowMeasure;
         // FIXME: The following ``+ 5.0'' is temporary: it was added as a workaround for
         // FIXME: a more relaxed formatting of voices
-        let width: number = formatter.preCalculateMinTotalWidth(allVoices) / 10.0 + 5.0;
+        let width: number = formatter.preCalculateMinTotalWidth(allVoices) / UnitInPixels + 5.0;
         for (let measure of measures) {
             measure.minimumStaffEntriesWidth = width;
             (measure as VexFlowMeasure).formatVoices = undefined;

+ 8 - 6
src/MusicalScore/Graphical/VexFlow/VexFlowMusicSheetDrawer.ts

@@ -7,6 +7,8 @@ import {GraphicalLabel} from "../GraphicalLabel";
 import {VexFlowConverter} from "./VexFlowConverter";
 import {VexFlowTextMeasurer} from "./VexFlowTextMeasurer";
 
+export const UnitInPixels = 10;
+
 export class VexFlowMusicSheetDrawer extends MusicSheetDrawer {
     private renderer: Vex.Flow.Renderer;
     private vfctx: Vex.Flow.CanvasContext;
@@ -53,13 +55,13 @@ export class VexFlowMusicSheetDrawer extends MusicSheetDrawer {
      * @returns {number} the distance in pixels
      */
     public calculatePixelDistance(unitDistance: number): number {
-        return unitDistance * 10.0;
+        return unitDistance * UnitInPixels;
     }
 
     protected drawMeasure(measure: VexFlowMeasure): void {
         measure.setAbsoluteCoordinates(
-            measure.PositionAndShape.AbsolutePosition.x * 10.0,
-            measure.PositionAndShape.AbsolutePosition.y * 10.0
+            measure.PositionAndShape.AbsolutePosition.x * UnitInPixels,
+            measure.PositionAndShape.AbsolutePosition.y * UnitInPixels
         );
         return measure.draw(this.vfctx);
     }
@@ -92,7 +94,7 @@ export class VexFlowMusicSheetDrawer extends MusicSheetDrawer {
         let ctx: CanvasRenderingContext2D = (this.vfctx as any).vexFlowCanvasContext;
         let old: string = ctx.font;
         ctx.font = VexFlowConverter.font(
-            graphicalLabel.Label.fontHeight * 10.0,
+            graphicalLabel.Label.fontHeight * UnitInPixels,
             graphicalLabel.Label.fontStyle,
             graphicalLabel.Label.font
         );
@@ -120,7 +122,7 @@ export class VexFlowMusicSheetDrawer extends MusicSheetDrawer {
      * @returns {PointF2D}
      */
     protected applyScreenTransformation(point: PointF2D): PointF2D {
-        return new PointF2D(point.x * 10.0, point.y * 10.0);
+        return new PointF2D(point.x * UnitInPixels, point.y * UnitInPixels);
     }
 
     /**
@@ -129,6 +131,6 @@ export class VexFlowMusicSheetDrawer extends MusicSheetDrawer {
      * @returns {RectangleF2D}
      */
     protected applyScreenTransformationForRect(rectangle: RectangleF2D): RectangleF2D {
-        return new RectangleF2D(rectangle.x * 10.0, rectangle.y * 10.0, rectangle.width * 10.0, rectangle.height * 10.0);
+        return new RectangleF2D(rectangle.x * UnitInPixels, rectangle.y * UnitInPixels, rectangle.width * UnitInPixels, rectangle.height * UnitInPixels);
     }
 }

+ 2 - 1
src/MusicalScore/Graphical/VexFlow/VexFlowStaffEntry.ts

@@ -2,6 +2,7 @@ import {GraphicalStaffEntry} from "../GraphicalStaffEntry";
 import {VexFlowMeasure} from "./VexFlowMeasure";
 import {SourceStaffEntry} from "../../VoiceData/SourceStaffEntry";
 import {GraphicalNote} from "../GraphicalNote";
+import {UnitInPixels} from "./VexFlowMusicSheetDrawer";
 
 export class VexFlowStaffEntry extends GraphicalStaffEntry {
     constructor(measure: VexFlowMeasure, sourceStaffEntry: SourceStaffEntry, staffEntryParent: VexFlowStaffEntry) {
@@ -27,6 +28,6 @@ export class VexFlowStaffEntry extends GraphicalStaffEntry {
                 n += 1;
             }
         }
-        return x / n / 10.0;
+        return x / n / UnitInPixels;
     }
 }