示例#1
0
void ofxGuido::draw(int x, int y){
	GuidoPageFormat gpf;
	GuidoGetPageFormat(mGRHandler, 1, &gpf);
	ofLogNotice("ofxGuido") << gpf.width << "x" << gpf.height << " (" << gpf.margintop << ","
		<< gpf.marginbottom << "," << gpf.marginleft << "," << gpf.marginright << ")";
	float scaleX = mW / gpf.width;
	float scaleY = mH / gpf.height;
	int offsetX = 0, offsetY = 0;
	if(scaleX < scaleY){
		offsetY = (mH - (int)(gpf.height * scaleX)) / 2 - 1;
		ofLogNotice("ofxGuido") << "Scale: " << scaleX << " offsetY: " << offsetY;
	}
	else{
		offsetX = (mW - (int)(gpf.width * scaleY)) / 2 - 1;
		ofLogNotice("ofxGuido") << "Scale: " << scaleY << " offsetX: " << offsetX;
	}
	mGuidoOnDrawDesc.page = 1;
	mGuidoOnDrawDesc.scrollx = 0;
	mGuidoOnDrawDesc.scrolly = 0;
	mGuidoOnDrawDesc.updateRegion.erase = true;
	mGuidoOnDrawDesc.sizex = mW;
	mGuidoOnDrawDesc.sizey = mH;
	ofPushMatrix();
	ofPushStyle();
	ofFill();
	ofSetColor(mBackground);
	ofRect(x, y, mW, mH);
	ofTranslate(x + offsetX, y + offsetY);
	GuidoOnDraw(&mGuidoOnDrawDesc);
	ofPopStyle();
	ofPopMatrix();
}
示例#2
0
/** \brief Returns the whole size ("scrollable") of the music score, in pixels.

	It can be much bigger than the current visible portion of the score in the control.
*/
void		
GuidoCarbonControl::GetFullScoreSize( float * outWidth, float * outHeight ) const
{
	GuidoPageFormat format = { 100, 100, 10, 10, 10, 10 };
	GuidoGetPageFormat( GetGuidoGR(), GetPageNum(),  &format );
	
	*outWidth = format.width * GetZoom() * 0.1f;
	*outHeight = format.height * GetZoom() * 0.1f;
}
示例#3
0
//-------------------------------------------------------------------------
int QGuidoPainter::heightForWidth ( int w , int page ) const
{
	if ( !hasValidGR() )
		return w;
		
	GuidoPageFormat format;
	GuidoGetPageFormat( mDesc.handle , page , &format );
	float ratio = format.width / format.height;
	
	return int( w / ratio );
}
示例#4
0
//-------------------------------------------------------------------------
QSizeF QGuidoPainter::pageSizeMM(int page) const
{
	if ( !hasValidGR() )
		return QSizeF(0,0);

	GuidoPageFormat format;
	GuidoGetPageFormat( mDesc.handle , page , &format );
	float widthMM = GuidoUnit2CM( format.width ) * 10.0f;	
	float heightMM = GuidoUnit2CM( format.height ) * 10.0f;	
	
	return QSizeF( widthMM , heightMM );
}
示例#5
0
//-------------------------------------------------------------------------
void QGuidoPainter::draw( QPainter * painter , int page , const QRect& drawRectangle , const QRect& redrawRectangle)
{
	if ( !hasValidGR() )
		return;
	
	painter->save();
	painter->setClipRect( drawRectangle );
	painter->translate( drawRectangle.x() , drawRectangle.y() );
	
	//Creation of temporaries Qt implementations of VGSystem & VGDevice.
	VGSystem * sys = new GSystemQt( painter );
	VGDevice * dev = sys->CreateDisplayDevice();
	
	//Update the mDesc with the specified page and draw dimensions.
	mDesc.hdc = dev;
	page = MAX(1 , page);
	page = MIN(pageCount() , page);
	mDesc.page = page;	

	mDesc.sizex = drawRectangle.width();
	mDesc.sizey = drawRectangle.height();

	//mDesc.scrollx = -drawRectangle.x();
	//mDesc.scrolly = -drawRectangle.y();
	
	if ( redrawRectangle.isNull() )
	{
		//Redraw everything
		mDesc.updateRegion.erase = true;
	}
	else
	{
		//1. Computes the actual drawing rectangle 
		//(because the Guido Score won't strech and will keep its height/width ratio,
		//the drawing rectangle is different from the QPainter's QPaintDevice rectangle.).
		float ratio = heightForWidth(1000,page) / 1000.0f;
		//This ratio means that:  height = ratio * width.
		bool drawRectTooHigh = ( mDesc.sizey >= (mDesc.sizex * ratio) );
		int actualWidth, actualHeight;
		if ( drawRectTooHigh )
		{
			actualWidth = mDesc.sizex;
			actualHeight = actualWidth * ratio;
		}
		else
		{
			actualHeight = mDesc.sizey;
			actualWidth = actualHeight / ratio;
		}
		//2. Conversion of the redrawRectangle from QPaintDevice coordinate space to GuidoVirtualUnit.
		GuidoPageFormat format;
		GuidoGetPageFormat( mDesc.handle , page , &format );
		float widthConversionFactor = actualWidth / format.width;
		float heightConversionFactor = actualHeight / format.height;
		// pixel / conversionFactor = GuidoVirtualUnit
		mDesc.updateRegion.left = (redrawRectangle.x() - drawRectangle.x()) / widthConversionFactor;
		mDesc.updateRegion.top  = (redrawRectangle.y() - drawRectangle.y()) / heightConversionFactor;
		mDesc.updateRegion.right =  ( (redrawRectangle.x() - drawRectangle.x()) + redrawRectangle.width()  )  / widthConversionFactor;
		mDesc.updateRegion.bottom = ( (redrawRectangle.y() - drawRectangle.y()) + redrawRectangle.height() )  / heightConversionFactor;
		mDesc.updateRegion.erase	= false;
	}

//	QTime time;
//	time.start();

	//Actual draw of the Guido Score.
	VGColor color(fCurrentColor.red(), fCurrentColor.green(), fCurrentColor.blue(), fCurrentColor.alpha());
	dev->SelectPenColor (color);
	dev->SelectFillColor(color);
	dev->SetFontColor	(color);

#if absoluteTransform1 || absoluteTransform2
	// DF Apr. 28 2011
	// rescaling introduced to take account of the QTDevice::SetScale change
 	// the QTDevice::SetScale change corresponds to the common VGDevice demantic and implementation
	// actually commented out due to unresolved problems with rotations
	qreal xs, ys;
	QPainter * p = (QPainter*)dev->GetNativeContext();
	p->worldTransform().map(qreal(mDesc.sizex), qreal(mDesc.sizey), &xs, &ys);
	mDesc.sizex = xs;
	mDesc.sizey = ys;
#endif
	GuidoOnDraw (&mDesc);
	
//	qDebug("Score : width = %d , height = %d" , mDesc.sizex , mDesc.sizey );
//	qDebug("QGuidoPainter: Draw time : %d ms" , time.elapsed() );
	
	delete dev;
	delete sys;
	
	painter->restore();
}
示例#6
0
void ofxGuido::getPageFormat(GuidoPageFormat& format)
{
	GuidoGetPageFormat(guido->getGRHandler(), 1, &format);
}