//____________________________________________________________________________________ void GRSingleNote::OnDraw( VGDevice & hdc ) const { float incy = 1; float posy = 0; int sum = mNumHelpLines; if (mNumHelpLines > 0) { // ledger lines up incy = -mCurLSPACE; posy = -mCurLSPACE; hdc.SetFontAlign( VGDevice::kAlignLeft | VGDevice::kAlignBase ); } else if( mNumHelpLines < 0 ) { incy = mCurLSPACE; posy = mGrStaff->getNumlines() * mCurLSPACE; sum = - sum; hdc.SetFontAlign( VGDevice::kAlignLeft | VGDevice::kAlignBase ); } // draw ledger lines const float ledXPos = -60 * 0.85f * mSize; for (int i = 0; i < sum; ++i, posy += incy) GRNote::DrawSymbol( hdc, kLedgerLineSymbol, ledXPos, ( posy - mPosition.y )); const VGColor oldcolor = hdc.GetFontColor(); if (mColRef) hdc.SetFontColor( VGColor( mColRef )); // - Draw elements (stems, dots...) DrawSubElements( hdc ); // - draw articulations & ornament const GRNEList * articulations = getArticulations(); if( articulations ) { for( GRNEList::const_iterator ptr = articulations->begin(); ptr != articulations->end(); ++ptr ) { GRNotationElement * el = *ptr; el->OnDraw(hdc); } } if (mOrnament ) mOrnament->OnDraw(hdc); // - Restore if (mColRef) hdc.SetFontColor( oldcolor ); if (gBoundingBoxesMap & kEventsBB) DrawBoundingBox( hdc, kEventBBColor); }
/** \brief Draws a musical symbol glyph at given position into input graphic device context. It possible to scale the symbol, by specifying a font height and a x-scale. */ void GRNotationElement::OnDrawSymbol( VGDevice & hdc, unsigned int inSymbol, float inOffsetX, float inOffsetY, float inFontSize ) const //, float inScaleX ) const { // - Setup colors if(!mDraw) return; const unsigned char * colref = getColRef(); const VGColor prevFontColor = hdc.GetFontColor(); if (colref) hdc.SetFontColor( VGColor( colref )); // int nBackmode = hdc.GetBackgroundMode(); // hdc.SetBackgroundMode( VGDevice::kModeTransparent ); // - Setup text align hdc.SetFontAlign(getTextAlign()); // - Draw DrawSymbol( hdc, inSymbol, inOffsetX, inOffsetY, inFontSize ); // DrawBoundingBox( hdc, VGColor(0,0,200)); // debug // - Restore context if (colref) hdc.SetFontColor( prevFontColor ); //(TODO: in a parent method) }
void GRClef::OnDraw(VGDevice & hdc) const { // DrawBoundingBox( hdc, GColor( 255, 200, 0, 150)); // DEBUG if (error) return; GRTagARNotationElement::OnDraw(hdc); if( mDoubleTreble ) { const float xOffset = ((mRightSpace + mLeftSpace) * float(0.5)) - LSPACE * float(0.2); OnDrawSymbol( hdc, mSymbol, xOffset, 0 ); } else if( mOctaveStr ) // Draws the octava { const int fontSize = (int)(float(1.5) * LSPACE); NVstring textFont ( FontManager::kDefaultTextFont ); const VGFont* fontRef = FontManager::FindOrCreateFont( fontSize, &textFont ); const float octX = mPosition.x + mOctaveOffset.x; const float octY = mPosition.y + mOctaveOffset.y; // hdc.SelectFont( fontRef ); hdc.SetTextFont( fontRef ); // hdc.SetMusicFont( fontRef ); hdc.SetFontAlign( VGDevice::kAlignBottom | VGDevice::kAlignCenter ); hdc.DrawString( octX, octY, mOctaveStr, (int)strlen(mOctaveStr) ); } }
// ---------------------------------------------------------------------------- void GRTempo::DrawText( VGDevice & hdc, const char * cp, float xOffset, float yOffset, float * outWidth ) const { // hdc.SelectFont( mFont ); hdc.SetTextFont( mFont ); hdc.SetFontAlign (getTextAlign()); hdc.DrawString ( xOffset + mPosition.x, yOffset + mPosition.y, cp, (int)strlen(cp) ); if( outWidth ) { float fooHeight; // hdc.GetTextExtent(cp, (int)strlen(cp), outWidth, &fooHeight); const VGFont *font = hdc.GetTextFont(); if (!font) { font = FontManager::gFontText; } if (!font) { std::cerr << "Cannot find text font" << std::endl; *outWidth = 0; } else { font->GetExtent(cp, (int)strlen(cp), outWidth, &fooHeight, &hdc); } } }
// ------------------------------------------------------------------------- void GRNotationElement::OnDrawText( VGDevice & hdc, const char * cp, int inCharCount ) const { // first we have to get a font .... if(!mDraw) return; const VGFont* hmyfont = FontManager::gFontText; const int size = getFontSize(); const NVstring * font = getFont(); const unsigned char * colref = getColRef(); if (font && font->length() > 0) { // handle font-attributes ... hmyfont = FontManager::FindOrCreateFont( size, font, getFontAttrib()); } hdc.SetTextFont( hmyfont ); const VGColor prevTextColor = hdc.GetFontColor(); if (colref) hdc.SetFontColor( VGColor( colref )); // const unsigned int ta = hdc.GetTextAlign(); // GColor backColor = hdc.GetTextBackgroundColor(); // hdc.SetTextBackgroundColor( 255, 255, 255, 255 ); const NVPoint & refpos = getReferencePosition(); const NVPoint & offset = getOffset(); hdc.SetFontAlign(getTextAlign()); hdc.DrawString( (float)(mPosition.x + offset.x + (refpos.x * size)), (float)(mPosition.y + offset.y + (refpos.y * size)), cp, inCharCount ); // hdc.SetTextAlign( ta ); // hdc.SetTextBackgroundColor( backColor ); if (colref) hdc.SetFontColor( prevTextColor ); }
// ---------------------------------------------------------------------------- void GRTuplet::OnDraw(VGDevice & hdc) const { if(!mDraw) return; assert(gCurSystem); GRSystemStartEndStruct * sse = getSystemStartEndStruct(gCurSystem); if (sse == 0) return; VGColor prevFontColor = hdc.GetFontColor(); if (mColRef) { hdc.SetFontColor(VGColor(mColRef)); hdc.PushPenColor(VGColor(mColRef)); } GRTupletSaveStruct * st = (GRTupletSaveStruct *)sse->p; const ARTuplet * arTuplet = getARTuplet(); int charCount = 0; float const thickness = arTuplet->getThickness(); float const dxOffset = (arTuplet->getDX() ? arTuplet->getDX()->getValue() : 0); // - Draws the number const int numerator = arTuplet->getNumerator(); if (numerator > 0) { std::stringstream bufferNumeratorDenominatorStream; const int denominator = arTuplet->getDenominator(); if (denominator > 0) bufferNumeratorDenominatorStream << numerator << ":" << denominator; else bufferNumeratorDenominatorStream << numerator; std::string bufferNumeratorDenominator = bufferNumeratorDenominatorStream.str(); charCount = bufferNumeratorDenominator.size(); const VGFont *font = 0; const NVstring fontName("Times New Roman"); NVstring attrs; if (arTuplet->isTextBold()) attrs = "b"; font = FontManager::FindOrCreateFont(int(80 * arTuplet->getTextSize()), &fontName, &attrs); hdc.SetTextFont(font); /* In order that numerator/denominator stays at the same vertical position even if size is changed */ float extentCharNumeratorDenominatorx; float extentCharNumeratorDenominatory; FontManager::gFontScriab->GetExtent(bufferNumeratorDenominator.c_str(), bufferNumeratorDenominator.size(), &extentCharNumeratorDenominatorx, &extentCharNumeratorDenominatory, &hdc); int offset = int(extentCharNumeratorDenominatory / 11.2 * arTuplet->getTextSize() - 40); /***************************************************************************************************/ hdc.SetFontAlign(VGDevice::kAlignCenter | VGDevice::kAlignBottom); hdc.DrawString(st->textpos.x + dxOffset, st->textpos.y + offset, bufferNumeratorDenominator.c_str(), charCount); } // - Draws the braces const float middleX = (st->p1.x + st->p2.x) * 0.5f; const float middleY = (st->p1.y + st->p2.y) * 0.5f; const float slope = (st->p2.y - st->p1.y) / (st->p2.x - st->p1.x); //<- could be stored const float textSpace = ((float)charCount + float(0.5)) * LSPACE * float(0.5) * arTuplet->getTextSize(); if (mShowLeftBrace | mShowRightBrace) { hdc.PushPenWidth(thickness); if (mShowLeftBrace) { //arTuplet->getLeftBrace()) // (mBraceState & BRACELEFT) float p1X = st->p1.x + dxOffset; if (sse->startflag == GRSystemStartEndStruct::LEFTMOST) { GDirection d = mDirection; // If a position is explicitely set, we use it. if (arTuplet->isPositionAbove() == 1) d = dirUP; else if (arTuplet->isPositionAbove() == -1) d = dirDOWN; hdc.Line(p1X, st->p1.y + 0.5f * LSPACE * (float)d, p1X, st->p1.y); } hdc.Line(p1X, st->p1.y, middleX - textSpace + dxOffset, middleY - slope * textSpace ); } if (mShowRightBrace) { //arTuplet->getRightBrace()) // (mBraceState & BRACERIGHT) float p2X = st->p2.x + dxOffset; hdc.Line(middleX + textSpace + dxOffset, middleY + slope * textSpace, p2X, st->p2.y); if (sse->endflag == GRSystemStartEndStruct::RIGHTMOST) { GDirection d = mDirection; // If a position is explicitely set, we use it. if (arTuplet->isPositionAbove() == 1) d = dirUP; else if (arTuplet->isPositionAbove() == -1) d = dirDOWN; hdc.Line(p2X, st->p2.y, p2X, st->p2.y + 0.5f * LSPACE * (float)d); } } hdc.PopPenWidth(); } if (mColRef) { hdc.SetFontColor(prevFontColor); hdc.PopPenColor(); } }