• 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
polyfrag

Custom GUI input events propagation

8 posts in this topic

My GUI is made up of views/layers. Like, I might have a view for the main menu and one for the credits.

 

Each view has widgets.

 

Now, I've found it necessary to have a "pre" call for any mouse input event and a normal call. For example, I might call prelbuttondown (left mouse button down) on all the views, which propagates to all their widgets.

 

The reason is that if I have a dropdown list selector that covers up a widget (let's say a button) that comes after it, the input event will first get intercepted by the button covered up by the dropdown menu. The widgets input methods are called in reverse order, since the last one will be drawn last and be on top of the other ones.

 

This also applies to drawing. I have a draw() method and a draw2() method that is called after all the draw() methods because even though the dropdown list is drawn before the button, it might have a dropdown menu opened that will cover up other widgets.

 

I was told I should have a variable that keeps track of the active widget. That way I can check the active widget for input event interception first. And I suppose I could call an overdraw() method on the active widget for any drawing that has to be done on top of the other widgets. 

 

But this brings more headache; I only propagate events to views that are open and there's no way to get the view that a widget belongs to, and a widgets can have whole hierarchies of subwidgets. Also, if I have only one active widget with an overdraw() method being called, how do I do label text that appears when the mouse hovers over a button?

 

Is there an easy solution? What is the correct way to do this?

0

Share this post


Link to post
Share on other sites

Turning the Views into Widgets would simplify things.

 

About the z-order and popping up a new widget: I could push a new list box selector widget at the highest level, eliminating the input and drawing order problem. But if I set its parent Widget to be the dropdown list selector that created it, that would mess up the hierarchy, because the parent Widget doesn't have it as a child. Maybe add a callback Widget pointer to the child? I need some way for the parent widget to know when an item has been selected. 

 

I don't use the z-buffer in my 2D orthographic drawing.

0

Share this post


Link to post
Share on other sites

What if on an input event the child widget calls the callback (parent) widget and the parent widget deletes the the child widget while its child's function is still on the stack?

 

And the STL list would be modified while it was still being traversed.

0

Share this post


Link to post
Share on other sites

Signals and slots (which are fancy callback functions), or regular callback functions.

 

If the parent widget is creating the popup widget, it should already have a pointer to it in whatever function/logic/script created the popup widget anyway.

 

And nothing is stopping the parent widget from owning it as a child - it's just that (in Qt's implementation) the child has the special widget flag: 'Popup' (this is not a special type of widget, this is a flag available to any widget that changes the behavior).

 

Logic-wise, your program could do something like:

//Process the popups' hierarchies:
for-all-popup-flagged-widgets:
     popupWidget->processEvents() //Including non-popup children widgets.

//Then process the regular hierarchy:
rootWidget->processEvents() //Including non-popup children widgets.

About deleting: Set a 'delete' flag, or push a 'DeleteMe' event. Delete it at the beginning of the next frame, or when the event is processed.

My own non-Qt game logic code uses a 'delete' flag that is processed at the beginning of the next frame. Qt has the base abstract widget type have a 'deleteLater()' function, which probably does something similar.

Edited by Servant of the Lord
0

Share this post


Link to post
Share on other sites
Another problem:

If I have a bunch of buttons for a list of selected units in an RTS, with a highlight effect when the mouse hovers over them, how do I ensure that only one of them is highlighted. If the mousemove event is intercepted when the mouse goes over a button, it might still be over another button if they are stacked.

The way I do it now is with 'pre' and 'post' event propagation as I said - the premousemove method cannot intercept the mouse event and only sets the button's state to not mouse over, and the (post) mousemove method intercepts the mouse event if mouse is over..

Keeping track of which widget the mouse is over in one variable seems like the solution.


Logic-wise, your program could do something like:

//Process the popups' hierarchies:for-all-popup-flagged-widgets:     popupWidget->processEvents() //Including non-popup children widgets.//Then process the regular hierarchy:rootWidget->processEvents() //Including non-popup children widgets.

So basically have a pre and post event like I have? Edited by polyfrag
0

Share this post


Link to post
Share on other sites
Doesn't seem like there's a much better way to do it than what I have. I was going to finish an article about it. Maybe I'll do that soon.

Would be interesting to know how Windows or any other OS does it.
0

Share this post


Link to post
Share on other sites

I do use pre- and post- events for logic and drawing and input, but that's not what I was suggesting above (I use it more for customizing behavior of individual widgets).

 

I'm not sure how Qt handles that specific case, but what I was suggesting is treating popups as their own "root" of their children. Even though they might have parents and might be owned just like other widgets, you can use that popup flag to treat them differently. It can be used so all pop-up widgets are treated (only when drawing, or processing events) as entirely separate hierarchies of widgets.

 

[b][Edit:][/b] An illustration of what I mean:

 

popup_A.png 

 

popup_B.png

 

Just a thought - that's how I'd begin to explore a solution.

Edited by Servant of the Lord
0

Share this post


Link to post
Share on other sites

Popups are nasty things :)

 

Popups come in different flavours, one would be tool tips, others the opened listbox of a combo box.

 

In my GUI system childs are usually truncated to their parent. Popups are basically added as childs of the root component (the root widget in SotLs diagram). Popups are then tied to their source component in a owner/owned relationship.

 

To allow only one child being influenced by a mouse event this is handled by the parent control. The parent control cycles through its childs and chooses the first hit control (and then stops searching). This is done recursively and thus ends up either with nothing or the chosen control.

Esp. for hottips the control itself can define if it is actually clickable (you don't want to focus a tool tip), so it can work as click through.

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