- KeldorKatarn
- Posts: 193
- Joined:
Getting the View DPI
In WPF there are a couple common ways of getting the current DPI:
Unity itself has a Screen.dpi, which first of all is not differentiating between x and y, and also seems to be incorrect on some devices as discussed here:
https://forum.unity.com/threads/screen- ... id.414014/
So... what is the best way with Noesis to get the DPI value if I want to do some calculations inside my custom controls with it? (In case I want to support UseLayoutRounding)
- Code: Select all
VisualTreeHelper.GetDpi(Visual visual); // Since .NET Framework 4.6.2
- orCode: Select all
var dpiXProperty = typeof(SystemParameters).GetProperty("DpiX", BindingFlags.NonPublic | BindingFlags.Static); var dpiYProperty = typeof(SystemParameters).GetProperty("Dpi", BindingFlags.NonPublic | BindingFlags.Static); var pixelsPerInchX = (int)dpiXProperty.GetValue(null, null); DpiX = (double)pixelsPerInchX; var pixelsPerInchY = (int)dpiYProperty.GetValue(null, null); DpiY = (double)pixelsPerInchY;
- Code: Select all
var source = PresentationSource.FromVisual(visual); var dpiX = One; var dpiY = One; if (source?.CompositionTarget != null) { dpiX = NinetySix * source.CompositionTarget.TransformToDevice.M11; dpiY = NinetySix * source.CompositionTarget.TransformToDevice.M22; }
Unity itself has a Screen.dpi, which first of all is not differentiating between x and y, and also seems to be incorrect on some devices as discussed here:
https://forum.unity.com/threads/screen- ... id.414014/
So... what is the best way with Noesis to get the DPI value if I want to do some calculations inside my custom controls with it? (In case I want to support UseLayoutRounding)
Re: Getting the View DPI
Support for DPI in the View was implemented for Noesis 3.1. In Unity, right now, we are using Screen.dpi because that's probably going to be the most robust way, even if it is buggy on a few devices.
And we should implement VisualTreeHelper.GetDpi, I have created a ticket for it (#2034)
And we should implement VisualTreeHelper.GetDpi, I have created a ticket for it (#2034)
Re: Getting the View DPI
If this helps, this is implemented as a root transform in the view. In NoesisGUI 3.0 this must be done manually as shown in our Controls Gallery.So... what is the best way with Noesis to get the DPI value if I want to do some calculations inside my custom controls with it? (In case I want to support UseLayoutRounding)
- KeldorKatarn
- Posts: 193
- Joined:
Re: Getting the View DPI
A root transform? I'm not sure how that works.
The usecase I was thinking of was for example what WPF does in the Border class. When LayoutRounding is active, the border thickness is rounded to the nearest integer of device pixels.
I need the DPI to make that calculation inside a custom border class (like is present in my Conductors sample branch in the DecorativeBorder)
The usecase I was thinking of was for example what WPF does in the Border class. When LayoutRounding is active, the border thickness is rounded to the nearest integer of device pixels.
I need the DPI to make that calculation inside a custom border class (like is present in my Conductors sample branch in the DecorativeBorder)
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot], Semrush [Bot] and 20 guests