• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Nausea

UI: move-able windows (z-order)

5 posts in this topic

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();
									}

								
								
								}
								

						
						}
					
					}

				
				}

				

			}
		
		}
		
	}


}


 

 

0

Share this post


Link to post
Share on other sites

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
1

Share this post


Link to post
Share on other sites

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
0

Share this post


Link to post
Share on other sites

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*/
1

Share this post


Link to post
Share on other sites

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)

0

Share this post


Link to post
Share on other sites

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
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0