Hi everyone!
I have an image of a cogwheel in my app that the user can zoom in:
I want to enable the user to click and select one of these lines. What would be the best way? I thought about saving a std::vector of the wxRect around each line during the paint process and loop the mouse position through it to see if one contains it. But the wxRect overlap quite a lot. Ideal would be a rotated wxRect, but that might result in a lot of calculations?
Any better idea?
Thanx!
mouseOver lines on wxBitmap Topic is solved
- doublemax@work
- Super wx Problem Solver
- Posts: 474
- Joined: Wed Jul 29, 2020 6:06 pm
- Location: NRW, Germany
Re: mouseOver lines on wxBitmap
I'd use a wxRect for a fast check, and a wxRegion (or a pure calculated method) for a second, precise check. Depending on how many lines you have - and it looks like there could be many - you might need a tree structure with nested rectangles for better performance.
-
- Ultimate wxWidgets Guru
- Posts: 539
- Joined: Fri May 22, 2009 8:52 am
- Location: Bremen, Germany
Re: mouseOver lines on wxBitmap
Sounds good, thanx! I would say there will be max 4000 lines. You think wxRegion is much slower than wxRect? To use both like you suggested, I would have to fill and loop at least two vectors. I would tend to only use wxRegion, what do you think?
A nice pre test would be if the mouse is between the inner and outer radius of the cogs. Is there built in way to test it or do I have to calculate it myself?
A nice pre test would be if the mouse is between the inner and outer radius of the cogs. Is there built in way to test it or do I have to calculate it myself?
- doublemax@work
- Super wx Problem Solver
- Posts: 474
- Joined: Wed Jul 29, 2020 6:06 pm
- Location: NRW, Germany
Re: mouseOver lines on wxBitmap
It *is* much slower. Actually it uses a list of rectangles internally. In worst case this will be many rectangles with 1 pixel height.
(Edit: that's when you use a bitmap to create the region. I don't know what happens if you use vector points and i can't check this atm)
You'd have to calculate that yourself.
Re: mouseOver lines on wxBitmap
After a look into the sources, it seems that at least under Windows there's dedicated platform specific code that creates a region from a polygon without rendering it into a bitmap. So it's possible that at least under Windows a wxRegion can be both small and fast. I didn't make any performance tests, but it might be worth a try.
Use the source, Luke!
-
- Ultimate wxWidgets Guru
- Posts: 539
- Joined: Fri May 22, 2009 8:52 am
- Location: Bremen, Germany
Re: mouseOver lines on wxBitmap
Thank you for taking the time! Since my app only runs on Windows, I will look into it. I have a first test if the mouse is within outer and inner radius and ordered the lines´ wxRects by x coordinate so I can access and leave the vector efficiently. Maybe using wxRect is fast enough and overlapping rects are not as bad as I thought.doublemax wrote: ↑Tue Oct 06, 2020 9:54 pm After a look into the sources, it seems that at least under Windows there's dedicated platform specific code that creates a region from a polygon without rendering it into a bitmap. So it's possible that at least under Windows a wxRegion can be both small and fast. I didn't make any performance tests, but it might be worth a try.