Plotting and mouseover

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
kayamel
Knows some wx things
Knows some wx things
Posts: 42
Joined: Wed May 24, 2006 2:38 pm

Plotting and mouseover

Post by kayamel »

Hi,

I would appreciate any idea on how to detect a mouseover when the user hover the mouse pointer over any part of a plot.

To draw the plot, I'm drawing lines from point to point so a solution based on comparing the mouse position and the points would leave out the hovering over the connecting lines.

I then tried using wxDC::GetPixel. It solves the problem of detecting any part of the plot but I have to call refresh to make something happen (show coordinates)

Thanks
nroberts
Knows some wx things
Knows some wx things
Posts: 44
Joined: Fri Aug 03, 2007 8:07 pm

Re: Plotting and mouseover

Post by nroberts »

kayamel wrote:Hi,

I would appreciate any idea on how to detect a mouseover when the user hover the mouse pointer over any part of a plot.

To draw the plot, I'm drawing lines from point to point so a solution based on comparing the mouse position and the points would leave out the hovering over the connecting lines.
Would it? You have an equation for the lines, do you not? You pretty much have to in order to draw them.

So, something like:

Code: Select all

  if (abs(eq(pt.x) - pt.y) <= hit_tolerance)
Right?
kayamel
Knows some wx things
Knows some wx things
Posts: 42
Joined: Wed May 24, 2006 2:38 pm

Post by kayamel »

Hi,

No I don't plot a function actually.

I'm taking a data file with columns of x and y's and just plot them.

Unless there is some preset function in wxWidgets or anything else, I don't think I'll take the pain of developing something to try and get all the points by which a line passes. Also I'll have to apply it on every segment between every two points. Only then would I be able to make the hit check. Which would leave me with still having to call refresh constantly if I want the coordinates to pop-up automatically :(
nroberts
Knows some wx things
Knows some wx things
Posts: 44
Joined: Fri Aug 03, 2007 8:07 pm

Post by nroberts »

kayamel wrote:Hi,

No I don't plot a function actually.

I'm taking a data file with columns of x and y's and just plot them.
You still have the point-slope formula.
kayamel
Knows some wx things
Knows some wx things
Posts: 42
Joined: Wed May 24, 2006 2:38 pm

Post by kayamel »

That's why I said I'll have to apply the code on every segment if I do it manually. With data ranging from 1024 to 4096 -> 1023 - 4095 segments for which I'll have to check for every point...

Or maybe there is something I'm not getting
nroberts
Knows some wx things
Knows some wx things
Posts: 44
Joined: Fri Aug 03, 2007 8:07 pm

Post by nroberts »

kayamel wrote:That's why I said I'll have to apply the code on every segment if I do it manually. With data ranging from 1024 to 4096 -> 1023 - 4095 segments for which I'll have to check for every point...

Or maybe there is something I'm not getting
search functions are friendly.

O(log N)
kayamel
Knows some wx things
Knows some wx things
Posts: 42
Joined: Wed May 24, 2006 2:38 pm

Post by kayamel »

Ok, I gave this a thought and I have come to a problem :

If I have two points that have adjacent x coordinates but very different y coordinates (or vice versa), the screen display would approximate the segment with a few horizontal or vertical lines.

In real math, I would get fractional coordinates for the points in between but that won't be the case with pixels. Just rounding up the results is not guaranteed to give me the same display as on the screen.
nroberts
Knows some wx things
Knows some wx things
Posts: 44
Joined: Fri Aug 03, 2007 8:07 pm

Post by nroberts »

kayamel wrote:Ok, I gave this a thought and I have come to a problem :

If I have two points that have adjacent x coordinates but very different y coordinates (or vice versa), the screen display would approximate the segment with a few horizontal or vertical lines.

In real math, I would get fractional coordinates for the points in between but that won't be the case with pixels. Just rounding up the results is not guaranteed to give me the same display as on the screen.
Yes, you need to do some scaling and rounding to find the pixels. Furthermore, you probably don't actually want only those pixels in the line but to be within some margin of error. Otherwise you make it too difficult to grab the line.

It seems to me that what you need is indeed the point/slope formula but you just need to do more work to translate that then maybe you know how to do? Anyway, this is a problem that's independent of GUI framework; I don't think you'll find anything in wx that will do it for you.
Post Reply