2007년 4월 8일 일요일

GDI+ line cap shape/join shape

void CGdiplusDemoView::OnDraw(CDC* pDC)
{
    Graphics g(pDC->m_hDC);

    Pen capPen(Color(255, 0, 0, 0), 5);
    
    /*
    enum LineCap
    {
        LineCapFlat             = 0,
        LineCapSquare           = 1,
        LineCapRound            = 2,
        LineCapTriangle         = 3,

        LineCapNoAnchor         = 0x10, // corresponds to flat cap
        LineCapSquareAnchor     = 0x11, // corresponds to square cap
        LineCapRoundAnchor      = 0x12, // corresponds to round cap
        LineCapDiamondAnchor    = 0x13, // corresponds to triangle cap
        LineCapArrowAnchor      = 0x14, // no correspondence

        LineCapCustom           = 0xff, // custom cap

        LineCapAnchorMask       = 0xf0  // mask to check for anchor or not.
    };
    */

    // Line 
    capPen.SetStartCap(LineCapSquare);
    capPen.SetEndCap(LineCapRound);
    g.DrawLine(&capPen, 50, 50, 400, 50);

    capPen.SetStartCap(LineCapTriangle);
    capPen.SetEndCap(LineCapNoAnchor);
    g.DrawLine(&capPen, 50, 100, 400, 100);

    capPen.SetStartCap(LineCapSquareAnchor);
    capPen.SetEndCap(LineCapRoundAnchor);
    g.DrawLine(&capPen, 50, 150, 400, 150);

    capPen.SetStartCap(LineCapDiamondAnchor);
    capPen.SetEndCap(LineCapArrowAnchor);
    g.DrawLine(&capPen, 50, 200, 400, 200);

    /*
        enum LineJoin
    {
        LineJoinMiter        = 0,
        LineJoinBevel        = 1,
        LineJoinRound        = 2,
        LineJoinMiterClipped = 3
    };
    */

    // Set line join style
    Pen joinPen(Color(255, 0, 0, 0), 10);

    joinPen.SetLineJoin(LineJoinBevel);
    g.DrawRectangle(&joinPen, 50, 250, 100, 100);

    joinPen.SetLineJoin(LineJoinMiter);
    g.DrawRectangle(&joinPen, 180, 250, 100, 100);

    joinPen.SetLineJoin(LineJoinRound);
    g.DrawRectangle(&joinPen, 310, 250, 100, 100);
}


댓글 없음: