// ---------------------------------------------------------------------------- // * 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; }
// -------------------------------------------------------------------------- void GRRepeatBegin::OnDraw(VGDevice & hdc ) const { if (!mDraw || fSize < kMinNoteSize) return; VGColor prevColor = hdc.GetFontColor(); if (mColRef) { hdc.PushFillColor(VGColor(mColRef)); hdc.SetFontColor(VGColor(mColRef)); } // - 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; float rightLineThickness = 1.8f * kLineThick * fSize; // - Horizontal adjustement according to staff's lines size and staff's size const float offsetX = 0.5f * (fStaffThickness - 4) - 30 * (fSize - 1) + (fSize - 1) * (fStaffThickness - 4) * 0.5f + 40; const float spacing = fBaseThickness + LSPACE * 0.4f * fSize - rightLineThickness; const float x1 = mPosition.x - mBoundingBox.Width() + offsetX; const float x2 = x1 + spacing; const float y1 = mPosition.y + offsety1 * fSize; const float y2 = y1 + (mBoundingBox.bottom + offsety2) * fSize; hdc.Rectangle(x1, y1, x1 + fBaseThickness, y2); hdc.Rectangle(x2, y1, x2 + rightLineThickness, y2); /* Two points drawing */ float offsety1AccordingToLineNumber = 0; float offsety2AccordingToLineNumber = 0; if (fLineNumber == 0) offsety1AccordingToLineNumber = - LSPACE / 2 * fSize; else if (fLineNumber == 1) offsety1AccordingToLineNumber = - LSPACE * fSize; else if (fLineNumber == 2) { offsety1AccordingToLineNumber = 14 * fSize; offsety2AccordingToLineNumber = - 2 * offsety1AccordingToLineNumber; } int pointSymbol = 220; float pointOffsety1 = - 5 * fSize + offsety1AccordingToLineNumber; float pointOffsety2 = pointOffsety1 + LSPACE * fSize + offsety2AccordingToLineNumber; float pointOffsetx = 28 * (fSize - 1) + 0.5f * (fStaffThickness - 4) + (fSize - 1) * (fStaffThickness - 4) * 0.5f + 8; float pointSize = 0.4f * fSize; DrawSymbol(hdc, pointSymbol, pointOffsetx, pointOffsety1, pointSize); DrawSymbol(hdc, pointSymbol, pointOffsetx, pointOffsety2, pointSize); /**********************/ if (mColRef) { hdc.SetFontColor(prevColor); 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); }