Search in sources :

Example 1 with BitmapLine

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

the class TupletRenderer method draw.

/**
 * Draws the given {@link TupletStamping} on the given {@link Canvas},
 * using the given {@link RendererArgs}.
 */
@Override
public void draw(Stamping stamping, Canvas canvas, RendererArgs args) {
    TupletStamping tuplet = (TupletStamping) stamping;
    StaffStamping parentStaff = tuplet.parentStaff;
    float scaling = args.targetScaling;
    // horizontal position
    float x1Mm = tuplet.leftSP.xMm;
    float x2Mm = tuplet.rightSP.xMm;
    // height of hook is 1 IS
    float hookHeightPx = Units.mmToPx(parentStaff.is, scaling);
    // width and color of the line
    Color color = Color.Companion.getBlack();
    // a little bit thicker than staff line
    float width = parentStaff.getLineWidthMm() * 1.5f;
    float paintWidth;
    // compute the horizontal line and color
    float y1Mm, y2Mm;
    Color paintColor;
    if (canvas.getFormat() == CanvasFormat.Raster) {
        BitmapStaff ss = parentStaff.getBitmapInfo().getBitmapStaff(scaling);
        y1Mm = parentStaff.positionMm.y + ss.getYMm(tuplet.leftSP.lp);
        y2Mm = parentStaff.positionMm.y + ss.getYMm(tuplet.rightSP.lp);
        BitmapLine screenLine = parentStaff.getBitmapInfo().getBitmapLine(scaling, width, color);
        paintColor = screenLine.color;
        paintWidth = screenLine.widthMm;
    } else {
        y1Mm = parentStaff.computeYMm(tuplet.leftSP.lp);
        y2Mm = parentStaff.computeYMm(tuplet.rightSP.lp);
        paintColor = color;
        paintWidth = width;
    }
    // compute gap for text
    FormattedText text = tuplet.text;
    float gapMm = 0;
    float textMm = 0;
    if (text != null && text.getParagraphs().size() > 0) {
        textMm = text.getFirstParagraph().getMetrics().getWidth();
        gapMm = textMm * 2;
    }
    // draw line and hooks
    if (gapMm > 0) {
        // two lines, when there is text in between
        float xGapLMm = (x2Mm + x1Mm) / 2 - gapMm / 2;
        float xGapRMm = xGapLMm + gapMm;
        float gapVerticalMm = gapMm / (x2Mm - x1Mm) * (y2Mm - y1Mm);
        float yGapLMm = (y2Mm + y1Mm) / 2 - gapVerticalMm / 2;
        float yGapRMm = yGapLMm + gapVerticalMm;
        canvas.drawLine(new Point2f(x1Mm, y1Mm), new Point2f(xGapLMm, yGapLMm), paintColor, paintWidth);
        canvas.drawLine(new Point2f(xGapRMm, yGapRMm), new Point2f(x2Mm, y2Mm), paintColor, paintWidth);
    } else {
        // no gap
        canvas.drawLine(new Point2f(x1Mm, y1Mm), new Point2f(x2Mm, y2Mm), paintColor, paintWidth);
    }
    // hooks
    canvas.drawLine(new Point2f(x1Mm, y1Mm), new Point2f(x1Mm, y1Mm + hookHeightPx * (tuplet.leftSP.lp < 0 ? -1 : 1)), paintColor, paintWidth);
    canvas.drawLine(new Point2f(x2Mm, y2Mm), new Point2f(x2Mm, y2Mm + hookHeightPx * (tuplet.rightSP.lp < 0 ? -1 : 1)), paintColor, paintWidth);
    // draw text
    if (text != null && text.getParagraphs().size() > 0) {
        float textAscent = text.getFirstParagraph().getMetrics().getAscent();
        float textX = (x1Mm + x2Mm) / 2 - textMm / 2;
        float textY = (y1Mm + y2Mm) / 2 + textAscent / 2;
        canvas.drawText(tuplet.text, null, new Point2f(textX, textY), true, 0);
    }
}
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) FormattedText(com.xenoage.zong.core.text.FormattedText) TupletStamping(com.xenoage.zong.musiclayout.stampings.TupletStamping)

