Search in sources :

Example 1 with TimeStamping

use of com.xenoage.zong.musiclayout.stampings.TimeStamping in project Zong by Xenoage.

the class TimeRenderer method draw.

/**
 * Draws the given {@link TimeStamping} on the given {@link Canvas},
 * using the given {@link RendererArgs}.
 */
@Override
public void draw(Stamping stamping, Canvas canvas, RendererArgs args) {
    TimeStamping s = (TimeStamping) stamping;
    SymbolPool symbolPool = args.symbolPool;
    float interlineSpace = s.parentStaff.is;
    float linesCount = s.parentStaff.linesCount;
    // write numerator digits
    float offsetX = s.numeratorOffsetIs * interlineSpace;
    String num = Integer.toString(s.time.element.getType().getNumerator());
    for (int i = 0; i < num.length(); i++) {
        int d = num.charAt(i) - '0';
        Symbol symbol = symbolPool.getSymbol(CommonSymbol.getDigit(d));
        if (symbol != null) {
            float symbolWidth = symbol.getBoundingRect().size.width;
            StaffSymbolRenderer.drawWith(symbol, null, sp(s.xMm + offsetX, linesCount + 1), 1, s.parentStaff, false, canvas, args);
            offsetX += (symbolWidth + s.digitGapIs) * interlineSpace;
        }
    }
    // write denominator digits
    offsetX = s.denominatorOffsetIs * interlineSpace;
    String den = Integer.toString(s.time.element.getType().getDenominator());
    for (int i = 0; i < den.length(); i++) {
        int d = den.charAt(i) - '0';
        Symbol symbol = symbolPool.getSymbol(CommonSymbol.getDigit(d));
        if (symbol != null) {
            float symbolWidth = symbol.getBoundingRect().size.width;
            StaffSymbolRenderer.drawWith(symbol, null, sp(s.xMm + offsetX, linesCount - 3), 1, s.parentStaff, false, canvas, args);
            offsetX += (symbolWidth + s.digitGapIs) * interlineSpace;
        }
    }
}
Also used : Symbol(com.xenoage.zong.symbols.Symbol) CommonSymbol(com.xenoage.zong.symbols.common.CommonSymbol) TimeStamping(com.xenoage.zong.musiclayout.stampings.TimeStamping) SymbolPool(com.xenoage.zong.symbols.SymbolPool)

Aggregations

TimeStamping (com.xenoage.zong.musiclayout.stampings.TimeStamping)1 Symbol (com.xenoage.zong.symbols.Symbol)1 SymbolPool (com.xenoage.zong.symbols.SymbolPool)1 CommonSymbol (com.xenoage.zong.symbols.common.CommonSymbol)1