dotnet / Microsoft.Maui.Graphics

An experimental cross-platform native graphics library.
MIT License
682 stars 63 forks source link

How does this code interact with WinForms High-DPI? #43

Open wjk opened 3 years ago

wjk commented 3 years ago

What the title says. I want to be able to write my drawing code while reasoning about values (borders, corner radii, etc) to look correct at 100% DPI scaling, then have the system translate the values (making border lines wider, increasing the corner radius diameter, etc) so the end result is visually identical under DPI scaling values greater than 100%.

Direct2D can do this, but using it is a pain in the butt. WPF does this intrinsically, but I have decided to not use it for my projects due to how disorganized the code is (making it impossible to refactor and hard to contribute useful improvements). WinUI 3 can also do it, but then again WinUI 3 is useful for just about nothing right now considering how pre-alpha the codebase still is, and its glacial release cycle. I want to stick with Windows Forms for my app, but at the same time want more sophisticated drawing primitives to build upon. Can you tell me how to use System.Graphics to accomplish this? Thanks!

wjk commented 3 years ago

After inspecting System.Graphics more, I realize I misunderstood its purpose. System.Graphics is not an improvement on top of GDI+; System.Graphics is a portability layer over GDI+. I would not mind an answer to the above question, but I will continue to use raw System.Drawing in my Windows-only apps for this reason, as it has more features. Thanks!

jonlipsky commented 3 years ago

@wjk The way that I handle that use case with this library in my own apps is that the base implementation draws at full DPI, and then I wrap that canvas with a scaling canvas so that I scale to match the UI scale. This is also the approach that is used on Android, and in the case of Android the graphics view does this for you automatically. Perhaps I could add something similar for windows too.