Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Overlapping windows/menus  (Read 2638 times)

0 Members and 1 Guest are viewing this topic.

Naz

  • Newbie
  • *
  • Posts: 7
    • View Profile
Overlapping windows/menus
« on: November 07, 2015, 10:48:02 am »
Hi,

I am creating a 2d platformers and it is possible for the user that there are 2 or even more menus on top of each other. I do have a ui_manager class, that handles cthe mouse and keyboard input. Though what would be the best strategy if I the user clicks on a menu that has a menu behind it. Since I do get a click event with x,y. In my current code it will be the first menu in the container that does get the event passed to.

Maybe I am missing a relative 'simple' idea, since I can only come up with nasty code.

Gr

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Overlapping windows/menus
« Reply #1 on: November 07, 2015, 11:27:08 am »
Sort your container, from the more a window/menu is on top to the more it is in the background. So that the first you pick is the the one on top.

Resethel

  • Newbie
  • *
  • Posts: 22
    • View Profile
    • Email
Re: Overlapping windows/menus
« Reply #2 on: November 08, 2015, 01:08:03 am »
Sort your container, from the more a window/menu is on top to the more it is in the background. So that the first you pick is the the one on top.

Alongside that, you should also iterate through your container, sending the event, and stop when one widget react to it! Meaning that only the higher-widget which qualified for handling the event will do something!

GraphicsWhale

  • Full Member
  • ***
  • Posts: 131
    • View Profile
Re: Overlapping windows/menus
« Reply #3 on: November 08, 2015, 10:24:38 am »
Not sure what you're asking for, but you could do something like this:

void GuiManager::onClick(Vector2i position)
{
    for (auto it = menus.begin(); it != menus.end(); it++) //Iterator from front to back
    {
        if (it->doesMenuCoverPosition(position)) //Check if mouse is over the menu's covered area
        {
             it->onClick(position); //Dispatch event to the appropriate menu
             break;
        }
    }
}
 

This assumes your vectors are sorted to where the top menu menus[0] is "in front" of the other menus and menus[size-1] is "behind" the other menus. If you want, you could also swap the first element with the element containing menu that's clicked on (if it's not already the first menu) so if it's hidden behind another menu (or more) and you click on a small piece of it it will bring itself to the top and display over the over menus.

Naz

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Overlapping windows/menus
« Reply #4 on: November 13, 2015, 11:52:08 am »
Thanks for all the input, I had a busy week last week, but today I found some time to implent it. I did it as follows, if you ahve any tips/advice on my code, please share :) Tho it is not done yet and there is some debug stuff in there aswell, the colors that are filled from id and stuff. Later I will try to use a nice texture for the borders/titlebar aswell.

The basic idea is, every ui is on a panel. The panels are in a ui_manager, which handles all the events.

ui_manager, so the game_state has nothing to do with ui stuff, it just has a instance of the manager:
(click to show/hide)

This is the panel class, every ui is basically on a panel

(click to show/hide)

And this is how I call/init it, not this is just a copy paste of usefull code

(click to show/hide)

Note that the classes are not yet done, I acn think of some optimaztions and stuff, but the general idae is there.