Search in sources :

Example 6 with Color

use of com.xenoage.utils.color.Color in project Zong by Xenoage.

the class BarlineRenderer method paintBarline.

/**
 * Draws a barline with the given style between the given line of the given
 * staff and the other given line of the other
 * given staff, using the given rendering parameters.
 * The horizontal position correction in px is returned.
 *
 * TIDY TIDY TIDY
 */
private static float paintBarline(Canvas canvas, RendererArgs args, StaffStamping staff1, float staff1LP, StaffStamping staff2, float staff2LP, float xPosition, BarlineStyle style) {
    Color col = Color.Companion.getBlack();
    // barline a little bit thicker than staff line
    float lightMm = staff1.getLineWidthMm() * 1.5f;
    float heavyMm = lightMm * 3f;
    float gapMm = lightMm * 1.5f;
    float l = lightMm;
    float h = heavyMm;
    float g = gapMm;
    Color lightColor = col, heavyColor = col;
    /* UNNEEDED... looks good anyway
		//correction for bitmap display
		if (canvas.getFormat() == CanvasFormat.Bitmap)
		{
			//screen
			//light
			BitmapLine screenLine = new BitmapLine(lightMm, col, scaling);
			l = screenLine.widthMm;
			lightColor = screenLine.color;
			//heavy
			screenLine = new BitmapLine(heavyMm, col, scaling);
			h = screenLine.widthMm;
			heavyColor = screenLine.color;
			//gap (for a better look, use bigger gap at low zoom. tried out.)
			float gapPxFloat = Units.mmToPx(gapMm, scaling);
			if (gapPxFloat >= 2)
				g = gapMm;
			else if (gapPxFloat >= 1f)
				g = Units.pxToMm(2, scaling);
			else if (gapPxFloat >= 0.2f)
				g = Units.pxToMm(1, scaling);
			else
				g = 0;
		} */
    // if on the very left or very right side of the staff, don't center
    // the barline but place it completely within the staff
    boolean isLeft = (xPosition <= staff1.positionMm.x + lightMm);
    boolean isRight = (xPosition >= staff1.positionMm.x + staff1.lengthMm - lightMm);
    float x = xPosition;
    float c = 0;
    // half of light/heavy/gap
    float l2 = l / 2;
    float h2 = h / 2;
    float g2 = g / 2;
    // TODO: Dashed, Dotted
    switch(style) {
        case Regular:
            if (isLeft) {
                c = l2;
                x += c;
            } else if (isRight) {
                c = -l2;
                x += c;
            }
            paintLine(canvas, args, staff1, staff1LP, staff2, staff2LP, x, l, lightColor);
            break;
        case Heavy:
            if (isLeft) {
                c = h2;
                x += c;
            } else if (isRight) {
                c = -h2;
                x += c;
            }
            paintLine(canvas, args, staff1, staff1LP, staff2, staff2LP, x, h, heavyColor);
            break;
        case LightLight:
            if (isLeft) {
                c = g2 + 2 * l2;
                x += c;
            } else if (isRight) {
                c = -l2 - g2 - l2;
                x += c;
            }
            paintLine(canvas, args, staff1, staff1LP, staff2, staff2LP, x - g2 - l2, l, lightColor);
            paintLine(canvas, args, staff1, staff1LP, staff2, staff2LP, x + g2 + l2, l, lightColor);
            break;
        case // heavy is centered (if barline not at the border of the staff)
        LightHeavy:
            if (isLeft) {
                c = 2 * l2 + g + h2;
                x += c;
            } else if (isRight) {
                c = -h2;
                x += c;
            }
            paintLine(canvas, args, staff1, staff1LP, staff2, staff2LP, x - h2 - g - l2, l, lightColor);
            paintLine(canvas, args, staff1, staff1LP, staff2, staff2LP, x, h, heavyColor);
            break;
        case // heavy is centered (if barline not at the border of the staff)
        HeavyLight:
            if (isLeft) {
                c = h2;
                x += c;
            } else if (isRight) {
                c = -l2 - h2 - g - l2;
                x += c;
            }
            paintLine(canvas, args, staff1, staff1LP, staff2, staff2LP, x, h, heavyColor);
            paintLine(canvas, args, staff1, staff1LP, staff2, staff2LP, x + h2 + g + l2, l, lightColor);
            break;
        case HeavyHeavy:
            if (isLeft) {
                c = g2 + 2 * h2;
                x += c;
            } else if (isRight) {
                c = -h2 - g2 - h2;
                x += c;
            }
            paintLine(canvas, args, staff1, staff1LP, staff2, staff2LP, x - g2 - h2, h, heavyColor);
            paintLine(canvas, args, staff1, staff1LP, staff2, staff2LP, x + g2 + h2, h, heavyColor);
            break;
        case None:
        case Dashed:
        case Dotted:
            // TODO
            break;
    }
    return c;
}
Also used : Color(com.xenoage.utils.color.Color)

