3

I've just switched to using Direct2D on my project. I'm using C++Builder XE2 with the VCL windows platform and I am using the wrapper Direct2D that came with XE2. I'm able to draw Rectangle, Line, Ellipse and all with scale, rotation, translation. All works great. The only issue I have now is that the Line thickness is scaled to my Scale factor. I'd like to keep the line thickness to what ever I specify regardless the Scale factor. The only solution I found from long long googling is to set D2D1_STROKE_TRANSFORM_TYPE to D2D1_STROKE_TRANSFORM_TYPE_FIXED.

How and where do I set this? And is there another way to do this?

Thanks Bill

JP Yang
  • 31
  • 1

1 Answers1

1

I was looking for the same thing, putting this here in case it will be useful for someone else. At the end of the "Draw..." methods there is a parameter called "ID2D1StrokeStyle1*", this is what we need to pass. To create a stroke style, we declare a

ID2D1StrokeStyle1* strokeStyleFixedThickness;

We initialize it with ID2D1Factory1's CreateStrokeStyle function. Below creates a stroke style with all the default settings, only with the stroke transform type set to fixed:

HRESULT hr = direct2dFactory->CreateStrokeStyle(
    D2D1::StrokeStyleProperties1(
        D2D1_CAP_STYLE_FLAT,
        D2D1_CAP_STYLE_FLAT,
        D2D1_CAP_STYLE_FLAT,
        D2D1_LINE_JOIN_MITER,
        10.0f,
        D2D1_DASH_STYLE_SOLID,
        0.0f, D2D1_STROKE_TRANSFORM_TYPE_FIXED),
        nullptr, 0, &strokeStyleFixedThickness);

Then you can use it in the render target's draw methods:

renderTarget->DrawLine(point0, point1, myBrush, lineWidth, strokeStyleFixedThickness);
Furkan
  • 11
  • 3