c++ moving object from middle to top of stack

Started by
3 comments, last by maltman 5 years, 1 month ago

I never ask for help, to a fault, but I'm stumped on this. I am trying to recreate something like Windows where there is a stack of windows and one window is on top which can be interacted with. When a window that is not on top is clicked on, it goes to the top. 

My problem is that I cannot figure out how to move a window from the middle of the stack to the top of the stack so that it can be rendered first and appear on the top.

I'm using C++ and I'm trying to do it in a non-crappy way. 

Attached photo with some of my code (doesn't work).

stumped.PNG

Advertisement

Try something like this:


std::rotate(windows.begin(), iterator_to_clicked_window, iterator_to_clicked_window + 1);
On 2/23/2019 at 10:58 PM, alvaro said:

Try something like this:



std::rotate(windows.begin(), iterator_to_clicked_window, iterator_to_clicked_window + 1);

 

You know I just realized, I shouldn't be rotating or moving the windows directly because that means moving where they are in memory. Instead I should just move a reference or pointer to the window. The window class may grow big after all.

This worked: 


			std::rotate(winIt, winIt + 1, windows.end());

Had to be backwards with the window being last in the array because I am using painters algorithm so last drawn is on top. I also switched to unique_ptrs

Thank you.

This topic is closed to new replies.

Advertisement