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);
}
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;
}
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);
}
Aggregations