Example 7 with Color

use of com.xenoage.utils.color.Color 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 Color

use of com.xenoage.utils.color.Color in project Zong by Xenoage.

the class StampingRenderer method drawBoundingShape.

/**
 * Draws the bounding shape of the given stamping, if it is a
 * {@link Rectangle2f}.
 */
public void drawBoundingShape(Stamping stamping, Canvas canvas) {
    if (stamping.getBoundingShape() instanceof Rectangle2f) {
        Rectangle2f r = (Rectangle2f) stamping.getBoundingShape();
        Color ci = Companion.color(0, 0, 255, 100);
        canvas.drawLine(r.nw(), r.ne(), ci, 0.5f);
        canvas.drawLine(r.ne(), r.se(), ci, 0.5f);
        canvas.drawLine(r.se(), r.sw(), ci, 0.5f);
        canvas.drawLine(r.sw(), r.nw(), ci, 0.5f);
    }
}
Also used : Color(com.xenoage.utils.color.Color) Rectangle2f(com.xenoage.utils.math.geom.Rectangle2f)

Example 9 with Color

use of com.xenoage.utils.color.Color in project Zong by Xenoage.

the class BitmapLineTest method testHalfPixel.

@Test
public void testHalfPixel() {
    // 0.5px line. Should result in 1 px with transparency.
    for (float scaling = 0.1f; scaling < 5; scaling *= 1.5f) {
        Color color = Color.Companion.getBlack();
        BitmapLine sl = new BitmapLine(Units.pxToMm(0.5f, scaling), color, scaling);
        assertEquals(Units.pxToMm(1, scaling), sl.widthMm, Delta.DELTA_FLOAT);
        int alpha = sl.color.getA();
        assertTrue(Math.abs(alpha - 128) < 5);
    }
}
Also used : Color(com.xenoage.utils.color.Color) Test(org.junit.Test)

Example 10 with Color

use of com.xenoage.utils.color.Color in project Zong by Xenoage.

the class BitmapLineTest method test1Pixel.

@Test
public void test1Pixel() {
    // 1px line. Should result in 1 px, opaque.
    for (float scaling = 0.1f; scaling < 5; scaling *= 1.5f) {
        Color color = Color.Companion.getBlack();
        BitmapLine sl = new BitmapLine(Units.pxToMm(1, scaling), color, scaling);
        assertEquals(Units.pxToMm(1, scaling), sl.widthMm, Delta.DELTA_FLOAT);
        assertEquals(255, sl.color.getA());
    }
}
Also used : Color(com.xenoage.utils.color.Color) Test(org.junit.Test)

Aggregations

Color (com.xenoage.utils.color.Color)15 BitmapStaff (com.xenoage.zong.musiclayout.stampings.bitmap.BitmapStaff)8 Point2f (com.xenoage.utils.math.geom.Point2f)7 StaffStamping (com.xenoage.zong.musiclayout.stampings.StaffStamping)6 BitmapLine (com.xenoage.zong.musiclayout.stampings.bitmap.BitmapLine)6 FormattedText (com.xenoage.zong.core.text.FormattedText)3 Test (org.junit.Test)3 FontInfo (com.xenoage.utils.font.FontInfo)2 Rectangle2f (com.xenoage.utils.math.geom.Rectangle2f)2 FormattedTextStyle (com.xenoage.zong.core.text.FormattedTextStyle)2 NonNull (com.xenoage.utils.annotations.NonNull)1 Alignment (com.xenoage.zong.core.text.Alignment)1 FormattedTextElement (com.xenoage.zong.core.text.FormattedTextElement)1 FormattedTextParagraph (com.xenoage.zong.core.text.FormattedTextParagraph)1 FormattedTextString (com.xenoage.zong.core.text.FormattedTextString)1 FontInfoReader (com.xenoage.zong.io.musicxml.in.readers.FontInfoReader)1 OtherReader.readAlignment (com.xenoage.zong.io.musicxml.in.readers.OtherReader.readAlignment)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