use of com.xenoage.zong.musiclayout.stampings.bitmap.BitmapStaff in project Zong by Xenoage.
the class BarlineRenderer method paintLine.
/**
* Draws the given line with the given width in px.
*/
private static void paintLine(Canvas canvas, RendererArgs args, StaffStamping staff1, float staff1LinePosition, StaffStamping staff2, float staff2LinePosition, float xMm, float widthMm, Color color) {
if (canvas.getFormat() == CanvasFormat.Raster) {
float scaling = args.targetScaling;
BitmapStaff screenStaff1 = staff1.getBitmapInfo().getBitmapStaff(scaling);
BitmapStaff screenStaff2 = staff2.getBitmapInfo().getBitmapStaff(scaling);
Point2f p1 = new Point2f(xMm, staff1.positionMm.y + screenStaff1.getYMm(staff1LinePosition));
Point2f p2 = new Point2f(xMm, staff2.positionMm.y + screenStaff2.getYMm(staff2LinePosition));
canvas.drawLine(p1, p2, color, widthMm);
} else if (canvas.getFormat() == CanvasFormat.Vector) {
Point2f p1 = new Point2f(xMm, staff1.positionMm.y + staff1.is * (staff1.linesCount - 1 - staff1LinePosition / 2));
Point2f p2 = new Point2f(xMm, staff2.positionMm.y + staff2.is * (staff2.linesCount - 1 - staff2LinePosition / 2));
canvas.drawLine(p1, p2, color, widthMm);
}
}
use of com.xenoage.zong.musiclayout.stampings.bitmap.BitmapStaff 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);
}
use of com.xenoage.zong.musiclayout.stampings.bitmap.BitmapStaff in project Zong by Xenoage.
the class StaffSymbolRenderer method drawWith.
/**
* Paints the given symbol using the given information and rendering parameters.
*/
public static void drawWith(Symbol symbol, Color color, SP position, float scaling, StaffStamping parentStaff, boolean mirrorV, Canvas canvas, RendererArgs args) {
float viewScaling = args.targetScaling;
float symbolScaling = scaling * parentStaff.is;
float yPosition;
if (canvas.getFormat() == CanvasFormat.Raster) {
BitmapStaff ss = parentStaff.getBitmapInfo().getBitmapStaff(viewScaling);
yPosition = parentStaff.positionMm.y + ss.getYMm(position.lp);
symbolScaling *= ss.heightScaling;
/*
//TEST
int x = Units.mmToPx(positionX, viewScaling);
int yOffset = ss.getYOffsetPx();
int yTopLine = Units.mmToPx(
endStaff.getPosition().y + endStaff.getLineWidth() / 2,
viewScaling) + yOffset;
for (int i = 0; i < 2; i++)
params.renderTarget.drawLine(
new Point2i(x + i, yTopLine),
new Point2i(x + i, yTopLine + ss.getHeightPx()), Color.red, 1); */
} else {
yPosition = parentStaff.computeYMm(position.lp);
}
Point2f correctedPosition = new Point2f(position.xMm, yPosition);
SymbolsRenderer.draw(symbol, canvas, (color != null ? color : Color.Companion.getBlack()), correctedPosition, new Point2f(symbolScaling, (mirrorV ? -1 : 1) * symbolScaling));
}
use of com.xenoage.zong.musiclayout.stampings.bitmap.BitmapStaff in project Zong by Xenoage.
the class SystemCursorRenderer method draw.
/**
* Draws the given {@link SystemCursorStamping} on the given {@link Canvas},
* using the given {@link RendererArgs}.
*/
@Override
public void draw(Stamping stamping, Canvas canvas, RendererArgs args) {
SystemCursorStamping cursor = (SystemCursorStamping) stamping;
float viewScaling = args.targetScaling;
StaffStamping topStaff = cursor.topStaff;
StaffStamping bottomStaff = cursor.bottomStaff;
float x, y1, y2;
x = topStaff.positionMm.x + cursor.xMm;
if (canvas.getFormat() == CanvasFormat.Raster) {
float staffY = topStaff.positionMm.y;
BitmapStaff ss = topStaff.getBitmapInfo().getBitmapStaff(viewScaling);
// top staff: top line
y1 = staffY + ss.getYMm(topStaff.linesCount * 2);
// bottom staff: bottom line
staffY = bottomStaff.positionMm.y;
ss = bottomStaff.getBitmapInfo().getBitmapStaff(viewScaling);
y2 = staffY + ss.getYMm(-2);
} else {
y1 = topStaff.computeYMm(topStaff.linesCount * 2);
y2 = bottomStaff.computeYMm(-2);
}
canvas.drawLine(new Point2f(x, y1), new Point2f(x, y2), Companion.color(50, 50, 230), getCursorWidth(viewScaling));
}
use of com.xenoage.zong.musiclayout.stampings.bitmap.BitmapStaff in project Zong by Xenoage.
the class BitmapStaffTest method test12Pixel.
@Test
public void test12Pixel() {
// 1mm -> 1px, 5 lines, interline: 3.4 mm. Displayed staff must be 12px high.
float scaling = Units.pxToMm(1, 1);
BitmapStaff ss = new BitmapStaff(5, 3.4f, 0.1f, scaling);
assertEquals(Units.pxToMm(12, scaling), ss.heightMm, Delta.DELTA_FLOAT);
assertEquals(Units.pxToMm(1, scaling), ss.yOffsetMm, Delta.DELTA_FLOAT);
assertEquals(12 / (4 * 3.4f), ss.heightScaling, Delta.DELTA_FLOAT_ROUGH);
assertEquals(Units.pxToMm(3, scaling), ss.interlineSpaceMm, Delta.DELTA_FLOAT);
}
Aggregations