Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
823 views
in Technique[技术] by (71.8m points)

uwp - Test whether pointer is over irregular shape

In my app, shapes are highlighted while the cursor is over them. This is achieved using event handlers for PointerEntered and PointerExited. You can also drag shapes and the shape captures the pointer while it is being dragged.

If you drag a shape behind another shape, then the shape in front should be highlighted when the pointer is released. However this doesn't happen because its PointerEntered event was never fired because mouse events were being captured by the dragged shape when it entered.

A solution would be to do a hit test on the pointer with all the shapes that are in front of the dragged shape in its PointerCaptureLost event handler. I found an easy way of testing whether the pointer is over a shape here:

Test whether the pointer is over a UIElement

However that is not applicable in my case because the shapes can be irregular. I think implementing a hit test for irregular shapes for this feature would be overkill.

Is there a simple solution to this?

(Edits follow...)

I don't think manually implementing a hit test is a feasible solution to this, given the large amount of effort that I think would be involved compared to the fairly minor extent of the problem.

It would be easy to do if the pointer capture wasn't active. Is it practical to have draggable elements without an active pointer capture? I could use a PointerMoved handler at the canvas level instead of the shape? [edit 2] Thinking about it, it seems to me that it would create more problems than it would solve.

Edit 3: I've removed this feature to avoid this issue. Now shapes are highlighted only when they are pressed, not hovered over. The cursor changes when it hovers over a shape. From looking at other applications with similar functionality, this seems to be a more typical approach.

question from:https://stackoverflow.com/questions/65868896/test-whether-pointer-is-over-irregular-shape

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...