コード例 #1
0
ファイル: Turret.cpp プロジェクト: pokelege/GeometryWars
void Turret::draw(Graphics& graphics, const Vector2& parentPosition)
{
	graphics.SetColor(WHITE);

	Engine::Matrix3 turretRotation(rotationNormal, Engine::PerpCW(rotationNormal), parentPosition);

	Engine::Vector2 drawTurretArray[] =
	{
		turretRotation * (Engine::Vector2(0, -turretSize)),
		turretRotation * (Engine::Vector2(0, turretSize)),

		turretRotation * (Engine::Vector2(0, turretSize)),
		turretRotation * (Engine::Vector2(turretSize, 0)),

		turretRotation * (Engine::Vector2(turretSize, 0)),
		turretRotation * (Engine::Vector2(0, -turretSize))
	};

	unsigned int drawTurretArraySize = sizeof(drawTurretArray) / (sizeof(*drawTurretArray) * 2);

	graphics.SetColor(RED);
	graphics.DrawLines(drawTurretArraySize, *drawTurretArray);
}
コード例 #2
0
bool CGdiPlusImage::DrawImage(CDC* pDC, CRect& rcDraw, CRect& rcCanvas)
{
    //´´½¨ÆÁÄ»
    ASSERT(pDC!=NULL); 
    if ( !pDC ) return false; 

    Bitmap bmp(rcCanvas.Width(), rcCanvas.Height()); 
    Graphics* pGraphics = Graphics::FromImage(&bmp); 
    if ( !pGraphics ) return false;

    //GraphicsContainer Containter = pGraphics->BeginContainer();
    pGraphics->SetSmoothingMode(SmoothingModeHighQuality); 

    SolidBrush bgbrush(Color(238, 243, 250));
    pGraphics->FillRectangle(&bgbrush, 0, 0, rcCanvas.Width(), rcCanvas.Height());
     
    if ( m_pImage )
    {
        //»ñÈ¡ÊôÐÔ 
        INT nImageWidth  = m_pImage->GetWidth();
        INT nImageHeight = m_pImage->GetHeight(); 


        float fMin = 1.0F;  
        bool bZoomOut = false; 
        int nXSrc = 0;
        int nYSrc = 0;  
         
        //¹¹ÔìλÖÃ
        RectF rcDrawRect;  
        rcDrawRect.X = rcDraw.left;
        rcDrawRect.Y = rcDraw.top;
        rcDrawRect.Width = rcDraw.Width();
        rcDrawRect.Height = rcDraw.Height(); 

        // »­±Ê
        Pen pen(Color(255, 0, 0), 2); 

        Matrix mtr;
        mtr.Translate(rcDrawRect.X + rcDrawRect.Width / 2, rcDrawRect.Y + rcDrawRect.Height / 2);
        mtr.Rotate(m_nRotateAngle);
        mtr.Translate(-(rcDrawRect.X + rcDrawRect.Width / 2), -(rcDrawRect.Y + rcDrawRect.Height / 2));

        pGraphics->SetTransform(&mtr); 

        //»æ»­Í¼Ïñ 
        pGraphics->DrawImage(
            m_pImage, rcDrawRect,
            nXSrc, nYSrc,
            (REAL)nImageWidth - nXSrc * 2, (REAL)nImageHeight - nYSrc * 2, UnitPixel);  
         

        for ( int i = 0; i < m_vvecPoints.size(); ++ i )
        {
            int nCount = m_vvecPoints[i].size(); 
            Point *pts = new Point[nCount];

            for ( int j = 0; j < nCount; ++ j )
            {
                pts[ j ] = m_vvecPoints[ i ][ j ]; 
                pts[ j ].X += rcDraw.left;
                pts[ j ].Y += rcDraw.top; 
            }  

            //for ( int j = 0; j < nCount - 1; ++ j )
            { 
               // pGraphics->DrawLine(&pen, pts[ j ], pts[ j +1 ]); 
            } 

  
                pGraphics->DrawLines(&pen, pts, nCount);
                //pGraphics->DrawPolygon(&pen, pts, nCount); 
        


            delete[] pts;
            pts = NULL; 
        }


        pGraphics->ResetTransform();   
        //pGraphics->EndContainer(Containter);

    } // if ( m_pImage )

    // ´ÓÄڴ濽±´ÖÁÉ豸
    Graphics graphicsreal(pDC->GetSafeHdc()); 
    graphicsreal.DrawImage(&bmp, 0, 0, rcCanvas.Width(), rcCanvas.Height()); 
    delete pGraphics;
    pGraphics = NULL;

    return true;
}