Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues about Bounds of TouchPoint #9727

Open
lindexi opened this issue Sep 6, 2024 · 2 comments
Open

Issues about Bounds of TouchPoint #9727

lindexi opened this issue Sep 6, 2024 · 2 comments
Labels
Investigate Requires further investigation by the WPF team.

Comments

@lindexi
Copy link
Contributor

lindexi commented Sep 6, 2024

I discovered that the implementation of PointerTouchDevice uses a particularly strange and incorrect method to obtain the size of the touch point. In the GetStylusPointWidthOrHeight method of PointerTouchDevice, it attempts to extract the width and height information of the touch point. However, it uses Resolution for conversion, thus obtaining the physical size of the touch point. Please pay special attention to this point: the physical size of the actual touch is obtained here. Subsequently, the physical size of the actual touch is used in calculations with pixelsPerInch. However, this pixelsPerInch represents the screen DPI value of the display, which cannot be associated with the physical size of the actual touch. This leads to a very strange and incorrect touch size being returned in PointerTouchDevice. The core issue is the confusion between the screen DPI and the physical size of the touch.

protected override double GetStylusPointWidthOrHeight(StylusPoint stylusPoint, bool isWidth)
{
double pixelsPerInch = DpiUtil.DefaultPixelsPerInch;
// If we have an active source and root visual use the DPI from there
if (ActiveSource?.RootVisual != null)
{
pixelsPerInch = VisualTreeHelper.GetDpi(ActiveSource.RootVisual).PixelsPerInchX;
}
StylusPointProperty property = (isWidth ? StylusPointProperties.Width : StylusPointProperties.Height);
double value = 0d;
if (stylusPoint.HasProperty(property))
{
// Get the property value in the corresponding units
value = (double)stylusPoint.GetPropertyValue(property);
StylusPointPropertyInfo propertyInfo = stylusPoint.Description.GetPropertyInfo(property);
if (!DoubleUtil.AreClose(propertyInfo.Resolution, 0d))
{
value /= propertyInfo.Resolution;
}
else
{
value = 0;
}
// Convert the value to Inches
if (propertyInfo.Unit == StylusPointPropertyUnit.Centimeters)
{
value /= CentimetersPerInch;
}
// Convert the value to pixels
value *= pixelsPerInch;
}
return value;
}

The code of main issues are value /= propertyInfo.Resolution; and value *= pixelsPerInch;.

What is Correct Behavior?

There are two aspects to consider:

  1. Providing True Physical Dimensions: To obtain the true physical dimensions, use the following code: value /= propertyInfo.Resolution;. This computation delivers the real-world physical size.

  2. Returning Pixel Dimensions: If the goal is to return the pixel dimensions, you need to acquire the maximum and minimum values of StylusPointProperty and calculate the ratio against the screen dimensions. By doing this, you can determine the touch size in terms of the screen resolution. Subsequently, you can incorporate the DPI to translate this size into pixel dimensions within the WPF coordinate system.

I do not think it is the design issues. But some one may dependent on this behavior to build the application.

@harshit7962 harshit7962 added the Investigate Requires further investigation by the WPF team. label Sep 6, 2024
@miloush
Copy link
Contributor

miloush commented Sep 6, 2024

That code seems to be used for the touch point bounding rectangle, which seems to be reasonable to be in pixels? You don't mention what you expect the behavior to be.

(Also note that the WISP device does not use DPI.)

@lindexi
Copy link
Contributor Author

lindexi commented Sep 6, 2024

@miloush Thank you and I update the issues content.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Investigate Requires further investigation by the WPF team.
Projects
None yet
Development

No branches or pull requests

3 participants