Select underlying objects
Greetings!
I've made a progra开发者_如何学Gom that lets you draw shapes. All shapes are contained in a vector. What I need help with is; when several shapes are stacked on top of each other, I want to cycle through them, top to bottom, if the user clicks repeatedly. I'm thinking something along the lines of:
- Store every object under the mouse location where the user clicked in some sort of container
- Keep track of which object was first in queue, and should be last (?) after the next click
- Repeat step two until the user clicks somewhere that results in a different queue
This is more of a general programming question, rather than just C++, but any help would be greatly appreciated, and if that answer also provides a pretty solution in C++, all the better!
A popular approach to this is to assign each item a z-order. Items with higher z-order hide items with lower z-order if they overlap. In your case, you would just have to find all items below the cursor and rotate their z-orders when the user clicks.
精彩评论