Example 2 with BitmapLine

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

the class VoltaRenderer method draw.

/**
 * Draws the given {@link VoltaStamping} on the given {@link Canvas},
 * using the given {@link RendererArgs}.
 */
@Override
public void draw(Stamping stamping, Canvas canvas, RendererArgs args) {
    VoltaStamping volta = (VoltaStamping) stamping;
    StaffStamping parentStaff = volta.parentStaff;
    float scaling = args.scaling;
    // horizontal position
    float x1 = volta.leftXMm + parentStaff.positionMm.x;
    float x2 = volta.rightXMm + parentStaff.positionMm.x;
    // compute hooks
    boolean hook = volta.leftHook || volta.rightHook;
    float hookHeight = 0;
    if (hook) {
        // height of hook is 2 interline spaces
        hookHeight = parentStaff.is * 2;
    }
    // width and color of the line
    Color color = Color.Companion.getBlack();
    // a little bit thicker than staff line
    float width = parentStaff.getLineWidthMm() * 1.5f;
    float paintWidth;
    // compute the horizontal line and color
    float y;
    Color paintColor;
    if (canvas.getFormat() == CanvasFormat.Raster) {
        BitmapStaff ss = parentStaff.getBitmapInfo().getBitmapStaff(scaling);
        y = parentStaff.positionMm.y + ss.getYMm(volta.lp);
        BitmapLine screenLine = parentStaff.getBitmapInfo().getBitmapLine(scaling, width, color);
        paintColor = screenLine.color;
        paintWidth = screenLine.widthMm;
    } else {
        y = parentStaff.computeYMm(volta.lp);
        paintColor = color;
        paintWidth = width;
    }
    // draw line and hooks
    canvas.drawLine(new Point2f(x1, y), new Point2f(x2, y), paintColor, paintWidth);
    if (volta.leftHook) {
        canvas.drawLine(new Point2f(x1, y), new Point2f(x1, y + hookHeight), paintColor, paintWidth);
    }
    if (volta.rightHook) {
        canvas.drawLine(new Point2f(x2, y), new Point2f(x2, y + hookHeight), paintColor, paintWidth);
    }
    // draw text
    FormattedText text = volta.text;
    if (text != null && text.getParagraphs().size() > 0) {
        float textAscent = text.getFirstParagraph().getMetrics().getAscent();
        float textX = x1 + parentStaff.is * 1;
        float textY = y + textAscent;
        canvas.drawText(volta.text, null, new Point2f(textX, textY), true, 0);
    }
}
Also used : Point2f(com.xenoage.utils.math.geom.Point2f) VoltaStamping(com.xenoage.zong.musiclayout.stampings.VoltaStamping) 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) FormattedText(com.xenoage.zong.core.text.FormattedText)

Example 3 with BitmapLine

use of com.xenoage.zong.musiclayout.stampings.bitmap.BitmapLine 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 4 with BitmapLine

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

the class StaffRenderer method draw.

/**
 * Draws the given {@link StaffStamping} on the given {@link Canvas},
 * using the given {@link RendererArgs}.
 */
@Override
public void draw(Stamping stamping, Canvas canvas, RendererArgs args) {
    StaffStamping staff = (StaffStamping) stamping;
    float scaling = args.targetScaling;
    Point2f position = staff.positionMm;
    // TODO: custom line width
    float lineWidthMm = staff.getLineWidthMm();
    float length = staff.lengthMm;
    Color color = Color.Companion.getBlack();
    if (canvas.getFormat() == CanvasFormat.Raster) {
        // render on screen
        BitmapLine screenLine = staff.getBitmapInfo().getBitmapLine(scaling, lineWidthMm, color);
        BitmapStaff ss = staff.getBitmapInfo().getBitmapStaff(scaling);
        position = new Point2f(position.x, position.y + ss.yOffsetMm);
        if (ss.isSimplifiedStaff) {
            // simplified staff (fill rectangle)
            color = screenLine.color;
            color = Companion.color(color.getR(), color.getG(), color.getB(), (int) (0.7f * color.getA()));
            // don't forget the line heights, they belong into the rectangle
            position = position.add(0, -1 * ss.lineHeightMm / 2);
            canvas.drawSimplifiedStaff(position, length, ss.heightMm + ss.lineHeightMm, color);
        } else {
            // normal staff (draw lines)
            canvas.drawStaff(position, length, staff.linesCount, screenLine.color, screenLine.widthMm, ss.interlineSpaceMm);
        }
    } else // if (canvas.getFormat() == CanvasFormat.Vector)
    {
        // render with high quality
        canvas.drawStaff(position, length, staff.linesCount, color, lineWidthMm, staff.is);
    }
}
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)

