Jump to content

  • Log In with Google      Sign In   
  • Create Account


UI: move-able windows (z-order)


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 Nausea   Members   -  Reputation: 257

Like
0Likes
Like

Posted 29 March 2013 - 06:19 AM

Hey!

 

I've run into a problem with my noobish UI setup. I have a Vector that stores all my windows. When the mouse is clicked I go through the windows vector and check if the mouse is inside any of the windows. If it is i move that window relative to the mouse position.

 

Now my problem is: How do I order the window selected to be in front? and since the mouse can be inside 2 windows during my check the last window it's inside will always be the one selected. 

 

I know I should probably be using a z-order of some kind, but I just can't work out where to set it for a window and how to adjust the other accordingly.

 

I'll just post some code of the way I check if the mouse is inside a window.

void CGame::OnLButtonDown(int _mousex, int _mousey)
{
	

	for(unsigned int i=0; i < WindowList.size(); i++)
	{
	
		if(!WindowList[i]->GetShow()) //dont do any checks if the window is hidden.
		{
		
			continue;
		
		}

		if(_mousex >= WindowList[i]->GetX() && _mousex <= (WindowList[i]->GetX() + WindowList[i]->GetW() ))
		{
		
			if(_mousey >= WindowList[i]->GetY() && _mousey <= (WindowList[i]->GetY() + WindowList[i]->GetH()))
			{


				CurrentWindow = i;
				WindowList[i]->SetMouseDown(true);
				WindowList[i]->SetDifference(_mousex - WindowList[i]->GetX(), _mousey - WindowList[i]->GetY());

				
				for(unsigned int itemnum = 0; itemnum < WindowList[i]->WindowItemList.size(); itemnum++)
				{
				
					if(_mousex >= WindowList[i]->WindowItemList[itemnum]->GetX() && _mousex <= (WindowList[i]->WindowItemList[itemnum]->GetX() + WindowList[i]->WindowItemList[itemnum]->GetW()))
					{
					
						if(_mousey >= WindowList[i]->WindowItemList[itemnum]->GetY() && _mousey <= (WindowList[i]->WindowItemList[itemnum]->GetY() + WindowList[i]->WindowItemList[itemnum]->GetH()))
						{
							
								if(!WindowList[i]->WindowItemList[itemnum]->GetActive()) //if the item is not an active item (such as a divider), don't do any checks for it.
								{
									continue;
								}
								else
								{
									
									OverActiveItem = true;

									if(WindowList[i]->WindowItemList[itemnum]->GetType() == ITEM_TYPE_CHECKBOX)
									{
										WindowList[i]->WindowItemList[itemnum]->Toggle();
									}

								
								
								}
								

						
						}
					
					}

				
				}

				

			}
		
		}
		
	}


}


 

 



Sponsor:

#2 Waterlimon   Crossbones+   -  Reputation: 2456

Like
1Likes
Like

Posted 29 March 2013 - 06:34 AM

I would, in each window, store a index to the window in front of it.

 

W1

v

 

W2

v

 

W3

 

So if you were to click on W2, you should swap the index of W2 and W3, and make W1 point to W3

 

W1

v

 

W3

v

 

W2

 

 

So its kind of a linked list. If you make it doubly linked (indices to the other dir. too) you could start from the topmost window (perhaps always store the top window index somewhere) and stop on the first window which the mouse is on top of to find the window you click.

 

If you want to use the same system for buttons and stuff, i would make each of those W's able to contain many same-depth elements (eg. buttons on the same window)

 

I suggest you also google for how to handle this.

 

EDIT:

Another way to handle it would be to have a separate list which contains indices to the list of the windows in depth order. This way you dont need the windows to know about their depth.

 

So

-List of windows

-List of indices to windows, in depth order

 

To move a window in depth, you just remove the index, move all the indices above down by 1, and place it at the top. However this requires you to find the window from the depth sorted list first, but if you just used the depth list to find which window you clicked on, you should have that information available.


Edited by Waterlimon, 29 March 2013 - 06:39 AM.

o3o


#3 Nausea   Members   -  Reputation: 257

Like
0Likes
Like

Posted 29 March 2013 - 06:49 AM

Thank you for your answer. Could you go into more detail on the "list of indices" thing? Sorry my first language is not English so I don't fully understand what you mean by it.

Especially the "indices" part :P


Edited by Nausea, 29 March 2013 - 06:49 AM.


#4 Amr0   Members   -  Reputation: 1082

Like
1Likes
Like

Posted 29 March 2013 - 06:57 AM

Instead of storing the window pointers in a vector, store them in the list. Mouse testing is then done from top to bottom, and drawing is done from bottom to top. Moving a window to the top requires that the window be removed and added to the front of the list.

 

On an unrelated note, the code you posted is somewhat hard to follow because of all the nested code blocks. Try to make it more flat. For example,

 

 

 

if(!WindowList[i]->WindowItemList[itemnum]->GetActive())
{
continue;
}
else
{/*do stuff*/}
 

is equivalent to

if(!WindowList[i]->WindowItemList[itemnum]->GetActive())
    continue;
/*do stuff*/


#5 Waterlimon   Crossbones+   -  Reputation: 2456

Like
0Likes
Like

Posted 29 March 2013 - 07:20 AM

Ok, so lets say you have the vector of windows

 

Vector<Window> windows; //9001 windows here

 

Now, you have another list, which stores the indices of the windows (to the window vector) in depth order

 

Vector<int> windowsSortedByDepth;

 

So lets say you have a window at windows[30]. As such, the index of the window is 30.

If this windows is at the top of windowsSortedByDepth, it means its the top window

 

windowsSortedByDepth[windowsSortedByDepth.size() - 1] = 30 //window 30 is in front

 

So, to find the top window itself, you can do

 

windows[ windowsSortedByDepth[windowsSortedByDepth.size() - 1] ]

 

for example to get its size and position so you can check against the mouse.

 

You would then iterate this depth sorted list when finding out where you clicked, and the first window you find will be the top window your mouse is on top of, so now you can move the index of the window in the depth list to the front of the depth list (and fill the hole you created)


o3o


#6 Nausea   Members   -  Reputation: 257

Like
0Likes
Like

Posted 29 March 2013 - 07:27 AM

Instead of storing the window pointers in a vector, store them in the list. Mouse testing is then done from top to bottom, and drawing is done from bottom to top. Moving a window to the top requires that the window be removed and added to the front of the list.

On an unrelated note, the code you posted is somewhat hard to follow because of all the nested code blocks. Try to make it more flat. For example,


if(!WindowList[i]->WindowItemList[itemnum]->GetActive()){continue;}else{/*do stuff*/}
is equivalent to
if(!WindowList[i]->WindowItemList[itemnum]->GetActive())    continue;/*do stuff*/

Thank you so much for your answer :) I will try to make this work. And thanks for your critique on my code blocks.

edit: I got it working thanks to you :) Happy times!

Edited by Nausea, 29 March 2013 - 10:17 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS