Search in sources :

Example 16 with BitmapStaff

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

the class BeamRenderer method draw.

/**
 * Draws the given {@link BeamStamping} on the given {@link Canvas},
 * using the given {@link RendererArgs}.
 */
@Override
public void draw(Stamping stamping, Canvas canvas, RendererArgs args) {
    BeamStamping beam = (BeamStamping) stamping;
    StaffStamping staff = beam.staff;
    float scaling = args.targetScaling;
    // TODO: stem should be thinner than lineWidth?
    float stemWidthMm = staff.getLineWidthMm();
    float x1Mm = staff.positionMm.x + beam.sp1.xMm - stemWidthMm / 2f;
    float x2Mm = staff.positionMm.x + beam.sp2.xMm + stemWidthMm / 2f;
    Color color = Color.Companion.getBlack();
    float leftYStart, rightYStart, beamHeightMm;
    if (canvas.getFormat() == CanvasFormat.Raster) {
        // render on screen
        float staffYPos = staff.positionMm.y;
        BitmapStaff screenStaff = staff.getBitmapInfo().getBitmapStaff(scaling);
        leftYStart = staffYPos + screenStaff.getYMm(beam.sp1.lp);
        rightYStart = staffYPos + screenStaff.getYMm(beam.sp2.lp);
        beamHeightMm = BeamNotation.lineHeightIs * screenStaff.interlineSpaceMm;
    } else {
        leftYStart = staff.computeYMm(beam.sp1.lp);
        rightYStart = staff.computeYMm(beam.sp2.lp);
        beamHeightMm = BeamNotation.lineHeightIs * staff.is;
    }
    // TODO: avoid edges at the stem end points
    // beam sits on or hangs from the vertical position, dependent on stem direction
    float vAdd = (beam.stemDir.getSign() - 1) / 2f * beamHeightMm;
    Point2f sw = new Point2f(x1Mm, leftYStart + vAdd);
    Point2f nw = new Point2f(x1Mm, sw.y + beamHeightMm);
    Point2f se = new Point2f(x2Mm, rightYStart + vAdd);
    Point2f ne = new Point2f(x2Mm, se.y + beamHeightMm);
    List<PathElement> elements = alist(4);
    elements.add(new MoveTo(sw));
    elements.add(new LineTo(nw));
    elements.add(new LineTo(ne));
    elements.add(new LineTo(se));
    elements.add(new ClosePath());
    Path path = new Path(elements);
    canvas.fillPath(path, color);
}
Also used : BeamStamping(com.xenoage.zong.musiclayout.stampings.BeamStamping) Point2f(com.xenoage.utils.math.geom.Point2f) StaffStamping(com.xenoage.zong.musiclayout.stampings.StaffStamping) Color(com.xenoage.utils.color.Color) BitmapStaff(com.xenoage.zong.musiclayout.stampings.bitmap.BitmapStaff)

Example 17 with BitmapStaff

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

the class BracketRenderer method getStaffTopY.

/**
 * Gets the vertical position in px of the topmost line
 * of the given staff.
 * TIDY: move into other class?
 */
private static float getStaffTopY(StaffStamping staff, Canvas canvas, RendererArgs args) {
    float scaling = args.targetScaling;
    float ret = staff.positionMm.y;
    if (canvas.getFormat() == CanvasFormat.Raster) {
        // render on screen
        BitmapStaff screenStaff = staff.getBitmapInfo().getBitmapStaff(scaling);
        ret += screenStaff.yOffsetMm;
    }
    return ret;
}
Also used : BitmapStaff(com.xenoage.zong.musiclayout.stampings.bitmap.BitmapStaff)

Example 18 with BitmapStaff

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

the class WedgeRenderer method draw.

/**
 * Draws the given {@link WedgeStamping} on the given {@link Canvas},
 * using the given {@link RendererArgs}.
 */
@Override
public void draw(Stamping stamping, Canvas canvas, RendererArgs args) {
    WedgeStamping wedge = (WedgeStamping) stamping;
    StaffStamping parentStaff = wedge.parentStaff;
    float scaling = args.scaling;
    // horizontal position
    float x1Mm = wedge.leftXMm + parentStaff.positionMm.x;
    float x2Mm = wedge.rightXMm + parentStaff.positionMm.x;
    // compute vertical distances at the start and end point
    float d1Mm = wedge.leftDistanceIs * parentStaff.is;
    float d2Mm = wedge.rightDistanceIs * parentStaff.is;
    // width and color of the line
    Color color = Color.Companion.getBlack();
    // like staff line
    float width = parentStaff.getLineWidthMm();
    float paintWidth;
    // compute the horizontal line and color
    float yMm;
    Color paintColor;
    if (canvas.getFormat() == CanvasFormat.Raster) {
        BitmapStaff ss = parentStaff.getBitmapInfo().getBitmapStaff(scaling);
        yMm = parentStaff.positionMm.y + ss.getYMm(wedge.lp);
        BitmapLine screenLine = parentStaff.getBitmapInfo().getBitmapLine(scaling, width, color);
        paintColor = screenLine.color;
        paintWidth = screenLine.widthMm;
    } else {
        yMm = parentStaff.computeYMm(wedge.lp);
        paintColor = color;
        paintWidth = width;
    }
    // draw lines
    canvas.drawLine(new Point2f(x1Mm, yMm - d1Mm / 2), new Point2f(x2Mm, yMm - d2Mm / 2), paintColor, paintWidth);
    canvas.drawLine(new Point2f(x1Mm, yMm + d1Mm / 2), new Point2f(x2Mm, yMm + d2Mm / 2), paintColor, paintWidth);
}
Also used : Point2f(com.xenoage.utils.math.geom.Point2f) 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) WedgeStamping(com.xenoage.zong.musiclayout.stampings.WedgeStamping)

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