Search in sources :

Example 6 with BitmapStaff

use of com.xenoage.zong.musiclayout.stampings.bitmap.BitmapStaff in project Zong by Xenoage.

the class BarlineRenderer method paintLine.

/**
 * Draws the given line with the given width in px.
 */
private static void paintLine(Canvas canvas, RendererArgs args, StaffStamping staff1, float staff1LinePosition, StaffStamping staff2, float staff2LinePosition, float xMm, float widthMm, Color color) {
    if (canvas.getFormat() == CanvasFormat.Raster) {
        float scaling = args.targetScaling;
        BitmapStaff screenStaff1 = staff1.getBitmapInfo().getBitmapStaff(scaling);
        BitmapStaff screenStaff2 = staff2.getBitmapInfo().getBitmapStaff(scaling);
        Point2f p1 = new Point2f(xMm, staff1.positionMm.y + screenStaff1.getYMm(staff1LinePosition));
        Point2f p2 = new Point2f(xMm, staff2.positionMm.y + screenStaff2.getYMm(staff2LinePosition));
        canvas.drawLine(p1, p2, color, widthMm);
    } else if (canvas.getFormat() == CanvasFormat.Vector) {
        Point2f p1 = new Point2f(xMm, staff1.positionMm.y + staff1.is * (staff1.linesCount - 1 - staff1LinePosition / 2));
        Point2f p2 = new Point2f(xMm, staff2.positionMm.y + staff2.is * (staff2.linesCount - 1 - staff2LinePosition / 2));
        canvas.drawLine(p1, p2, color, widthMm);
    }
}
Also used : Point2f(com.xenoage.utils.math.geom.Point2f) BitmapStaff(com.xenoage.zong.musiclayout.stampings.bitmap.BitmapStaff)

Example 7 with BitmapStaff

use of com.xenoage.zong.musiclayout.stampings.bitmap.BitmapStaff in project Zong by Xenoage.

the class LegerLineRenderer method draw.

/**
 * Draws the given {@link LegerLineStamping} on the given {@link Canvas},
 * using the given {@link RendererArgs}.
 */
@Override
public void draw(Stamping stamping, Canvas canvas, RendererArgs args) {
    LegerLineStamping legerLine = (LegerLineStamping) stamping;
    StaffStamping parentStaff = legerLine.parentStaff;
    float linePosition = legerLine.sp.lp;
    float scaling = args.targetScaling;
    float width = legerLine.widthIs * parentStaff.is;
    float p1xMm = legerLine.sp.xMm - width / 2;
    float p2xMm = p1xMm + width;
    float lineWidthMm = parentStaff.getLineWidthMm();
    Color color = Color.Companion.getBlack();
    float yMm = 0;
    if (canvas.getFormat() == CanvasFormat.Raster) {
        // render on screen or print
        BitmapLine screenLine = new BitmapLine(lineWidthMm, color, scaling);
        BitmapStaff screenStaff = parentStaff.getBitmapInfo().getBitmapStaff(scaling);
        yMm = parentStaff.positionMm.y + screenStaff.getYMm(linePosition);
        lineWidthMm = screenLine.widthMm;
    } else if (canvas.getFormat() == CanvasFormat.Vector) {
        // render with high quality
        yMm = parentStaff.computeYMm(linePosition);
    }
    canvas.drawLine(p(p1xMm, yMm), p(p2xMm, yMm), color, lineWidthMm);
}
Also used : StaffStamping(com.xenoage.zong.musiclayout.stampings.StaffStamping) Color(com.xenoage.utils.color.Color) BitmapLine(com.xenoage.zong.musiclayout.stampings.bitmap.BitmapLine) BitmapStaff(com.xenoage.zong.musiclayout.stampings.bitmap.BitmapStaff) LegerLineStamping(com.xenoage.zong.musiclayout.stampings.LegerLineStamping)

Example 8 with BitmapStaff

use of com.xenoage.zong.musiclayout.stampings.bitmap.BitmapStaff in project Zong by Xenoage.

the class StaffSymbolRenderer method drawWith.

/**
 * Paints the given symbol using the given information and rendering parameters.
 */
public static void drawWith(Symbol symbol, Color color, SP position, float scaling, StaffStamping parentStaff, boolean mirrorV, Canvas canvas, RendererArgs args) {
    float viewScaling = args.targetScaling;
    float symbolScaling = scaling * parentStaff.is;
    float yPosition;
    if (canvas.getFormat() == CanvasFormat.Raster) {
        BitmapStaff ss = parentStaff.getBitmapInfo().getBitmapStaff(viewScaling);
        yPosition = parentStaff.positionMm.y + ss.getYMm(position.lp);
        symbolScaling *= ss.heightScaling;
    /*
			//TEST
			int x = Units.mmToPx(positionX, viewScaling);
			int yOffset = ss.getYOffsetPx();
			int yTopLine = Units.mmToPx(
			  endStaff.getPosition().y + endStaff.getLineWidth() / 2,
			  viewScaling) + yOffset;
			for (int i = 0; i < 2; i++)
			  params.renderTarget.drawLine(
			  	new Point2i(x + i, yTopLine),
			  	new Point2i(x + i, yTopLine + ss.getHeightPx()), Color.red, 1); */
    } else {
        yPosition = parentStaff.computeYMm(position.lp);
    }
    Point2f correctedPosition = new Point2f(position.xMm, yPosition);
    SymbolsRenderer.draw(symbol, canvas, (color != null ? color : Color.Companion.getBlack()), correctedPosition, new Point2f(symbolScaling, (mirrorV ? -1 : 1) * symbolScaling));
}
Also used : Point2f(com.xenoage.utils.math.geom.Point2f) BitmapStaff(com.xenoage.zong.musiclayout.stampings.bitmap.BitmapStaff)

