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->GetShow()) //dont do any checks if the window is hidden.
{
continue;
}
if(_mousex >= WindowList->GetX() && _mousex <= (WindowList->GetX() + WindowList->GetW() ))
{
if(_mousey >= WindowList->GetY() && _mousey <= (WindowList->GetY() + WindowList->GetH()))
{
CurrentWindow = i;
WindowList->SetMouseDown(true);
WindowList->SetDifference(_mousex - WindowList->GetX(), _mousey - WindowList->GetY());
for(unsigned int itemnum = 0; itemnum < WindowList->WindowItemList.size(); itemnum++)
{
if(_mousex >= WindowList->WindowItemList[itemnum]->GetX() && _mousex <= (WindowList->WindowItemList[itemnum]->GetX() + WindowList->WindowItemList[itemnum]->GetW()))
{
if(_mousey >= WindowList->WindowItemList[itemnum]->GetY() && _mousey <= (WindowList->WindowItemList[itemnum]->GetY() + WindowList->WindowItemList[itemnum]->GetH()))
{
if(!WindowList->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->WindowItemList[itemnum]->GetType() == ITEM_TYPE_CHECKBOX)
{
WindowList->WindowItemList[itemnum]->Toggle();
}
}
}
}
}
}
}
}
}