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 GRBeam::OnDraw( VGDevice & hdc) const { if (error) return; if(!mDraw) return; GRSystemStartEndStruct * sse = getSystemStartEndStruct( gCurSystem ); if (sse == 0) return; GRBeamSaveStruct * st = (GRBeamSaveStruct *)sse->p; assert(st); if (mColRef) { VGColor color ( mColRef ); // custom or black hdc.PushFillColor( color ); hdc.PushPen( color, 1); } float ax [4] = { st->p[0].x, st->p[1].x, st->p[3].x, st->p[2].x }; float ay [4] = { st->p[0].y, st->p[1].y, st->p[3].y, st->p[2].y }; // This does the drawing! hdc.Polygon(ax, ay, 4); if (st->simpleBeams) { GuidoPos smplpos = st->simpleBeams->GetHeadPosition(); while (smplpos) { GRSimpleBeam * smplbeam = st->simpleBeams->GetNext(smplpos); smplbeam->OnDraw(hdc); } } if(drawDur) { const char * fraction = st->duration.c_str(); size_t n = st->duration.length(); hdc.PushPenWidth(4); if(sse->startflag != GRSystemStartEndStruct::OPENLEFT) { hdc.Line(st->DurationLine[0].x, st->DurationLine[0].y, st->DurationLine[1].x, st->DurationLine[1].y); hdc.Line(st->DurationLine[1].x, st->DurationLine[1].y, st->DurationLine[2].x, st->DurationLine[2].y); hdc.Line(st->DurationLine[3].x, st->DurationLine[3].y, st->DurationLine[4].x, st->DurationLine[4].y); } else hdc.Line(st->DurationLine[1].x, st->DurationLine[1].y, st->DurationLine[4].x, st->DurationLine[4].y); if(sse->endflag != GRSystemStartEndStruct::OPENRIGHT) hdc.Line(st->DurationLine[4].x, st->DurationLine[4].y, st->DurationLine[5].x, st->DurationLine[5].y); const VGFont* hmyfont; hmyfont = FontManager::gFontText; hdc.SetTextFont( hmyfont ); if (sse->startflag != GRSystemStartEndStruct::OPENLEFT) hdc.DrawString(st->DurationLine[2].x + LSPACE/4, st->DurationLine[2].y + LSPACE / 2, fraction, n); hdc.PopPenWidth(); } if (mColRef) { hdc.PopPen(); hdc.PopFillColor(); } }
// ---------------------------------------------------------------------------- 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(); } }