graphicscontext.cpp

来自「这是VCF框架的代码」· C++ 代码 · 共 1,799 行 · 第 1/4 页

CPP
1,799
字号
	pathOperations_.push_back( PointOperation(x2,y2,PointOperation::ptEllipse) );}void GraphicsContext::arc( const double& centerX,  const double& centerY,				const double& radiusWidth, const double& radiusHeight,				const double& startAngle, const double& endAngle){	checkPathOperations();	currentDrawingState_ = GraphicsContext::gsAddingGraphicsOps;	pathOperations_.push_back( PointOperation(centerX,centerY,PointOperation::ptArc) );	pathOperations_.push_back( PointOperation(radiusHeight,radiusHeight,PointOperation::ptArc) );	pathOperations_.push_back( PointOperation(startAngle,endAngle,PointOperation::ptArc) );}void GraphicsContext::pie(const double & x1, const double & y1, const double & x2, const double & y2,                          const double & x3, const double & y3, const double & x4, const double & y4){	checkPathOperations();	currentDrawingState_ = GraphicsContext::gsAddingGraphicsOps;	//contextPeer_->pie( x1, y1, x2, y2, x3, y3, x4, y4 );}void GraphicsContext::chord(const double & x1, const double & y1, const double & x2, const double & y2,                            const double & x3, const double & y3, const double & x4, const double & y4){	checkPathOperations();	currentDrawingState_ = GraphicsContext::gsAddingGraphicsOps;	//contextPeer_->chord( x1, y1, x2, y2, x3, y3, x4, y4 );}void GraphicsContext::polyline( const std::vector<Point>& pts ){	checkPathOperations();	currentDrawingState_ = GraphicsContext::gsAddingGraphicsOps;	std::vector<Point>::const_iterator it = pts.begin();	while ( it != pts.end() ) {		const Point& pt = *it;		pathOperations_.push_back( PointOperation(pt.x_, pt.y_, PointOperation::ptPolyLine) );		++it;	}}void GraphicsContext::curve(const double & x1, const double & y1, const double & x2, const double & y2,                            const double & x3, const double & y3, const double & x4, const double & y4){	checkPathOperations();	currentDrawingState_ = GraphicsContext::gsAddingGraphicsOps;	pathOperations_.push_back( PointOperation(x1,y1,PointOperation::ptBezier) );	pathOperations_.push_back( PointOperation(x2,y2,PointOperation::ptBezier) );	pathOperations_.push_back( PointOperation(x3,y3,PointOperation::ptBezier) );	pathOperations_.push_back( PointOperation(x4,y4,PointOperation::ptBezier) );}void GraphicsContext::lineTo(const double & x, const double & y){	checkPathOperations();	currentDrawingState_ = GraphicsContext::gsAddingGraphicsOps;	pathOperations_.push_back( PointOperation(x,y,PointOperation::ptLineTo) );}void GraphicsContext::moveTo(const double & x, const double & y){	checkPathOperations();	currentDrawingState_ = GraphicsContext::gsAddingGraphicsOps;	pathOperations_.push_back( PointOperation(x,y,PointOperation::ptMoveTo) );}void GraphicsContext::fillPath(){	if ( contextPeer_->prepareForDrawing( GraphicsContext::doFill ) ) {		execPathOperations();		contextPeer_->finishedDrawing( 	GraphicsContext::doFill );	}}void GraphicsContext::strokePath(){	if ( contextPeer_->prepareForDrawing( GraphicsContext::doStroke ) ) {		execPathOperations();		contextPeer_->finishedDrawing( 	GraphicsContext::doStroke );	}}ContextPeer* GraphicsContext::getPeer(){	return contextPeer_;}void GraphicsContext::setOrigin( const double& x, const double& y ){	contextPeer_->setOrigin( x, y );}Point GraphicsContext::getOrigin(){	return contextPeer_->getOrigin();}void GraphicsContext::copyContext( const Rect& sourceRect,						const Rect& destRect,						GraphicsContext* context ){	contextPeer_->copyContext( sourceRect, destRect, context->getPeer() );}void GraphicsContext::setCurrentTransform( const Matrix2D& transform ){	currentGraphicsState_->transformMatrix_ = transform;}Matrix2D* GraphicsContext::getCurrentTransform(){	return &currentGraphicsState_->transformMatrix_;}void GraphicsContext::setRotation( const double& theta ){	currentGraphicsState_->rotation_  = theta;	currentGraphicsState_->compositeMatrix();}void GraphicsContext::setTranslation( const double transX, const double& transY ){	currentGraphicsState_->translateX_  = transX;	currentGraphicsState_->translateY_  = transY;	currentGraphicsState_->compositeMatrix();}void GraphicsContext::setShear( const double& shearX, const double& shearY ){	currentGraphicsState_->shearX_  = shearX;	currentGraphicsState_->shearY_  = shearY;	currentGraphicsState_->compositeMatrix();}void GraphicsContext::setScale( const double& scaleX, const double& scaleY ){	currentGraphicsState_->scaleX_  = scaleX;	currentGraphicsState_->scaleY_  = scaleY;	currentGraphicsState_->compositeMatrix();}void GraphicsContext::concatRotation( const double& theta ){	currentGraphicsState_->rotation_  += theta;	Matrix2D rot;	rot.rotate( currentGraphicsState_->rotation_ );	Matrix2D tmp;	tmp.multiply( &rot, &currentGraphicsState_->transformMatrix_ );	currentGraphicsState_->transformMatrix_ = tmp;}void GraphicsContext::concatTranslation( const double transX, const double& transY ){	currentGraphicsState_->translateX_  += transX;	currentGraphicsState_->translateY_  += transY;	Matrix2D translation;	translation.translate( currentGraphicsState_->translateX_, currentGraphicsState_->translateY_);	Matrix2D tmp;	tmp.multiply( &translation, &currentGraphicsState_->transformMatrix_ );	currentGraphicsState_->transformMatrix_ = tmp;}void GraphicsContext::concatShear( const double& shearX, const double& shearY ){	currentGraphicsState_->shearX_  += shearX;	currentGraphicsState_->shearY_  += shearY;	Matrix2D shear;	shear.shear( currentGraphicsState_->shearX_, currentGraphicsState_->shearY_ );	Matrix2D tmp;	tmp.multiply( &shear, &currentGraphicsState_->transformMatrix_ );	currentGraphicsState_->transformMatrix_ = tmp;}void GraphicsContext::concatScale( const double& scaleX, const double& scaleY ){	currentGraphicsState_->scaleX_  += scaleX;	currentGraphicsState_->scaleY_  += scaleY;	Matrix2D scale;	scale.scale( currentGraphicsState_->scaleX_, currentGraphicsState_->scaleY_ );	Matrix2D tmp;	tmp.multiply( &scale, &currentGraphicsState_->transformMatrix_ );	currentGraphicsState_->transformMatrix_ = tmp;}Font* GraphicsContext::getCurrentFont(){	return &currentGraphicsState_->font_;}void GraphicsContext::setColor( Color* color ){	if ( NULL != color ) {		currentGraphicsState_->color_ = *color;	}}void GraphicsContext::setColor( const Color* color ){	if ( NULL != color ) {		currentGraphicsState_->color_ = *color;	}}Color* GraphicsContext::getColor(){	return &currentGraphicsState_->color_;}void GraphicsContext::textBoundedBy( Rect* bounds, const String& text, const bool& wordWrap ){	long drawOptions = wordWrap ? GraphicsContext::tdoWordWrap : GraphicsContext::tdoNone;	Rect tmp = *bounds;	double xx = tmp.left_ * (currentGraphicsState_->transformMatrix_[Matrix2D::mei00]) +							tmp.top_ * (currentGraphicsState_->transformMatrix_[Matrix2D::mei10]) +								(currentGraphicsState_->transformMatrix_[Matrix2D::mei20]);	double yy = tmp.left_ * (currentGraphicsState_->transformMatrix_[Matrix2D::mei01]) +							tmp.top_ * (currentGraphicsState_->transformMatrix_[Matrix2D::mei11]) +								(currentGraphicsState_->transformMatrix_[Matrix2D::mei21]);	tmp.offset( xx - tmp.left_, yy - tmp.top_ );	if ( contextPeer_->prepareForDrawing( GraphicsContext::doText ) ) {		contextPeer_->textAt( tmp, text, drawOptions );		contextPeer_->finishedDrawing( 	GraphicsContext::doText );	}}void GraphicsContext::textBoundedBy( Rect* bounds, const String& text, const long drawOptions ){	Rect tmp = *bounds;	double xx = tmp.left_ * (currentGraphicsState_->transformMatrix_[Matrix2D::mei00]) +							tmp.top_ * (currentGraphicsState_->transformMatrix_[Matrix2D::mei10]) +								(currentGraphicsState_->transformMatrix_[Matrix2D::mei20]);	double yy = tmp.left_ * (currentGraphicsState_->transformMatrix_[Matrix2D::mei01]) +							tmp.top_ * (currentGraphicsState_->transformMatrix_[Matrix2D::mei11]) +								(currentGraphicsState_->transformMatrix_[Matrix2D::mei21]);	tmp.offset( xx - tmp.left_, yy - tmp.top_ );	if ( contextPeer_->prepareForDrawing( GraphicsContext::doText ) ) {		contextPeer_->textAt( tmp, text, drawOptions );		contextPeer_->finishedDrawing( 	GraphicsContext::doText );	}}bool GraphicsContext::isXORModeOn(){	return contextPeer_->isXORModeOn();}void GraphicsContext::setXORModeOn( const bool& XORModeOn ){	contextPeer_->setXORModeOn( XORModeOn );}double GraphicsContext::getTextWidth( const String& text ){	return contextPeer_->getTextWidth( text );}double GraphicsContext::getTextHeight( const String& text ){	return contextPeer_->getTextHeight( text );}void GraphicsContext::setClippingRect( Rect* rect ){	BezierCurve* rectClipPath = NULL;	if ( NULL != rect ) {		rectClipPath = new BezierCurve();		rectClipPath->moveTo( rect->left_, rect->top_ );		rectClipPath->lineTo( rect->right_, rect->top_ );		rectClipPath->lineTo( rect->right_, rect->bottom_ );		rectClipPath->lineTo( rect->left_, rect->bottom_ );		rectClipPath->close();	}	Path* clipPath = currentGraphicsState_->clippingPath_;	if ( NULL != clipPath ) { //release the underlying object instance		Object* pathObj = dynamic_cast<Object*>( clipPath );		pathObj->release();	}	clipPath = rectClipPath;	if ( NULL != clipPath ) { //take ownership of the underlying object instance		Object* pathObj = dynamic_cast<Object*>( clipPath );		pathObj->addRef();	}	currentGraphicsState_->clippingPath_ = clipPath;	contextPeer_->setClippingRect( rect );}void GraphicsContext::setClippingPath( Path* clippingPath ){	Path* clipPath = currentGraphicsState_->clippingPath_;	if ( NULL != clipPath ) { //release the underlying object instance		Object* pathObj = dynamic_cast<Object*>( clipPath );		pathObj->release();	}	clipPath = clippingPath;	if ( NULL != clipPath ) { //take ownership of the underlying object instance		Object* pathObj = dynamic_cast<Object*>( clipPath );		pathObj->addRef();	}	currentGraphicsState_->clippingPath_ = clipPath;	contextPeer_->setClippingPath( clipPath );}Rect GraphicsContext::getClippingRect(){	Rect result;	Path* clipPath = currentGraphicsState_->clippingPath_;	if ( NULL != clipPath ) {		result = clipPath->getBounds();	}	return result;}Path* GraphicsContext::getClippingPath(){	return currentGraphicsState_->clippingPath_;}void GraphicsContext::drawThemeSelectionRect( Rect* rect, DrawUIState& state ){	contextPeer_->drawThemeSelectionRect( rect, state );}void GraphicsContext::drawThemeFocusRect( Rect* rect, DrawUIState& state ){	contextPeer_->drawThemeFocusRect( rect, state );}void GraphicsContext::drawThemeButtonRect( Rect* rect, ButtonState& state, Rect* captionRect ){	contextPeer_->drawThemeButtonRect( rect, state, captionRect );}void GraphicsContext::drawThemeButtonFocusRect( Rect* rect ){	contextPeer_->drawThemeButtonFocusRect( rect );}void GraphicsContext::drawThemeCheckboxRect( Rect* rect, ButtonState& state ){	contextPeer_->drawThemeCheckboxRect( rect, state );}void GraphicsContext::drawThemeRadioButtonRect( Rect* rect, ButtonState& state ){	contextPeer_->drawThemeRadioButtonRect( rect, state );}void GraphicsContext::drawThemeComboboxRect( Rect* rect, ButtonState& state ){	contextPeer_->drawThemeComboboxRect( rect, state );}void GraphicsContext::drawThemeScrollButtonRect( Rect* rect, ScrollBarState& state ){	contextPeer_->drawThemeScrollButtonRect( rect, state );}void GraphicsContext::drawThemeDisclosureButton( Rect* rect, DisclosureButtonState& state ){	contextPeer_->drawThemeDisclosureButton( rect, state );}void GraphicsContext::drawThemeTab( Rect* rect, TabState& state ){	contextPeer_->drawThemeTab( rect, state );}void GraphicsContext::drawThemeTabPage( Rect* rect, DrawUIState& state ){	contextPeer_->drawThemeTabPage( rect, state );}void GraphicsContext::drawThemeTabContent( Rect* rect, DrawUIState& state ){	contextPeer_->drawThemeTabContent( rect, state );}void GraphicsContext::drawThemeTabs( Rect* rect, DrawUIState& paneState, TabState& selectedTabState, TabState& otherTabs, const std::vector<String>& tabNames, int selectedTabIndex ){	contextPeer_->drawThemeTabs( rect, paneState, selectedTabState, otherTabs, tabNames, selectedTabIndex );}void GraphicsContext::drawThemeTickMarks( Rect* rect, SliderState& state ){	contextPeer_->drawThemeTickMarks( rect, state );}void GraphicsContext::drawThemeSlider( Rect* rect, SliderState& state ){	contextPeer_->drawThemeSlider( rect, state );}void GraphicsContext::drawThemeProgress( Rect* rect, ProgressState& state ){	contextPeer_->drawThemeProgress( rect, state );}void GraphicsContext::drawThemeImage( Rect* rect, Image* image, DrawUIState& state ){	contextPeer_->drawThemeImage( rect, image, state );}void GraphicsContext::drawThemeHeader( Rect* rect, ButtonState& state ){

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?