GameOver::GameOver(MainWindow* parent) { parent_ = parent; scene_ = new QGraphicsScene(); setScene(scene_); QBrush silverBrush(QColor(227,228,229)); gameOverText = new QGraphicsSimpleTextItem("GAME OVER"); QFont myFont("Helvetica [Cronyx]",70,QFont::Bold); gameOverText->setFont(myFont); gameOverText->setBrush(silverBrush); scene_->addItem(gameOverText); gameOverText->setPos(300,170); QBrush blackBrush(QColor(0,0,0)); clickText = new QGraphicsSimpleTextItem("Click File->New Game to play again!"); QFont bFont("Helvetica [Cronyx]",30,QFont::Bold); clickText->setFont(bFont); clickText->setBrush(blackBrush); scene_->addItem(clickText); clickText->setPos(250,300); counter = 0; timer_ = new QTimer(this); timer_->setInterval(1000); connect(timer_,SIGNAL(timeout()),this,SLOT(handleTimer())); timer_->start(); }
void ClsDiagItem::doFont(){ string strFontName = iqrfe::ClsFESettings::instance().getBlockDiagramFontName(); int iFontSize = iqrfe::ClsFESettings::instance().getBlockDiagramFontSize(); QFont myFont(strFontName.c_str(), iFontSize, QFont::Normal); qgtiLabel->setFont(myFont); }
void k9MenuEdit::bFontClick() { if (m_menuEditor->getSelected()) { k9MenuButton *b=m_menuEditor->getSelected(); QFont myFont(b->getFont()); int result = KFontDialog::getFont( myFont ); if ( result == KFontDialog::Accepted && m_menuEditor->getSelected() ) { QPtrList <k9MenuButton> *l=m_menuEditor->getSelection(); for (b=l->first();b;b=l->next()) { b->setFont(myFont); } } } else { if (m_text) { QFont myFont(m_text->font()); int result = KFontDialog::getFont( myFont ); if ( result == KFontDialog::Accepted ) setFont(myFont); } } }
void QgsDecorationScaleBar::render( QPainter * theQPainter ) { QgsMapCanvas* canvas = QgisApp::instance()->mapCanvas(); int myBufferSize = 1; //softcode this later //Get canvas dimensions int myCanvasHeight = theQPainter->device()->height(); int myCanvasWidth = theQPainter->device()->width(); //Get map units per pixel. This can be negative at times (to do with //projections) and that just confuses the rest of the code in this //function, so force to a positive number. double myMapUnitsPerPixelDouble = qAbs( canvas->mapUnitsPerPixel() ); double myActualSize = mPreferredSize; // Exit if the canvas width is 0 or layercount is 0 or QGIS will freeze int myLayerCount = canvas->layerCount(); if ( !myLayerCount || !myCanvasWidth || !myMapUnitsPerPixelDouble ) return; //Large if statement which determines whether to render the scale bar if ( enabled() ) { // Hard coded sizes int myMajorTickSize = 8; int myTextOffsetX = 3; int myMargin = 20; QSettings settings; QGis::UnitType myPreferredUnits = QGis::fromLiteral( settings.value( "/qgis/measure/displayunits", QGis::toLiteral( QGis::Meters ) ).toString() ); QGis::UnitType myMapUnits = canvas->mapUnits(); // Adjust units meter/feet/... or vice versa myMapUnitsPerPixelDouble *= QGis::fromUnitToUnitFactor( myMapUnits, myPreferredUnits ); myMapUnits = myPreferredUnits; //Calculate size of scale bar for preferred number of map units double myScaleBarWidth = mPreferredSize / myMapUnitsPerPixelDouble; //If scale bar is very small reset to 1/4 of the canvas wide if ( myScaleBarWidth < 30 ) { myScaleBarWidth = myCanvasWidth / 4; // pixels myActualSize = myScaleBarWidth * myMapUnitsPerPixelDouble; // map units }; //if scale bar is more than half the canvas wide keep halving until not while ( myScaleBarWidth > myCanvasWidth / 3 ) { myScaleBarWidth = myScaleBarWidth / 3; }; myActualSize = myScaleBarWidth * myMapUnitsPerPixelDouble; // Work out the exponent for the number - e.g, 1234 will give 3, // and .001234 will give -3 double myPowerOf10 = floor( log10( myActualSize ) ); // snap to integer < 10 times power of 10 if ( mSnapping ) { double scaler = pow( 10.0, myPowerOf10 ); myActualSize = qRound( myActualSize / scaler ) * scaler; myScaleBarWidth = myActualSize / myMapUnitsPerPixelDouble; } //Get type of map units and set scale bar unit label text QString myScaleBarUnitLabel; switch ( myMapUnits ) { case QGis::Meters: if ( myActualSize > 1000.0 ) { myScaleBarUnitLabel = tr( " km" ); myActualSize = myActualSize / 1000; } else if ( myActualSize < 0.01 ) { myScaleBarUnitLabel = tr( " mm" ); myActualSize = myActualSize * 1000; } else if ( myActualSize < 0.1 ) { myScaleBarUnitLabel = tr( " cm" ); myActualSize = myActualSize * 100; } else myScaleBarUnitLabel = tr( " m" ); break; case QGis::Feet: if ( myActualSize > 5280.0 ) //5280 feet to the mile { myScaleBarUnitLabel = tr( " miles" ); // Adjust scale bar width to get even numbers myActualSize = myActualSize / 5000; myScaleBarWidth = ( myScaleBarWidth * 5280 ) / 5000; } else if ( myActualSize == 5280.0 ) //5280 feet to the mile { myScaleBarUnitLabel = tr( " mile" ); // Adjust scale bar width to get even numbers myActualSize = myActualSize / 5000; myScaleBarWidth = ( myScaleBarWidth * 5280 ) / 5000; } else if ( myActualSize < 1 ) { myScaleBarUnitLabel = tr( " inches" ); myActualSize = myActualSize * 10; myScaleBarWidth = ( myScaleBarWidth * 10 ) / 12; } else if ( myActualSize == 1.0 ) { myScaleBarUnitLabel = tr( " foot" ); } else { myScaleBarUnitLabel = tr( " feet" ); } break; case QGis::Degrees: if ( myActualSize == 1.0 ) myScaleBarUnitLabel = tr( " degree" ); else myScaleBarUnitLabel = tr( " degrees" ); break; case QGis::UnknownUnit: myScaleBarUnitLabel = tr( " unknown" ); default: QgsDebugMsg( QString( "Error: not picked up map units - actual value = %1" ).arg( myMapUnits ) ); }; //Set font and calculate width of unit label int myFontSize = 10; //we use this later for buffering QFont myFont( "helvetica", myFontSize ); theQPainter->setFont( myFont ); QFontMetrics myFontMetrics( myFont ); double myFontWidth = myFontMetrics.width( myScaleBarUnitLabel ); double myFontHeight = myFontMetrics.height(); //Set the maximum label QString myScaleBarMaxLabel = QLocale::system().toString( myActualSize ); //Calculate total width of scale bar and label double myTotalScaleBarWidth = myScaleBarWidth + myFontWidth; //determine the origin of scale bar depending on placement selected int myOriginX = myMargin; int myOriginY = myMargin; switch ( mPlacementIndex ) { case 0: // Bottom Left myOriginX = myMargin; myOriginY = myCanvasHeight - myMargin; break; case 1: // Top Left myOriginX = myMargin; myOriginY = myMargin; break; case 2: // Top Right myOriginX = myCanvasWidth - (( int ) myTotalScaleBarWidth ) - myMargin; myOriginY = myMargin; break; case 3: // Bottom Right myOriginX = myCanvasWidth - (( int ) myTotalScaleBarWidth ) - myMargin; myOriginY = myCanvasHeight - myMargin; break; default: QgsDebugMsg( "Unable to determine where to put scale bar so defaulting to top left" ); } //Set pen to draw with QPen myForegroundPen( mColor, 2 ); QPen myBackgroundPen( Qt::white, 4 ); //Cast myScaleBarWidth to int for drawing int myScaleBarWidthInt = ( int ) myScaleBarWidth; //Create array of vertices for scale bar depending on style switch ( mStyleIndex ) { case 0: // Tick Down { QPolygon myTickDownArray( 4 ); //draw a buffer first so bar shows up on dark images theQPainter->setPen( myBackgroundPen ); myTickDownArray.putPoints( 0, 4, myOriginX , ( myOriginY + myMajorTickSize ) , myOriginX , myOriginY , ( myScaleBarWidthInt + myOriginX ), myOriginY , ( myScaleBarWidthInt + myOriginX ), ( myOriginY + myMajorTickSize ) ); theQPainter->drawPolyline( myTickDownArray ); //now draw the bar itself in user selected color theQPainter->setPen( myForegroundPen ); myTickDownArray.putPoints( 0, 4, myOriginX , ( myOriginY + myMajorTickSize ) , myOriginX , myOriginY , ( myScaleBarWidthInt + myOriginX ), myOriginY , ( myScaleBarWidthInt + myOriginX ), ( myOriginY + myMajorTickSize ) ); theQPainter->drawPolyline( myTickDownArray ); break; } case 1: // tick up { QPolygon myTickUpArray( 4 ); //draw a buffer first so bar shows up on dark images theQPainter->setPen( myBackgroundPen ); myTickUpArray.putPoints( 0, 4, myOriginX , myOriginY , myOriginX , myOriginY + myMajorTickSize , ( myScaleBarWidthInt + myOriginX ), myOriginY + myMajorTickSize , ( myScaleBarWidthInt + myOriginX ), myOriginY ); theQPainter->drawPolyline( myTickUpArray ); //now draw the bar itself in user selected color theQPainter->setPen( myForegroundPen ); myTickUpArray.putPoints( 0, 4, myOriginX , myOriginY , myOriginX , myOriginY + myMajorTickSize , ( myScaleBarWidthInt + myOriginX ), myOriginY + myMajorTickSize , ( myScaleBarWidthInt + myOriginX ), myOriginY ); theQPainter->drawPolyline( myTickUpArray ); break; } case 2: // Bar { QPolygon myBarArray( 2 ); //draw a buffer first so bar shows up on dark images theQPainter->setPen( myBackgroundPen ); myBarArray.putPoints( 0, 2, myOriginX , ( myOriginY + ( myMajorTickSize / 2 ) ), ( myScaleBarWidthInt + myOriginX ), ( myOriginY + ( myMajorTickSize / 2 ) ) ); theQPainter->drawPolyline( myBarArray ); //now draw the bar itself in user selected color theQPainter->setPen( myForegroundPen ); myBarArray.putPoints( 0, 2, myOriginX , ( myOriginY + ( myMajorTickSize / 2 ) ), ( myScaleBarWidthInt + myOriginX ), ( myOriginY + ( myMajorTickSize / 2 ) ) ); theQPainter->drawPolyline( myBarArray ); break; } case 3: // box { // Want square corners for a box myBackgroundPen.setJoinStyle( Qt::MiterJoin ); myForegroundPen.setJoinStyle( Qt::MiterJoin ); QPolygon myBoxArray( 5 ); //draw a buffer first so bar shows up on dark images theQPainter->setPen( myBackgroundPen ); myBoxArray.putPoints( 0, 5, myOriginX , myOriginY, ( myScaleBarWidthInt + myOriginX ), myOriginY, ( myScaleBarWidthInt + myOriginX ), ( myOriginY + myMajorTickSize ), myOriginX , ( myOriginY + myMajorTickSize ), myOriginX , myOriginY ); theQPainter->drawPolyline( myBoxArray ); //now draw the bar itself in user selected color theQPainter->setPen( myForegroundPen ); theQPainter->setBrush( QBrush( mColor, Qt::SolidPattern ) ); int midPointX = myScaleBarWidthInt / 2 + myOriginX; myBoxArray.putPoints( 0, 5, myOriginX , myOriginY, midPointX, myOriginY, midPointX, ( myOriginY + myMajorTickSize ), myOriginX , ( myOriginY + myMajorTickSize ), myOriginX , myOriginY ); theQPainter->drawPolygon( myBoxArray ); theQPainter->setBrush( Qt::NoBrush ); myBoxArray.putPoints( 0, 5, midPointX , myOriginY, ( myScaleBarWidthInt + myOriginX ), myOriginY, ( myScaleBarWidthInt + myOriginX ), ( myOriginY + myMajorTickSize ), midPointX , ( myOriginY + myMajorTickSize ), midPointX , myOriginY ); theQPainter->drawPolygon( myBoxArray ); break; } default: QgsDebugMsg( "Unknown style" ); } //Do actual drawing of scale bar // //Do drawing of scale bar text // QColor myBackColor = Qt::white; QColor myForeColor = Qt::black; //Draw the minimum label buffer theQPainter->setPen( myBackColor ); myFontWidth = myFontMetrics.width( "0" ); myFontHeight = myFontMetrics.height(); for ( int i = 0 - myBufferSize; i <= myBufferSize; i++ ) { for ( int j = 0 - myBufferSize; j <= myBufferSize; j++ ) { theQPainter->drawText( int( i + ( myOriginX - ( myFontWidth / 2 ) ) ), int( j + ( myOriginY - ( myFontHeight / 4 ) ) ), "0" ); } } //Draw minimum label theQPainter->setPen( myForeColor ); theQPainter->drawText( int( myOriginX - ( myFontWidth / 2 ) ), int( myOriginY - ( myFontHeight / 4 ) ), "0" ); // //Draw maximum label // theQPainter->setPen( myBackColor ); myFontWidth = myFontMetrics.width( myScaleBarMaxLabel ); myFontHeight = myFontMetrics.height(); //first the buffer for ( int i = 0 - myBufferSize; i <= myBufferSize; i++ ) { for ( int j = 0 - myBufferSize; j <= myBufferSize; j++ ) { theQPainter->drawText( int( i + ( myOriginX + myScaleBarWidthInt - ( myFontWidth / 2 ) ) ), int( j + ( myOriginY - ( myFontHeight / 4 ) ) ), myScaleBarMaxLabel ); } } //then the text itself theQPainter->setPen( myForeColor ); theQPainter->drawText( int( myOriginX + myScaleBarWidthInt - ( myFontWidth / 2 ) ), int( myOriginY - ( myFontHeight / 4 ) ), myScaleBarMaxLabel ); // //Draw unit label // theQPainter->setPen( myBackColor ); //first the buffer for ( int i = 0 - myBufferSize; i <= myBufferSize; i++ ) { for ( int j = 0 - myBufferSize; j <= myBufferSize; j++ ) { theQPainter->drawText( i + ( myOriginX + myScaleBarWidthInt + myTextOffsetX ), j + ( myOriginY + myMajorTickSize ), myScaleBarUnitLabel ); } } //then the text itself theQPainter->setPen( myForeColor ); theQPainter->drawText( ( myOriginX + myScaleBarWidthInt + myTextOffsetX ), ( myOriginY + myMajorTickSize ), myScaleBarUnitLabel ); } }
void QgsQuickPrint::renderPrintScaleBar( QPainter * thepPainter, QgsMapRenderer * thepMapRenderer, int theMaximumWidth ) { //hard coding some options for now bool mySnappingFlag = true; QColor mColor = Qt::black; // Hard coded sizes int myTextOffsetX = 0; int myTextOffsetY = 5; int myXMargin = 20; int myYMargin = 20; int myPreferredSize = theMaximumWidth - ( myXMargin * 2 ); double myActualSize = 0; int myBufferSize = 1; //softcode this later QColor myBackColor = Qt::white; //used for text QColor myForeColor = Qt::black; //used for text //Get canvas dimensions //int myCanvasHeight = thepMapCanvas->height(); //Get map units per pixel. This can be negative at times (to do with //projections) and that just confuses the rest of the code in this //function, so force to a positive number. double myMapUnitsPerPixelDouble = qAbs( thepMapRenderer->mapUnitsPerPixel() ); // // Exit if the canvas width is 0 or layercount is 0 or QGIS will freeze int myLayerCount = thepMapRenderer->layerSet().count(); if ( !myLayerCount || !myMapUnitsPerPixelDouble ) return; //Calculate size of scale bar for preferred number of map units double myScaleBarWidth = myPreferredSize; myActualSize = myScaleBarWidth * myMapUnitsPerPixelDouble; // Work out the exponent for the number - e.g, 1234 will give 3, // and .001234 will give -3 double myPowerOf10 = floor( log10( myActualSize ) ); // snap to integer < 10 times power of 10 if ( mySnappingFlag ) { double scaler = pow( 10.0, myPowerOf10 ); myActualSize = round( myActualSize / scaler ) * scaler; myScaleBarWidth = myActualSize / myMapUnitsPerPixelDouble; } //Get type of map units and set scale bar unit label text QGis::UnitType myMapUnits = thepMapRenderer->mapUnits(); QString myScaleBarUnitLabel; switch ( myMapUnits ) { case QGis::Meters: if ( myActualSize > 1000.0 ) { myScaleBarUnitLabel = tr( " km" ); myActualSize = myActualSize / 1000; } else if ( myActualSize < 0.01 ) { myScaleBarUnitLabel = tr( " mm" ); myActualSize = myActualSize * 1000; } else if ( myActualSize < 0.1 ) { myScaleBarUnitLabel = tr( " cm" ); myActualSize = myActualSize * 100; } else myScaleBarUnitLabel = tr( " m" ); break; case QGis::Feet: if ( myActualSize > 5280.0 ) //5280 feet to the mile { myScaleBarUnitLabel = tr( " miles" ); myActualSize = myActualSize / 5280; } else if ( myActualSize == 5280.0 ) //5280 feet to the mile { myScaleBarUnitLabel = tr( " mile" ); myActualSize = myActualSize / 5280; } else if ( myActualSize < 1 ) { myScaleBarUnitLabel = tr( " inches" ); myActualSize = myActualSize * 12; } else if ( myActualSize == 1.0 ) { myScaleBarUnitLabel = tr( " foot" ); } else { myScaleBarUnitLabel = tr( " feet" ); } break; case QGis::Degrees: if ( myActualSize == 1.0 ) myScaleBarUnitLabel = tr( " degree" ); else myScaleBarUnitLabel = tr( " degrees" ); break; case QGis::UnknownUnit: myScaleBarUnitLabel = tr( " unknown" ); default: QgsDebugMsg( "Error: not picked up map units - actual value = " + QString::number( myMapUnits ) ); }; //Set font and calculate width of unit label int myFontSize = 10; //we use this later for buffering QFont myFont( "helvetica", myFontSize ); thepPainter->setFont( myFont ); QFontMetrics myFontMetrics( myFont ); double myFontWidth = myFontMetrics.width( myScaleBarUnitLabel ); double myFontHeight = myFontMetrics.height(); //Set the maximum label QString myScaleBarMaxLabel = QString::number( myActualSize ); //Calculate total width of scale bar and label //we divide by 2 because the max scale label //will be centered over the endpoint of the scale bar double myTotalScaleBarWidth = myScaleBarWidth + ( myFontWidth / 2 ); //determine the origin of scale bar (bottom right) //for x origin set things up so the scalebar is centered int myOriginX = ( theMaximumWidth - myTotalScaleBarWidth ) / 2; int myOriginY = myYMargin; //Set pen to draw with QPen myForegroundPen( mColor, 2 ); QPen myBackgroundPen( Qt::white, 3 ); //Cast myScaleBarWidth to int for drawing int myScaleBarWidthInt = ( int ) myScaleBarWidth; //now draw the bar itself in user selected color thepPainter->setPen( myForegroundPen ); //make a glossygradient for the background QGradientStops myStops; myStops << QGradientStop( 0.0, QColor( "#616161" ) ); myStops << QGradientStop( 0.5, QColor( "#505050" ) ); myStops << QGradientStop( 0.6, QColor( "#434343" ) ); myStops << QGradientStop( 1.0, QColor( "#656565" ) ); //draw again with the brush in the revers direction to complete teh glossiness QLinearGradient myReverseGlossyBrush( QPointF( myOriginX, myOriginY + myFontHeight*3 ), QPointF( myOriginX, myOriginY ) ); thepPainter->setBrush( myReverseGlossyBrush ); thepPainter->drawRect( myOriginX, myOriginY, myOriginX + myScaleBarWidthInt, myOriginY + myFontHeight ); // //Do drawing of scale bar text // //Draw the minimum label buffer thepPainter->setPen( myBackColor ); myFontWidth = myFontMetrics.width( "0" ); for ( int i = 0 - myBufferSize; i <= myBufferSize; i++ ) { for ( int j = 0 - myBufferSize; j <= myBufferSize; j++ ) { thepPainter->drawText( int( i + ( myOriginX - ( myFontWidth / 2 ) ) ), int( j + ( myOriginY - ( myFontHeight / 4 ) ) ) - myTextOffsetY, "0" ); } } //Draw minimum label thepPainter->setPen( myForeColor ); thepPainter->drawText( int( myOriginX - ( myFontWidth / 2 ) ), int( myOriginY - ( myFontHeight / 4 ) ) - myTextOffsetY, "0" ); // //Draw maximum label // thepPainter->setPen( myBackColor ); myFontWidth = myFontMetrics.width( myScaleBarMaxLabel ); myFontHeight = myFontMetrics.height(); //first the buffer for ( int i = 0 - myBufferSize; i <= myBufferSize; i++ ) { for ( int j = 0 - myBufferSize; j <= myBufferSize; j++ ) { thepPainter->drawText( int( i + ( myOriginX + myScaleBarWidthInt - ( myFontWidth / 2 ) ) ), int( j + ( myOriginY - ( myFontHeight / 4 ) ) ) - myTextOffsetY, myScaleBarMaxLabel ); } } //then the text itself thepPainter->setPen( myForeColor ); thepPainter->drawText( int( myOriginX + myScaleBarWidthInt - ( myFontWidth / 2 ) ), int( myOriginY - ( myFontHeight / 4 ) ) - myTextOffsetY, myScaleBarMaxLabel ); // //Draw unit label // thepPainter->setPen( myBackColor ); myFontWidth = myFontMetrics.width( myScaleBarUnitLabel ); //first the buffer for ( int i = 0 - myBufferSize; i <= myBufferSize; i++ ) { for ( int j = 0 - myBufferSize; j <= myBufferSize; j++ ) { thepPainter->drawText( i + ( myOriginX + myScaleBarWidthInt + myTextOffsetX ), j + myOriginY + myFontHeight + ( myFontHeight*2.5 ) + myTextOffsetY, myScaleBarUnitLabel ); } } //then the text itself thepPainter->setPen( myForeColor ); thepPainter->drawText( myOriginX + myScaleBarWidthInt + myTextOffsetX, myOriginY + myFontHeight + ( myFontHeight*2.5 ) + myTextOffsetY, myScaleBarUnitLabel ); }
void TesseractWidget::renderText3D(Coordinate Position,const QString &Text,int Size) { QFont myFont("Verdana",Size); myFont.setStyleStrategy(QFont::OpenGLCompatible); renderText(Position.x,Position.y,Position.z,Text,myFont); }
void CSkinDialog::DrawFrame(Graphics & graphics) { CRect rcWindow; GetWindowRect(&rcWindow); Rect rc, rc1; // Title Left rc = m_bActive?m_mapRect["TitleLeftActive"]:m_mapRect["TitleLeft"]; rc1.X = 0; rc1.Y = 0; rc1.Width = rc.Width; rc1.Height = rc.Height; graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel); // Title Center rc = m_bActive?m_mapRect["TitleCenterActive"]:m_mapRect["TitleCenter"]; rc1.X = m_mapRect["TitleLeftActive"].Width; rc1.Y = 0; rc1.Width = rcWindow.Width()-m_mapRect["TitleLeftActive"].Width-m_mapRect["TitleRightActive"].Width; rc1.Height = rc.Height; graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel); // Title Right rc = m_bActive?m_mapRect["TitleRightActive"]:m_mapRect["TitleRight"]; rc1.X = rc1.GetRight(); rc1.Y = 0; rc1.Width = rc.Width; rc1.Height = rc.Height; graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel); // Border Left rc = m_bActive?m_mapRect["BorderLeftActive"]:m_mapRect["BorderLeft"]; rc1.X = 0; rc1.Y = m_mapRect["TitleLeft"].Height; rc1.Width = rc.Width; rc1.Height = rcWindow.Height()-m_mapRect["TitleLeftActive"].Height-m_mapRect["BorderBotActive"].Height; graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel); // Border Bottom rc = m_bActive?m_mapRect["BorderBotActive"]:m_mapRect["BorderBot"]; rc1.X = 0; rc1.Y = rcWindow.Height()-rc.Height-1; rc1.Width = rcWindow.Width(); rc1.Height = rc.Height; graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel); // Border Right rc = m_bActive?m_mapRect["BorderRightActive"]:m_mapRect["BorderRight"]; rc1.X = rcWindow.Width()-rc.Width-1; rc1.Y = m_mapRect["TitleLeftActive"].Height; rc1.Width = rc.Width; rc1.Height = rcWindow.Height()-m_mapRect["TitleLeftActive"].Height-m_mapRect["BorderBotActive"].Height; graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel); // Close Button rc = m_nButtonDown==HT_CLOSE?m_mapRect["NcBtnCloseDown"]:m_mapRect["NcBtnClose"]; rc1.X = rcWindow.Width()-m_mapRect["NcBtnClosePos"].X; rc1.Y = m_mapRect["NcBtnClosePos"].Y; rc1.Width = rc.Width; rc1.Height = rc.Height; graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel); // Max Button if(GetStyle()&WS_MAXIMIZEBOX) { rc = IsZoomed()?(m_nButtonDown==HT_MAX?m_mapRect["NcBtnResDown"]:m_mapRect["NcBtnRes"]):(m_nButtonDown==HT_MAX?m_mapRect["NcBtnMaxDown"]:m_mapRect["NcBtnMax"]); rc1.X = rcWindow.Width()-m_mapRect["NcBtnMaxPos"].X; rc1.Y = m_mapRect["NcBtnMaxPos"].Y; rc1.Width = rc.Width; rc1.Height = rc.Height; graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel); } // Min Button if(GetStyle()&WS_MINIMIZEBOX) { rc = m_nButtonDown==HT_MIN?m_mapRect["NcBtnMinDown"]:m_mapRect["NcBtnMin"]; rc1.X = rcWindow.Width()-m_mapRect["NcBtnMinPos"].X; rc1.Y = m_mapRect["NcBtnMinPos"].Y; rc1.Width = rc.Width; rc1.Height = rc.Height; graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel); } Font myFont(L"宋体", 9); Color col(255,0,0,0); col.SetFromCOLORREF(m_mapColor["Caption"]); SolidBrush blackBrush(col); StringFormat format; format.SetAlignment(StringAlignmentNear); RectF layoutRect(::GetSystemMetrics(SM_CYICON)+m_mapRect["TitleTextStart"].X, m_mapRect["TitleTextStart"].Y, rcWindow.Width(), rcWindow.Height()); WCHAR string[MAX_PATH] = {0}; CString str; GetWindowText(str); MultiByteToWideChar( CP_ACP, 0, str, -1, string, MAX_PATH) ; graphics.DrawString(string, -1, &myFont, layoutRect, &format, &blackBrush); }
void CSkinDialog::OnNcPaint() { // TODO: Add your message handler code here if(!CImgSkin::IsLoaded()) { CXTPDialog::OnNcPaint(); return; } if(HasStyle(WS_CHILD)) { return; } /* RECT ClientRect; GetClientRect(&ClientRect); OffsetRect(&ClientRect, 100, 100); ExcludeClipRect(GetWindowDC()->GetSafeHdc(), ClientRect.left, ClientRect.top, ClientRect.right, ClientRect.bottom); */ CRect rcWindow; GetWindowRect(&rcWindow); Bitmap bmpBuf(rcWindow.Width(), rcWindow.Height()); Graphics graphics(&bmpBuf); Graphics g(GetWindowDC()->GetSafeHdc()); Rect rc, rc1; // Title Left rc = m_bActive?m_mapRect["TitleLeftActive"]:m_mapRect["TitleLeft"]; rc1.X = 0; rc1.Y = 0; rc1.Width = rc.Width; rc1.Height = rc.Height; graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel); // Title Center rc = m_bActive?m_mapRect["TitleCenterActive"]:m_mapRect["TitleCenter"]; rc1.X = m_mapRect["TitleLeftActive"].Width; rc1.Y = 0; rc1.Width = rcWindow.Width()-m_mapRect["TitleLeftActive"].Width-m_mapRect["TitleRightActive"].Width; rc1.Height = rc.Height; graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel); // Title Right rc = m_bActive?m_mapRect["TitleRightActive"]:m_mapRect["TitleRight"]; rc1.X = rc1.GetRight(); rc1.Y = 0; rc1.Width = rc.Width; rc1.Height = rc.Height; graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel); // Border Left rc = m_bActive?m_mapRect["BorderLeftActive"]:m_mapRect["BorderLeft"]; rc1.X = 0; rc1.Y = m_mapRect["TitleLeftActive"].Height; rc1.Width = rc.Width; rc1.Height = rcWindow.Height()-m_mapRect["TitleLeftActive"].Height-m_mapRect["BorderBotActive"].Height; graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel); // Border Bottom rc = m_bActive?m_mapRect["BorderBotActive"]:m_mapRect["BorderBot"]; rc1.X = 0; rc1.Y = rcWindow.Height()-rc.Height-1; rc1.Width = rcWindow.Width(); rc1.Height = rc.Height; graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel); // Border Right rc = m_bActive?m_mapRect["BorderRightActive"]:m_mapRect["BorderRight"]; rc1.X = rcWindow.Width()-rc.Width-1; rc1.Y = m_mapRect["TitleLeftActive"].Height; rc1.Width = rc.Width; rc1.Height = rcWindow.Height()-m_mapRect["TitleLeftActive"].Height-m_mapRect["BorderBotActive"].Height; graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel); // Close Button rc = m_nButtonDown==HT_CLOSE?m_mapRect["NcBtnCloseDown"]:m_mapRect["NcBtnClose"]; rc1.X = rcWindow.Width()-m_mapRect["NcBtnClosePos"].X; rc1.Y = m_mapRect["NcBtnClosePos"].Y; rc1.Width = rc.Width; rc1.Height = rc.Height; graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel); // Max Button if(GetStyle()&WS_MAXIMIZEBOX) { rc = IsZoomed()?(m_nButtonDown==HT_MAX?m_mapRect["NcBtnResDown"]:m_mapRect["NcBtnRes"]):(m_nButtonDown==HT_MAX?m_mapRect["NcBtnMaxDown"]:m_mapRect["NcBtnMax"]); rc1.X = rcWindow.Width()-m_mapRect["NcBtnMaxPos"].X; rc1.Y = m_mapRect["NcBtnMaxPos"].Y; rc1.Width = rc.Width; rc1.Height = rc.Height; graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel); } // Min Button if(GetStyle()&WS_MINIMIZEBOX) { rc = m_nButtonDown==HT_MIN?m_mapRect["NcBtnMinDown"]:m_mapRect["NcBtnMin"]; rc1.X = rcWindow.Width()-m_mapRect["NcBtnMinPos"].X; rc1.Y = m_mapRect["NcBtnMinPos"].Y; rc1.Width = rc.Width; rc1.Height = rc.Height; graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel); } Font myFont(L"宋体", 9); Color col(255,0,0,0); col.SetFromCOLORREF(m_mapColor["Caption"]); SolidBrush blackBrush(col); StringFormat format; format.SetAlignment(StringAlignmentNear); RectF layoutRect(::GetSystemMetrics(SM_CYICON)+m_mapRect["TitleTextStart"].X, m_mapRect["TitleTextStart"].Y, rcWindow.Width(), rcWindow.Height()); WCHAR string[MAX_PATH] = {0}; CString str; GetWindowText(str); MultiByteToWideChar( CP_ACP, 0, str, -1, string, MAX_PATH) ; graphics.DrawString(string, -1, &myFont, layoutRect, &format, &blackBrush); g.DrawImage(&bmpBuf, 0, 0); // Do not call CXTPDialog::OnNcPaint() for painting messages }
void CAngleLabel::DrawAngleLabelMark(Graphics& graph) { CPoint pt2((int)m_ptary[1].X, (int)m_ptary[1].Y); CPoint pt3((int)m_ptary[2].X, (int)m_ptary[2].Y); float fAngle3 = 0.0f; float fAngle1 = CalcRotateAngle(pt2, m_ptary[0]) - 90.0f; float fAngle2 = CalcRotateAngle(pt3, m_ptary[0]) - 90.0f; if(fAngle1 > - 90 && fAngle1 <= 0) { if(fAngle2 >= 180 && fAngle2 <= 270) { fAngle2 -= 360; } else if(fAngle2 - fAngle1 >= 180) { fAngle1 += 360; } } else if(fAngle1 >= 0 && fAngle1 <= 90) { if(fAngle2 >= 180) { if(fAngle2 - fAngle1 >= 180) { fAngle2 -= 360; } } } else if(fAngle1 >= 90 && fAngle1 <= 180) { if(fAngle2 >= -90 && fAngle2 <= 0) { if(fAngle1 - fAngle2 >= 180) { fAngle2 += 360; } } } else if(fAngle1 >= 180 && fAngle1 <= 270) { if(fAngle2 >= 0 && fAngle2 <= 90) { if(fAngle1 - fAngle2 >= 180) { fAngle2 += 360; } } else if(fAngle2 >= -90 && fAngle2 <= 0) { fAngle2 += 360; } } fAngle3 = (fAngle1 + fAngle2) / 2.0f; PointF ptDraw; ptDraw.Y = m_ptary[0].Y; if(fabs(fAngle1 - fAngle2) <= 20) { ptDraw.X = 100 + m_ptary[0].X; } else if(fabs(fAngle1 - fAngle2) <= 30) { ptDraw.X = 80 + m_ptary[0].X; } else { ptDraw.X = 60 + m_ptary[0].X; } Matrix mat; mat.RotateAt(fAngle3, m_ptary[0]); mat.TransformPoints(&ptDraw, 1); Pen penDraw(Color::Blue, 2); RectF rcf(m_ptary[0].X - 30, m_ptary[0].Y - 30, 60, 60); graph.DrawArc(&penDraw, rcf, fAngle1, fAngle2 - fAngle1); Font myFont(_T("Arial"), 12); SolidBrush brush(Color::Red); StringFormat format; format.SetAlignment(StringAlignmentCenter); int nAngle = CalLinesAngle(); m_strAngle.Format(_T("%dбу"), nAngle); graph.SetTextRenderingHint(TextRenderingHintAntiAlias); graph.DrawString(m_strAngle, m_strAngle.GetLength(), &myFont, ptDraw, &format, &brush); }
void __fastcall TTiffBook::FlipCurPage(int n) { //------------------------------------------------------------------------------- // Переворачивает текущую страницу вверх ногами | // n - номер страницы, который надо нанести. <= 0 - только убрать ном стр | //------------------------------------------------------------------------------- stop++; Gdiplus::Graphics *g32; TTiffImage *img = GetImagePage(GetPage()); Gdiplus::Bitmap *fbm = img->fbm; Gdiplus::Rect r; int w = fbm->GetWidth(), h = fbm->GetHeight(); // g = new Gdiplus::Graphics(fbm); Gdiplus::Bitmap *b32 = new Gdiplus::Bitmap(w, h, PixelFormat32bppARGB); g32 = new Gdiplus::Graphics(b32); Gdiplus::Matrix matr; matr.Rotate(180.0f); // поворачиваем его на 270 градусов g32->SetTransform(&matr); //r.X = 0; //r.Y = 0; //r.Width = w; //r.Height = h; //r.X = -SaveBitmapH; //r.Y = -30; //r.Width = SaveBitmapH - 30; //r.Height = SaveBitmapW - 30; r.X = -w; r.Y = -h; r.Width = w; r.Height = h; sres = g32->DrawImage(fbm, r, 0, 0, w, h, Gdiplus::UnitPixel, 0, 0, 0); matr.Reset(); g32->SetTransform(&matr); // Удаляем черные полосы сверху и снизу Gdiplus::Pen whitePen2(Gdiplus::Color(255, 255, 255, 255), 2); g32->DrawLine(&whitePen2, 0, 0, w, 0); g32->DrawLine(&whitePen2, 0, h-1, w, h-1); // Удаляем старый номер страницы - он теперь внизу // Gdiplus::Pen whitePen40(Gdiplus::Color(255, 0, 0, 0), 45); // ??? Пока черный - для отладки! Gdiplus::Pen whitePen40(Gdiplus::Color(255, 255, 255, 255), 45); g32->DrawLine(&whitePen40, 0, h - 50, 200, h - 50); if (n > 0) { // Здесь выводим номер страницы AnsiString snum; wchar_t wnum[20]; snum.printf("%d", n); snum.WideChar(wnum, 20); Gdiplus::Font myFont(L"Arial", 40, Gdiplus::FontStyleBold); Gdiplus::PointF origin(w - 160, 20.0f); Gdiplus::SolidBrush blackBrush(Gdiplus::Color(255, 0, 0, 0)); g32->DrawLine(&whitePen40, w - 200, 50, w, 50); sres = g32->DrawString(wnum, -1, &myFont, origin, &blackBrush); } //if (npage > 0) { // Здесь выводим номер страницы // AnsiString snum; // wchar_t wnum[20]; // snum.printf("%d", npage); // snum.WideChar(wnum, 20); // Gdiplus::Font myFont(L"Arial", 40, Gdiplus::FontStyleBold); // Gdiplus::PointF origin(SaveBitmapW - 160, 20.0f); // Gdiplus::SolidBrush blackBrush(Gdiplus::Color(255, 0, 0, 0)); // SaveBitmap2TiffGraphics->DrawString(wnum, -1, &myFont, origin, &blackBrush); //} // ------- строим SaveBitmap2TiffBitmap1 UINT *pix; unsigned char byte, bit, *pix1; Gdiplus::Bitmap *b1 = new Gdiplus::Bitmap(w, h, PixelFormat1bppIndexed); Gdiplus::Rect BitsRect(0, 0, w, h); Gdiplus::BitmapData *bits = new Gdiplus::BitmapData; Gdiplus::BitmapData *bits1 = new Gdiplus::BitmapData; sres = b32->LockBits(&BitsRect, Gdiplus::ImageLockModeRead, PixelFormat32bppARGB, bits); sres = b1->LockBits(&BitsRect, Gdiplus::ImageLockModeWrite, PixelFormat1bppIndexed, bits1); for (int y = 0; y < h; y++) { pix = (UINT *)((int)bits->Scan0 + bits->Stride * y); pix1 = (unsigned char *)((int)bits1->Scan0 + bits1->Stride * y); byte = 0; for (int x = 0; x < w; x++, pix++) { if ((*pix & 0xFF) > 0xD8) { bit = 1; } else bit = 0; byte <<= 1; byte |= bit; if ((x & 7) == 7) { *pix1++ = byte; byte = 0; } } } b32->UnlockBits(bits); delete bits; b1->UnlockBits(bits1); delete bits1; delete g32; delete b32; TTiffPageInfo *pi = GetPageInfo(GetPage()); if (img->Filn.Length() == 0) { // Это уже временный файл! delete img->fbm; img->fbm = b1; } else { // Надо будет заменить страницу на временный файл img = new TTiffImage(b1); pi->ImageIndex = AppendImage(img); pi->PageIndex = 0; } changed = true; }
void __fastcall TTiffImage::DrawCenter(TCanvas *c, int xc, int yc, int w1, int h1, int PageNumber) { //------------------------------------------------------------------------------- // Рисует текущую страницу с центром (xc, yc) | // Масштабирует пропроционально, в итоге будет заполнено либо w, либо h | //------------------------------------------------------------------------------- if (fbm == NULL) return; Gdiplus::Graphics *gra, *g32; Gdiplus::Bitmap *b32; Gdiplus::Rect r; int w = fbm->GetWidth(), h = fbm->GetHeight(); b32 = new Gdiplus::Bitmap(w, h, PixelFormat32bppARGB); g32 = new Gdiplus::Graphics(b32); r.X = 0; r.Y = 0; r.Width = w; r.Height = h; sres = g32->DrawImage(fbm, r, 0, 0, w, h, Gdiplus::UnitPixel, 0, 0, 0); if (PageNumber != 0) { // Надо выводить номер страницы? AnsiString snum; wchar_t wnum[20]; Gdiplus::Pen whitePen40(Gdiplus::Color(255, 255, 255, 255), 45); snum.printf("%d", PageNumber); snum.WideChar(wnum, 20); Gdiplus::Font myFont(L"Arial", 40, Gdiplus::FontStyleBold); Gdiplus::PointF origin(w - 160, 20.0f); Gdiplus::SolidBrush blackBrush(Gdiplus::Color(255, 0, 0, 0)); g32->DrawLine(&whitePen40, w - 200, 50, w, 50); if (PageNumber > 0) { sres = g32->DrawString(wnum, -1, &myFont, origin, &blackBrush); } } w = w1; h = h1; gra = new Gdiplus::Graphics(c->Handle); //if (CanvasHandle != c->Handle) { // if (CanvasHandle != NULL) delete gra; // CanvasHandle = c->Handle; // gra = new Gdiplus::Graphics(CanvasHandle); //} double scalex = (double)w / GetWidth(); double scaley = (double)h / GetHeight(); double scale = scalex < scaley ? scalex : scaley; w = round(GetWidth() * scale); h = round(GetHeight() * scale); xc -= w / 2; yc -= h / 2; Gdiplus::Rect dst(xc, yc, w, h); // gra->DrawImage(fbm, dst, 0, 0, GetWidth(), GetHeight(), Gdiplus::UnitPixel, 0, 0, 0); gra->DrawImage(b32, dst, 0, 0, GetWidth(), GetHeight(), Gdiplus::UnitPixel, 0, 0, 0); delete gra; delete g32; delete b32; }
static void __fastcall SaveBitmap2Tiff(Gdiplus::Bitmap *bm, int npage) { //------------------------------------------------------------------------------- // Выводит очередную страницу в файл *.tif | // Если npage == 0, то не выводит номер страницы | // Полагает, что если это многостраничный файл, то страница уже выбрана | //------------------------------------------------------------------------------- if (SaveBitmap2TiffState == 0) return; // ------------------ для начала строим образ в SaveBitmap2TiffBitmap32 (SaveBitmap2TiffGraphics) int x, y, w, h; h = bm->GetHeight(); w = bm->GetWidth(); Gdiplus::SolidBrush whiteBrush(Gdiplus::Color(255, 255, 255, 255)); SaveBitmap2TiffGraphics->FillRectangle(&whiteBrush, Gdiplus::Rect(0, 0, SaveBitmapW, SaveBitmapH)); //Gdiplus::Matrix matr; Gdiplus::Rect r; //if (w > h) { // Если изображение шире, чем выше // matr.Rotate(270.0f); // поворачиваем его на 270 градусов // SaveBitmap2TiffGraphics->SetTransform(&matr); // r.X = -SaveBitmapH; // r.Y = -30; // r.Width = SaveBitmapH - 30; // r.Height = SaveBitmapW - 30; //} else { // r.X = 30; // r.Y = 0; // r.Width = SaveBitmapW - 30; // r.Height = SaveBitmapH - 30; //} r.X = 0; r.Y = 0; r.Width = SaveBitmapW; r.Height = SaveBitmapH; SaveBitmap2TiffGraphics->DrawImage(bm, r, 0, 0, w, h, Gdiplus::UnitPixel, 0, 0, 0); // matr.Reset(); // SaveBitmap2TiffGraphics->SetTransform(&matr); if (npage != 0) { // Здесь выводим номер страницы AnsiString snum; wchar_t wnum[20]; Gdiplus::Pen whitePen40(Gdiplus::Color(255, 255, 255, 255), 45); snum.printf("%d", npage); snum.WideChar(wnum, 20); Gdiplus::Font myFont(L"Arial", 40, Gdiplus::FontStyleBold); Gdiplus::PointF origin(SaveBitmapW - 160, 20.0f); Gdiplus::SolidBrush blackBrush(Gdiplus::Color(255, 0, 0, 0)); SaveBitmap2TiffGraphics->DrawLine(&whitePen40, SaveBitmapW - 200, 50, SaveBitmapW, 50); if (npage > 0) { SaveBitmap2TiffGraphics->DrawString(wnum, -1, &myFont, origin, &blackBrush); } } // ------- строим SaveBitmap2TiffBitmap1 UINT *pix; unsigned char byte, bit, *pix1; w = SaveBitmapW; h = SaveBitmapH; Gdiplus::Rect BitsRect(0, 0, SaveBitmapW, SaveBitmapH); Gdiplus::BitmapData *bits = new Gdiplus::BitmapData; Gdiplus::BitmapData *bits1 = new Gdiplus::BitmapData; sres = SaveBitmap2TiffBitmap32->LockBits(&BitsRect, Gdiplus::ImageLockModeRead, PixelFormat32bppARGB, bits); sres = SaveBitmap2TiffBitmap1->LockBits(&BitsRect, Gdiplus::ImageLockModeWrite, PixelFormat1bppIndexed, bits1); for (y = 0; y < SaveBitmapH; y++) { pix = (UINT *)((int)bits->Scan0 + bits->Stride * y); pix1 = (unsigned char *)((int)bits1->Scan0 + bits1->Stride * y); byte = 0; for (x = 0; x < SaveBitmapW; x++, pix++) { if ((*pix & 0xFF) > 0xD8) { bit = 1; } else bit = 0; byte <<= 1; byte |= bit; if ((x & 7) == 7) { *pix1++ = byte; byte = 0; } } } SaveBitmap2TiffBitmap32->UnlockBits(bits); delete bits; SaveBitmap2TiffBitmap1->UnlockBits(bits1); delete bits1; // ------- и наконец выводим очередную страницу SaveBitmap2TiffBitmap1 Gdiplus::EncoderParameters encoderParameters; ULONG parameterValue; // An EncoderParameters object has an array of // EncoderParameter objects. In this case, there is only // one EncoderParameter object in the array. encoderParameters.Count = 1; // Initialize the one EncoderParameter object. // encoderParameters.Parameter[0].Guid = Gdiplus::EncoderSaveFlag; encoderParameters.Parameter[0].Guid = aEncoderSaveFlag; encoderParameters.Parameter[0].Type = Gdiplus::EncoderParameterValueTypeLong; encoderParameters.Parameter[0].NumberOfValues = 1; encoderParameters.Parameter[0].Value = ¶meterValue; // Get the CLSID of the TIFF encoder. CLSID encoderClsid; GetEncoderClsid(L"image/tiff", &encoderClsid); if (SaveBitmap2TiffState == 1) { // Требуется вывести первую страницу parameterValue = Gdiplus::EncoderValueMultiFrame; sres = SaveBitmap2TiffBitmap1->Save(SaveBitmap2TiffFiln, &encoderClsid, &encoderParameters); } else { parameterValue = Gdiplus::EncoderValueFrameDimensionPage; sres = SaveBitmap2TiffBitmap1->SaveAdd(&encoderParameters); } SaveBitmap2TiffState = 2; }