Example 9 with BitmapStaff

use of com.xenoage.zong.musiclayout.stampings.bitmap.BitmapStaff in project Zong by Xenoage.

the class SystemCursorRenderer method draw.

/**
 * Draws the given {@link SystemCursorStamping} on the given {@link Canvas},
 * using the given {@link RendererArgs}.
 */
@Override
public void draw(Stamping stamping, Canvas canvas, RendererArgs args) {
    SystemCursorStamping cursor = (SystemCursorStamping) stamping;
    float viewScaling = args.targetScaling;
    StaffStamping topStaff = cursor.topStaff;
    StaffStamping bottomStaff = cursor.bottomStaff;
    float x, y1, y2;
    x = topStaff.positionMm.x + cursor.xMm;
    if (canvas.getFormat() == CanvasFormat.Raster) {
        float staffY = topStaff.positionMm.y;
        BitmapStaff ss = topStaff.getBitmapInfo().getBitmapStaff(viewScaling);
        // top staff: top line
        y1 = staffY + ss.getYMm(topStaff.linesCount * 2);
        // bottom staff: bottom line
        staffY = bottomStaff.positionMm.y;
        ss = bottomStaff.getBitmapInfo().getBitmapStaff(viewScaling);
        y2 = staffY + ss.getYMm(-2);
    } else {
        y1 = topStaff.computeYMm(topStaff.linesCount * 2);
        y2 = bottomStaff.computeYMm(-2);
    }
    canvas.drawLine(new Point2f(x, y1), new Point2f(x, y2), Companion.color(50, 50, 230), getCursorWidth(viewScaling));
}
Also used : Point2f(com.xenoage.utils.math.geom.Point2f) SystemCursorStamping(com.xenoage.zong.musiclayout.stampings.SystemCursorStamping) StaffStamping(com.xenoage.zong.musiclayout.stampings.StaffStamping) BitmapStaff(com.xenoage.zong.musiclayout.stampings.bitmap.BitmapStaff)

Example 10 with BitmapStaff

use of com.xenoage.zong.musiclayout.stampings.bitmap.BitmapStaff in project Zong by Xenoage.

the class BitmapStaffTest method test12Pixel.

@Test
public void test12Pixel() {
    // 1mm -> 1px, 5 lines, interline: 3.4 mm. Displayed staff must be 12px high.
    float scaling = Units.pxToMm(1, 1);
    BitmapStaff ss = new BitmapStaff(5, 3.4f, 0.1f, scaling);
    assertEquals(Units.pxToMm(12, scaling), ss.heightMm, Delta.DELTA_FLOAT);
    assertEquals(Units.pxToMm(1, scaling), ss.yOffsetMm, Delta.DELTA_FLOAT);
    assertEquals(12 / (4 * 3.4f), ss.heightScaling, Delta.DELTA_FLOAT_ROUGH);
    assertEquals(Units.pxToMm(3, scaling), ss.interlineSpaceMm, Delta.DELTA_FLOAT);
}
Also used : BitmapStaff(com.xenoage.zong.musiclayout.stampings.bitmap.BitmapStaff) Test(org.junit.Test)

Aggregations

BitmapStaff (com.xenoage.zong.musiclayout.stampings.bitmap.BitmapStaff)18 Point2f (com.xenoage.utils.math.geom.Point2f)11 Color (com.xenoage.utils.color.Color)8 StaffStamping (com.xenoage.zong.musiclayout.stampings.StaffStamping)8 BitmapLine (com.xenoage.zong.musiclayout.stampings.bitmap.BitmapLine)6 Test (org.junit.Test)5 FormattedText (com.xenoage.zong.core.text.FormattedText)2 Rectangle2f (com.xenoage.utils.math.geom.Rectangle2f)1 BeamStamping (com.xenoage.zong.musiclayout.stampings.BeamStamping)1 LegerLineStamping (com.xenoage.zong.musiclayout.stampings.LegerLineStamping)1 SlurStamping (com.xenoage.zong.musiclayout.stampings.SlurStamping)1 StaffCursorStamping (com.xenoage.zong.musiclayout.stampings.StaffCursorStamping)1 StemStamping (com.xenoage.zong.musiclayout.stampings.StemStamping)1 SystemCursorStamping (com.xenoage.zong.musiclayout.stampings.SystemCursorStamping)1 TupletStamping (com.xenoage.zong.musiclayout.stampings.TupletStamping)1 VoltaStamping (com.xenoage.zong.musiclayout.stampings.VoltaStamping)1 WedgeStamping (com.xenoage.zong.musiclayout.stampings.WedgeStamping)1 SimpleSlurShape (com.xenoage.zong.renderer.slur.SimpleSlurShape)1