jingwood / d2dlib

A .NET library for hardware-accelerated, high performance, immediate mode rendering via Direct2D.
MIT License
234 stars 40 forks source link

Custom Dash Styles for DrawRectangle #28

Closed nikeee closed 4 years ago

nikeee commented 4 years ago

It seems that DrawRectangle can only be used with a specific Color.

In GDI, we can also use a Pen to draw a rectangle. This Pen as a DashPattern property as well as some other properties that change the behaviour of the Pen (for example, DashOffset). The DashPattern can be used to draw dashed lines. And when used for DrawRectangle, we get a dahsed rectangle.

Is it possible to do this with Direct2D aswell? I'd use this feature in my current application.

I see that there is a D2DDashStyle we can pass to DrawRectangle. Is there a way to provide a custom dash pattern or a dash offset?

Edit: I found this Direct2D api for that: https://docs.microsoft.com/en-us/windows/win32/direct2d/how-to-draw-an-ellipse#draw-an-ellipse-with-a-dashed-stroke This example shows how to create a custom dash pattern: https://docs.microsoft.com/en-us/windows/win32/api/d2d1/ne-d2d1-d2d1_dash_style#remarks