/** \brief Low-level symbol drawing. */ void GRNotationElement::DrawSymbol( VGDevice & hdc, unsigned int inSymbol, float inOffsetX, float inOffsetY, float inFontSize ) const { if(!mDraw) return; // - Setup font const VGFont* myfont = FontManager::gFontScriab; const float theSize = (inFontSize != 0) ? inFontSize : getSize(); if (theSize < kMinNoteSize) return; // element is too small, don't draw it if (theSize != float(1.0)) { const int newFontSize = (int)(theSize * 4 * LSPACE + 0.5f ); // +0.5 to round from float to int. myfont = FontManager::FindOrCreateFont( newFontSize ); } // hdc.SelectFont( myfont ); hdc.SetMusicFont( myfont ); // - Setup position const NVPoint & offset = getOffset(); const NVPoint & refpos = getReferencePosition(); const float xPos = mPosition.x + offset.x + (refpos.x * theSize) + inOffsetX; const float yPos = mPosition.y + offset.y + (refpos.y * theSize) + inOffsetY; // - Draw hdc.DrawMusicSymbol( xPos, yPos, inSymbol ); #ifdef SHOWRODS // draw the rods .... const float leftspc = getLeftSpace(); const float rightspc = getRightSpace(); if (leftspc) { const float myposy = 350; hdc.PushPen(VGColor( 0, 0, 200 ), 5 ); // Always blue hdc.Line( mPosition.x-leftspc,myposy-30, mPosition.x-leftspc,myposy+30 ); hdc.Line( mPosition.x-leftspc, myposy, mPosition.x, myposy ); hdc.PopPen(); } if (rightspc) { const float myposy = 350; hdc.PushPen(VGColor( 0, 0, 200 ), 5 ); // Always blue hdc.Line( mPosition.x+rightspc, myposy-30, mPosition.x+rightspc, myposy+30 ); hdc.LineTo( mPosition.x+rightspc, myposy, mPosition.x, myposy ); hdc.PopPen(); } #endif // #ifdef SHOWRODS }
// -------------------------------------------------------------------------- void GRDoubleBar::DrawWithLines( VGDevice & hdc ) const { if ((getTagType() != GRTag::SYSTEMTAG) && isSystemSlice()) return; // don't draw staff bars on system slices if (fSize < kMinNoteSize) // Too small, don't draw return; // - Vertical adjustement according to staff's line number float offsety1 = (fmod(- 0.5f * fLineNumber - 2, 3) + 1.5f) * LSPACE; float offsety2 = 0; if (fLineNumber != 0 && fLineNumber != 1) offsety2 = ((fLineNumber - 5) % 6) * LSPACE; // - Horizontal adjustement according to staff's lines size and staff's size const float offsetX = (fStaffThickness - 4) * 0.5f - 24; const float spacing = LSPACE * 0.7f * fSize; const float x1 = mPosition.x + offsetX; const float x2 = x1 + spacing; const float y1 = mPosition.y + mBoundingBox.top + offsety1 * fSize; const float y2 = y1 + mBoundingBox.bottom + offsety2 * fSize; float lineThickness = kLineThick * 1.5f * fSize; hdc.PushPenWidth(lineThickness); hdc.Line(x1, y1 + lineThickness / 2, x1, y2 - lineThickness / 2); hdc.Line(x2, y1 + lineThickness / 2, x2, y2 - lineThickness / 2); hdc.PopPenWidth(); }
// -------------------------------------------------------------------------- void GRBar::DrawWithLines( VGDevice & hdc ) const { if ((getTagType() != GRTag::SYSTEMTAG) && isSystemSlice()) return; // don't draw staff bars on system slices const float staffSize = mGrStaff->getSizeRatio(); if (staffSize < kMinNoteSize) // Too small, don't draw return; // - Vertical adjustement according to staff's line number float offsety1 = (fmod(- 0.5f * fLineNumber - 2, 3) + 1.5f) * LSPACE; float offsety2 = 0; if (fLineNumber != 0 && fLineNumber != 1) offsety2 = ((fLineNumber - 5) % 6) * LSPACE; const float offsetX = 3 + (staffSize - 1) * 2; const float x = mPosition.x + offsetX; const float y1 = mPosition.y + mBoundingBox.top + offsety1 * staffSize; const float y2 = y1 + mBoundingBox.bottom + offsety2 * staffSize; hdc.PushPenWidth( mGrStaff ? mGrStaff->currentLineThikness() * staffSize : kLineThick * staffSize ); hdc.Line(x, y1, x, y2); hdc.PopPenWidth(); }
/** \brief For debugging purpose only */ void GRNotationElement::DrawExtents( VGDevice & hdc, const VGColor & inColor ) const { if(!mDraw) return; #if (0) hdc.PushPen( inColor, LSPACE * 0.15f ); const float x1 = mPosition.x - getLeftSpace(); const float x2 = mPosition.x + getRightSpace(); const float y = mPosition.y; hdc.Line( x1, y, x2, y ); hdc.Line( x1, y - LSPACE, x1, y + LSPACE ); hdc.Line( x2, y - LSPACE, x2, y + LSPACE ); hdc.PopPen(); #endif }
void GRCrescendo::OnDraw( VGDevice & hdc) const { if (!mDraw) return; if (fCrescInfos->points[0].x == fCrescInfos->points[1].x) return; assert(gCurSystem); GRSystemStartEndStruct * sse = getSystemStartEndStruct(gCurSystem); if (sse == 0) return; const VGColor prevTextColor = hdc.GetFontColor(); if (mColRef) { hdc.PushPenColor(VGColor(mColRef)); hdc.PushFillColor(VGColor(mColRef)); hdc.SetFontColor(VGColor(mColRef)); } hdc.PushPenWidth(fCrescInfos->thickness); hdc.Line(fCrescInfos->points[0].x , fCrescInfos->points[0].y, fCrescInfos->points[1].x , fCrescInfos->points[1].y); hdc.Line(fCrescInfos->points[0].x , fCrescInfos->points[0].y, fCrescInfos->points[2].x , fCrescInfos->points[2].y); const float xMarkingOffset = fCrescInfos->points[1].x + 30; const float yMarkingOffset = fCrescInfos->points[0].y - 277 + (mTagSize - 1) * 25; if (fCrescInfos->fMarkingSymbol != 0) OnDrawSymbol(hdc, fCrescInfos->fMarkingSymbol, xMarkingOffset, yMarkingOffset, mTagSize); hdc.PopPenWidth(); if (mColRef) { hdc.SetFontColor(prevTextColor); hdc.PopFillColor(); hdc.PopPenColor(); } }
/** \brief This tries to draw the spring. */ void GRSpring::OnDraw( VGDevice & hdc ) const { const VGColor springColor ( 0, 0, 255, 50 ); // semi-transparent blue const float springThickness = 5; hdc.PushPen( springColor, springThickness ); const float offsety = -100; float x = posx, y = offsety; const int numturns = (int)((x-60.0f) / 40.0f + 0.5f ); if (numturns < 1) { hdc.Line( x, y, (posx + x), offsety ); } else { const float offset = ((x - numturns * 40) * 0.5f); hdc.Line( x, y, posx + offset, offsety ); x = posx + offset; for( float i = 0; i < numturns; i++ ) { hdc.Line( x, y, posx + offset + 40 * i + 10, -20 + offsety ); x = posx + offset + 40 * i + 10; y = -20 + offsety; hdc.Line( x, y, posx + offset + 40 * i + 30, 20 + offsety ); x = posx + offset + 40 * i + 30; y = 20 + offsety; hdc.Line( x, y, posx + offset + 40 * i + 40, offsety ); x = posx + offset + 40 * i + 40; y = offsety; } hdc.Line( x, y, (posx + x), 0 + offsety ); } hdc.PopPen(); }
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(); } }
/** \brief Draws the score page. The GuidoEngine does not draw nor erase the background. Client applications must display it by themself. Usually, printing does not require to draw a background. */ void GRPage::OnDraw( VGDevice & hdc, const GuidoOnDrawDesc & inDrawInfos ) const { setScaling( hdc, (float)inDrawInfos.sizex, (float)inDrawInfos.sizey ); // if croll coords are in virtual units: hdc.SetOrigin( - (float)inDrawInfos.scrollx, - (float)inDrawInfos.scrolly ); // (JB) sign change // if scroll coords are in device units: // hdc.SetOrigin( - (float)inDrawInfos.scrollx / hdc.GetXScale(), // - (float)inDrawInfos.scrolly / hdc.GetYScale()); if ( /*fullredraw ||*/ inDrawInfos.updateRegion.erase )// (JB) || c->ps.hdc == NULL { gClipRect.Set( 0, 0, getPageWidth(), getPageHeight()); } else { /* was: // This is the update region const GCoord left = c->updateRegion.left; const GCoord top = c->updateRegion.top; const GCoord right = c->updateRegion.right; const GCoord bottom = c->updateRegion.bottom; DPtoLPRect( hdc, left, top, right, bottom, &gClipRect ); // (JB) still ok ? */ gClipRect.Set( float(inDrawInfos.updateRegion.left), float(inDrawInfos.updateRegion.top), float(inDrawInfos.updateRegion.right), float(inDrawInfos.updateRegion.bottom) ); } #if (0) // Draw margins. const float x1 = getMarginLeft(); const float x2 = getPageWidth() - getMarginRight(); const float x3 = getPageWidth(); const float y1 = getMarginTop(); const float y2 = getPageHeight() - getMarginBottom(); const float y3 = getPageHeight(); hdc.PushPen( VGColor( 150, 150, 255 ), 5 ); // opaque hdc.PushFillColor( VGColor( 0, 0, 0, ALPHA_OPAQUE )); // DrawBoundingBox( hdc, GColor( 200, 255, 200 )); hdc.Rectangle( 0, 0, x3, y3 ); hdc.Rectangle( x1, y1, x2, y2 ); hdc.Line( 0, 0, x1, y1 ); // top left hdc.Line( 0, y3, x1, y2 ); // bottom left hdc.Line( x3, 0, x2, y1 ); // top right hdc.Line( x3, y3, x2, y2 ); // bottom right hdc.PopFillColor(); hdc.PopPen(); #endif // - Draws elements of the page. OnDraw( hdc ); // trace (hdc); }
// ---------------------------------------------------------------------------- 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(); } }