/** \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 GRSimpleBeam::OnDraw( VGDevice & hdc ) const { const unsigned char * colref = getColRef(); if (colref) { VGColor color ( colref ); // custom or black hdc.PushFillColor( color ); hdc.PushPen( color, 1 ); } float ax [4] = { fPoints[0].x, fPoints[1].x, fPoints[3].x, fPoints[2].x }; float ay [4] = { fPoints[0].y, fPoints[1].y, fPoints[3].y, fPoints[2].y }; // DF added to check for incorrect coordinates // makes sure that the right point is not to the left of the left point :-) // actually this should be checked at coordinates computation time // todo: check the object that computes the beam coordinates if (ax[0] > ax[2]) { ax[2] = ax[0]; } if (ax[1] > ax[3]) { ax[3] = ax[1]; } // This does the drawing! hdc.Polygon( ax, ay, 4 ); // - Cleanup if (colref) { hdc.PopPen(); hdc.PopFillColor(); } }
/** \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 }
/** \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; 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 (mColRef) { hdc.PopPen(); hdc.PopFillColor(); } }
void GRCluster::OnDraw(VGDevice &hdc) const { if (mDraw) { if (fNoteFormatColor) { VGColor color(fNoteFormatColor); hdc.PushPen(color, 1); if (!mColRef) hdc.PushFillColor(color); } if (mColRef) { VGColor color(mColRef); hdc.PushFillColor(color); hdc.PushPenColor(color); } // - Quarter notes and less if (fDuration < DURATION_2) { const float xCoords [] = { mMapping.left, mMapping.right, mMapping.right, mMapping.left}; const float yCoords [] = { mMapping.top, mMapping.top, mMapping.bottom, mMapping.bottom}; hdc.Polygon(xCoords, yCoords, 4); } else { const float xCoords1 [] = { mMapping.left, mMapping.right, mMapping.right, mMapping.left}; const float yCoords1 [] = { mMapping.top, mMapping.top, mMapping.top + 6 * mTagSize * fsize, mMapping.top + 6 * mTagSize * fsize}; const float xCoords2 [] = { mMapping.right - 6 * mTagSize * fsize, mMapping.right, mMapping.right, mMapping.right - 6 * mTagSize * fsize}; const float yCoords2 [] = { mMapping.top, mMapping.top, mMapping.bottom, mMapping.bottom}; const float xCoords3 [] = { mMapping.left, mMapping.right, mMapping.right, mMapping.left}; const float yCoords3 [] = { mMapping.bottom - 6 * mTagSize * fsize, mMapping.bottom - 6 * mTagSize * fsize, mMapping.bottom, mMapping.bottom}; const float xCoords4 [] = { mMapping.left, mMapping.left + 6 * mTagSize * fsize, mMapping.left + 6 * mTagSize * fsize, mMapping.left}; const float yCoords4 [] = { mMapping.top, mMapping.top, mMapping.bottom, mMapping.bottom}; hdc.Polygon(xCoords1, yCoords1, 4); hdc.Polygon(xCoords2, yCoords2, 4); hdc.Polygon(xCoords3, yCoords3, 4); hdc.Polygon(xCoords4, yCoords4, 4); } // - Restore context if (mColRef) { hdc.PopPenColor(); hdc.PopFillColor(); } if (fNoteFormatColor) { if (!mColRef) hdc.PopFillColor(); 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(); } }
// ---------------------------------------------------------------------------- // * DoDraw // ---------------------------------------------------------------------------- void GuidoCarbonControl::DoDraw() { const GRHandler guidoRef = GetGuidoGR(); if( guidoRef == 0 ) return; ControlRef theControl = GetControlRef(); if( theControl == 0 ) return; // - Get our local size int localWidth; int localHeight; GetSize( &localWidth, &localHeight ); CGRect deviceRect = ::CGRectMake( 0, 0, localWidth, localHeight ); // VGDevice * device = GetGDevice(); // <- was const int kScrollBarHeight = 15; // - Create the graphic context. It must be initialized with the actual size of the window, // otherwise the y-origin is not calculated properly. WindowRef winRef = ::GetControlOwner( theControl ); GrafPtr port = ::GetWindowPort( winRef ); CGContextRef contextRef = 0; OSStatus status = ::CreateCGContextForPort( port, &contextRef ); if( status != noErr ) return; GSystemOSX system(contextRef, NULL); VGDevice* device = system.CreateDisplayDevice(); device->NotifySize(localWidth, localHeight + kScrollBarHeight ); ::CGContextRelease(contextRef); // because the device now owns the context. // - Draw the background device->BeginDraw(); device->PushPen( VGColor( 0, 0, 0, ALPHA_OPAQUE ), 1 ); device->PushFillColor( VGColor( 255, 255, 255, ALPHA_TRANSPARENT )); device->Rectangle( 0, 0, localWidth, localHeight ); device->PopFillColor(); device->PopPen(); // - Setup the clipping rectangle, to avoid drawing on scrollbars. ::CGContextClipToRect( contextRef, deviceRect ); // - Draw the music score int virtualScrollX = (int)((float)mScrollX * 10 / GetZoom()); int virtualScrollY = (int)((float)mScrollY * 10 / GetZoom()); float virtualVisibleWidth = localWidth * 10 / GetZoom(); float virtualVisibleHeight = localHeight * 10 / GetZoom(); float fullScoreWidth; float fullScoreHeight; GetFullScoreSize( &fullScoreWidth, &fullScoreHeight ); GuidoOnDrawDesc desc; desc.handle = guidoRef; desc.hdc = device; desc.updateRegion.erase = false; desc.updateRegion.left = virtualScrollX; // absolute virtual coordinates clip rect desc.updateRegion.top = virtualScrollY; desc.updateRegion.right = (int)(virtualScrollX + virtualVisibleWidth); desc.updateRegion.bottom = (int)(virtualScrollY + virtualVisibleHeight); desc.scrollx = (int)virtualScrollX; desc.scrolly = (int)virtualScrollY; desc.page = GetPageNum(); desc.sizex = (int)fullScoreWidth; desc.sizey = (int)fullScoreHeight; MClock clock; GuidoOnDraw( &desc ); // debug #if 0 std::cout << "Score : sizex = " << desc.sizex << " ; sizey = " << desc.sizey << std::endl; std::cout << "Guido: time do draw the score: " << clock.Milliseconds() << " ms" << std::endl; // std::cout << "Guido: graphical objects: " << GuidoGRObjectCount() << std::endl; #endif if( GetParam( kDrawSymbolMap ) == 1 ) DrawSymbolMap(); // drawMap (guidoRef, device, GetPageNum()); device->EndDraw(); delete device; }
/** \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); }