0

Is it possible to hijack the mouse when dragging on a WPF component?

We have a polar chart that needs to be drawn on using the mouse.

Rather then use snapping and require the user to have some dexterity to match the curves, is it possible to hijack the mouse input, and convert mouse x to follow the degrees/rotations and mouse y to follow the magnitude?

Polar mouse mapping

Blue represents where the pointer would end up after a drag from origin red.

Ryan Leach
  • 4,262
  • 5
  • 34
  • 71
  • can you supply the code for drawing? how do you determine when a switch of magnitude occurs? does the drawing begin with mouse click?=! – Mong Zhu Aug 30 '17 at 06:20
  • It's when a drag occurs. This is currently theoretical as I am brand new to c# and wpf. No I can't share the code for the current drawing, as it would likely violate the license, and it doesn't currently act as I describe. What I'm trying to probe, is that it's possible or hints, so that I can justify that the time taken to refactor code in a new framework is worth the usability improvement. – Ryan Leach Aug 30 '17 at 06:45
  • "I'm trying to probe, is that it's possible or hints," I guess you don't expect that someone will write the code for you here. One hint would be to research how to get the chart coordinates from cursor position, and how to change cursor position programatically – Mong Zhu Aug 30 '17 at 06:54
  • No it would be rediculous to expect someone to code it all from scratch. The ideal answer in my mind would be "yes it's possible to do this via hiding the cursor / using a substitute / calling a method / modifying this event. Here's a link to the documentation for the X I used when I faced a similar issue" – Ryan Leach Aug 30 '17 at 07:42
  • 1
    See [this](https://stackoverflow.com/questions/8050825/how-to-move-mouse-cursor-using-c). – dymanoid Aug 30 '17 at 08:59

1 Answers1

1

Like others mentioned it is very hard to write something without seeing any code that you got so far. But this would be my take. One of the common pattern in WPF is MVVM. MVVM stands for Model View ViewModel. The key is to have the values you are drawing or basically everything view related in a ViewModel and just draw the graph via binding on the UI from the ViewModel (dump views). Now whenever you move the mouse compare the capture coordinates with the values for your drawing in the viewmodel. Then you have to detect for patterns where you want to take over control of your mouse pointer and update the position via code. Maybe you need to interpolate the movement to have it nice and smooth.

Also a very good library to work with events and especially mouse events is Rx (https://github.com/Reactive-Extensions/Rx.NET) this can help to react on mouse events and detect pattern.

Like I said this is just an approach how I would start to work myself to such a task. Since you did not provide any code so far its really hard to jump in in detail. But I hope it may help to develop a strategy.

silverfighter
  • 6,762
  • 10
  • 46
  • 73