dotnet / dotnet/wpf

Issues about Bounds of TouchPoint

Open
#9,727 2 comments 0 reactions 0 assignees View on GitHub
area-Touch Investigate
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

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.

https://github.com/dotnet/wpf/blob/9e2995f9871d96462224c1ebbb64b89ca9efb73f/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Pointer/PointerTouchDevice.cs#L77-L119

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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.