use of com.xenoage.utils.color.Color in project Zong by Xenoage.
the class SlurRenderer method draw.
/**
* Draws the given {@link SlurStamping} on the given {@link Canvas},
* using the given {@link RendererArgs}.
*/
@Override
public void draw(Stamping stamping, Canvas canvas, RendererArgs args) {
SlurStamping slur = (SlurStamping) stamping;
float scaling = args.targetScaling;
// compute absolute coordinates in px
float p1xMm = slur.p1.xMm;
float p2xMm = slur.p2.xMm;
float c1xMm = p1xMm + slur.c1.xMm;
float c2xMm = p2xMm + slur.c2.xMm;
float p1yMm = 0, p2yMm = 0, c1yMm = 0, c2yMm = 0;
if (canvas.getFormat() == CanvasFormat.Raster) {
float staff1YMm = slur.staff1.positionMm.y;
float staff2YMm = slur.staff2.positionMm.y;
BitmapStaff screenStaff1 = slur.staff1.getBitmapInfo().getBitmapStaff(scaling);
BitmapStaff screenStaff2 = slur.staff2.getBitmapInfo().getBitmapStaff(scaling);
float bottomLineMm1 = staff1YMm + screenStaff1.lp0Mm;
float bottomLineMm2 = staff2YMm + screenStaff2.lp0Mm;
float isMm1 = screenStaff1.interlineSpaceMm;
float isMm2 = screenStaff2.interlineSpaceMm;
p1yMm = bottomLineMm1 - isMm1 * slur.p1.lp / 2;
p2yMm = bottomLineMm2 - isMm2 * slur.p2.lp / 2;
c1yMm = p1yMm - isMm1 * slur.c1.lp / 2;
c2yMm = p2yMm - isMm2 * slur.c2.lp / 2;
} else if (canvas.getFormat() == CanvasFormat.Vector) {
p1yMm = slur.staff1.computeYMm(slur.p1.lp);
p2yMm = slur.staff2.computeYMm(slur.p2.lp);
c1yMm = slur.staff1.computeYMm(slur.p1.lp + slur.c1.lp);
c2yMm = slur.staff2.computeYMm(slur.p2.lp + slur.c2.lp);
}
Point2f p1 = new Point2f(p1xMm, p1yMm);
Point2f p2 = new Point2f(p2xMm, p2yMm);
Point2f c1 = new Point2f(c1xMm, c1yMm);
Point2f c2 = new Point2f(c2xMm, c2yMm);
Color color = Color.Companion.getBlack();
/* //TEST
Point2i lastPoint = new Point2i(MathTools.bezier(p1, p2, c1, c2, 0));
for (int i = 1; i <= iterations; i++)
{
float t = 1f * i / iterations;
float width = 0.7f + (0.5f - Math.abs(t - 0.5f)) * 2.5f;
Point2i p = new Point2i(MathTools.bezier(p1, p2, c1, c2, t));
params.renderTarget.drawLine(lastPoint, p, color, MathTools.clampMin((int) (scaling * width), 1));
lastPoint = p;
} */
SimpleSlurShape slurShape = new SimpleSlurShape(p1, p2, c1, c2, slur.staff1.is);
canvas.fillPath(slurShape.getPath(), color);
}
use of com.xenoage.utils.color.Color 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.color.Color 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.color.Color 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.color.Color 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