Example 5 with BitmapLine

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

the class StemRenderer method draw.

/**
 * Draws the given {@link StemStamping} on the given {@link Canvas},
 * using the given {@link RendererArgs}.
 */
@Override
public void draw(Stamping stamping, Canvas canvas, RendererArgs args) {
    StemStamping stem = (StemStamping) stamping;
    float scaling = args.targetScaling;
    // TODO: stem is thinner
    float lineWidthMm = stem.noteStaff.getLineWidthMm();
    Point2f p1Mm = new Point2f(stem.xMm - lineWidthMm / 2, stem.noteStaff.positionMm.y);
    Point2f p2Mm = new Point2f(stem.xMm + lineWidthMm / 2, stem.endStaff.positionMm.y);
    Color color = Color.Companion.getBlack();
    // shorten stem a little bit at the notehead - TODO: looks good. is code ok?
    float noteLp = stem.noteLp + 0.2f * (stem.endLp > stem.noteLp ? 1 : -1);
    if (canvas.getFormat() == CanvasFormat.Raster) {
        // render on screen or print
        BitmapLine screenLine = new BitmapLine(lineWidthMm, color, scaling);
        BitmapStaff noteScreenStaff = stem.noteStaff.getBitmapInfo().getBitmapStaff(scaling);
        BitmapStaff endScreenStaff = stem.endStaff.getBitmapInfo().getBitmapStaff(scaling);
        p1Mm = new Point2f(p1Mm.x, p1Mm.y + noteScreenStaff.getYMm(noteLp));
        p2Mm = new Point2f(p2Mm.x, p2Mm.y + endScreenStaff.getYMm(stem.endLp));
        // ensure same width for each stem in this staff
        float width = screenLine.widthMm;
        canvas.fillRect(new Rectangle2f(p1Mm.x, p1Mm.y, width, p2Mm.y - p1Mm.y), screenLine.color);
    } else if (canvas.getFormat() == CanvasFormat.Vector) {
        // render with high quality
        p1Mm = new Point2f(p1Mm.x, stem.noteStaff.computeYMm(noteLp));
        p2Mm = new Point2f(p2Mm.x, stem.endStaff.computeYMm(stem.endLp));
        canvas.fillRect(new Rectangle2f(p1Mm.x, p1Mm.y, p2Mm.x - p1Mm.x, p2Mm.y - p1Mm.y), color);
    }
}
Also used : Point2f(com.xenoage.utils.math.geom.Point2f) Color(com.xenoage.utils.color.Color) BitmapLine(com.xenoage.zong.musiclayout.stampings.bitmap.BitmapLine) Rectangle2f(com.xenoage.utils.math.geom.Rectangle2f) BitmapStaff(com.xenoage.zong.musiclayout.stampings.bitmap.BitmapStaff) StemStamping(com.xenoage.zong.musiclayout.stampings.StemStamping)

Aggregations

Color (com.xenoage.utils.color.Color)6 BitmapLine (com.xenoage.zong.musiclayout.stampings.bitmap.BitmapLine)6 BitmapStaff (com.xenoage.zong.musiclayout.stampings.bitmap.BitmapStaff)6 Point2f (com.xenoage.utils.math.geom.Point2f)5 StaffStamping (com.xenoage.zong.musiclayout.stampings.StaffStamping)5 FormattedText (com.xenoage.zong.core.text.FormattedText)2 Rectangle2f (com.xenoage.utils.math.geom.Rectangle2f)1 LegerLineStamping (com.xenoage.zong.musiclayout.stampings.LegerLineStamping)1 StemStamping (com.xenoage.zong.musiclayout.stampings.StemStamping)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