use of com.xenoage.utils.math.geom.Point2f 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);
}
}
use of com.xenoage.utils.math.geom.Point2f 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);
}
}
use of com.xenoage.utils.math.geom.Point2f 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);
}
use of com.xenoage.utils.math.geom.Point2f in project Zong by Xenoage.
the class BracketRenderer method paintBrace.
/**
* Draws a brace, using the given bracket stamping and rendering parameters.
*/
private static void paintBrace(BracketStamping bracket, Canvas canvas, RendererArgs args) {
float interlineSpace = bracket.firstStaff.is;
float y1 = getStaffTopY(bracket.firstStaff, canvas, args);
float y2 = getStaffBottomY(bracket.lastStaff, canvas, args);
Point2f pCenter = new Point2f(bracket.xMm, (y1 + y2) / 2);
Symbol braceSymbol = args.symbolPool.getSymbol(CommonSymbol.BracketBrace);
float symbolScaling = (y2 - y1) / braceSymbol.getBoundingRect().size.height;
SymbolsRenderer.draw(braceSymbol, canvas, Color.Companion.getBlack(), pCenter, new Point2f(interlineSpace * 1.2f, symbolScaling));
}
use of com.xenoage.utils.math.geom.Point2f in project Zong by Xenoage.
the class BracketRenderer method paintBracket.
/**
* Draws a bracket, using the given bracket stamping and rendering parameters.
*/
private static void paintBracket(BracketStamping bracket, Canvas canvas, RendererArgs args) {
float interlineSpace = bracket.firstStaff.is;
float y1 = getStaffTopY(bracket.firstStaff, canvas, args);
float y2 = getStaffBottomY(bracket.lastStaff, canvas, args);
Point2f p1Mm = new Point2f(bracket.xMm, y1);
Symbol bracketLineSymbol = args.symbolPool.getSymbol(CommonSymbol.BracketBracketLine);
Symbol bracketEndSymbol = args.symbolPool.getSymbol(CommonSymbol.BracketBracketEnd);
// to avoid gaps
float lineYCorrection = bracketEndSymbol.getBoundingRect().size.height / 2;
float lineYScaling = (y2 - y1 + lineYCorrection) / bracketLineSymbol.getBoundingRect().size.height;
SymbolsRenderer.draw(bracketLineSymbol, canvas, Color.Companion.getBlack(), p(p1Mm.x, p1Mm.y - lineYCorrection / 2), new Point2f(interlineSpace, lineYScaling));
SymbolsRenderer.draw(bracketEndSymbol, canvas, Color.Companion.getBlack(), p1Mm, new Point2f(interlineSpace, -interlineSpace));
p1Mm = new Point2f(p1Mm.x, y2);
SymbolsRenderer.draw(bracketEndSymbol, canvas, Color.Companion.getBlack(), p1Mm, new Point2f(interlineSpace, interlineSpace));
}
Aggregations