예제 #1
0
//-----------------------------------------------------------------------------
void D2DDrawContext::setLineStyle (const CLineStyle& style)
{
    if (strokeStyle && currentState.lineStyle == style)
        return;
    if (strokeStyle)
    {
        strokeStyle->Release ();
        strokeStyle = 0;
    }
    D2D1_STROKE_STYLE_PROPERTIES properties;
    switch (style.getLineCap ())
    {
    case CLineStyle::kLineCapButt:
        properties.startCap = properties.endCap = properties.dashCap = D2D1_CAP_STYLE_FLAT;
        break;
    case CLineStyle::kLineCapRound:
        properties.startCap = properties.endCap = properties.dashCap = D2D1_CAP_STYLE_ROUND;
        break;
    case CLineStyle::kLineCapSquare:
        properties.startCap = properties.endCap = properties.dashCap = D2D1_CAP_STYLE_SQUARE;
        break;
    }
    switch (style.getLineJoin ())
    {
    case CLineStyle::kLineJoinMiter:
        properties.lineJoin = D2D1_LINE_JOIN_MITER;
        break;
    case CLineStyle::kLineJoinRound:
        properties.lineJoin = D2D1_LINE_JOIN_ROUND;
        break;
    case CLineStyle::kLineJoinBevel:
        properties.lineJoin = D2D1_LINE_JOIN_BEVEL;
        break;
    }
    properties.dashOffset = (FLOAT)style.getDashPhase ();
    properties.miterLimit = 10.f;
    if (style.getDashCount ())
    {
        properties.dashStyle = D2D1_DASH_STYLE_CUSTOM;
        FLOAT* lengths = new FLOAT[style.getDashCount ()];
        for (int32_t i = 0; i < style.getDashCount (); i++)
            lengths[i] = (FLOAT)style.getDashLengths ()[i];
        getD2DFactory ()->CreateStrokeStyle (properties, lengths, style.getDashCount (), &strokeStyle);
        delete [] lengths;
    }
    else
    {
        properties.dashStyle = D2D1_DASH_STYLE_SOLID;
        getD2DFactory ()->CreateStrokeStyle (properties, 0, 0, &strokeStyle);
    }
    COffscreenContext::setLineStyle (style);
}
예제 #2
0
//-----------------------------------------------------------------------------
void GdiplusDrawContext::setLineStyleInternal (const CLineStyle& style)
{
	if (pPen)
	{
		Gdiplus::LineCap lineCap;
		switch (style.getLineCap ())
		{
			case CLineStyle::kLineCapButt: lineCap = Gdiplus::LineCapFlat; break;
			case CLineStyle::kLineCapRound: lineCap = Gdiplus::LineCapRound; break;
			case CLineStyle::kLineCapSquare: lineCap = Gdiplus::LineCapSquare; break;
		}
		pPen->SetLineCap (lineCap, lineCap, Gdiplus::DashCapFlat); // DashCapFlat correct ?

		Gdiplus::LineJoin lineJoin;
		switch (style.getLineJoin ())
		{
			case CLineStyle::kLineJoinMiter: lineJoin = Gdiplus::LineJoinMiter; break;
			case CLineStyle::kLineJoinRound: lineJoin = Gdiplus::LineJoinRound; break;
			case CLineStyle::kLineJoinBevel: lineJoin = Gdiplus::LineJoinBevel; break;
		}
		pPen->SetLineJoin (lineJoin);

		pPen->SetDashOffset ((Gdiplus::REAL)style.getDashPhase ());
		
		if (style.getDashCount () == 0)
		{
			pPen->SetDashStyle (Gdiplus::DashStyleSolid);
		}
		else
		{
			Gdiplus::REAL* dashes = new Gdiplus::REAL [style.getDashCount ()];
			for (uint32_t i = 0; i < style.getDashCount (); i++)
				dashes[i] = (Gdiplus::REAL)style.getDashLengths ()[i];
			pPen->SetDashPattern (dashes, style.getDashCount ());
			delete [] dashes; 
		}
	}
}