Archived

This topic is now archived and is closed to further replies.

MrSandman666

How to emulate a Windows interface? (Attaching events to objects)

Recommended Posts

Hello everybody! I''ve been thinking a while about which type of interface would work best for the game I''m currently working with and I''ve come to the conclusion that it would be best to implement something like a Windows-style interface. The problem is: how do I do that? I do have an idea or to organize the data for the graphical output (a tree-like structure with windows being the basic elements, which possess buttons and other controlls...). However, the problem is: how do I attach events to these objects? How can I tell that a user clicked on a button or dragged a slider or clicked on a window handle? Does anybody have an idea how to do this? ----------------------------- "Mr Sandman bring me a dream"

Share this post


Link to post
Share on other sites
My guess:
Track the state of the mouse each ''frame'', if the mouse is clicked, then scan through your list of screen objects and see which one was clicked (by checking if the cursor was in that objects screen rect) and call that objects virtual OnClick() function.
e.g. (guessing you are using C++):


class Window
{
virtual void OnClick();
bool CursorInRect();
Rect screenRect;
};

class Button: public Window
{
void OnClick(){DepressButton();};
};

Share this post


Link to post
Share on other sites
That''s what I thought of at first but I came to think that this would be a huge performance drain once you have several windows with lots of controlls. The reason why I posted this question was that I didn''t belive this brute-force method (checking the screen-rect for every single object) would work.
However, just today I got the idea of using a tree structure, so that you can remove a lot of objects (inactive windows and their controlls) from the test. This should work out...

Thanks a lot, anyways!

-----------------------------
"Mr Sandman bring me a dream"

Share this post


Link to post
Share on other sites
You could use a signal/slot scheme

Boost : not thread safe
sigslot : ugly but informative
libsigc++ : complete

I have my own implementation I could share with you. It has been designed for size AND speed but there''s still some functionalities missing.

Hope it helps

Share this post


Link to post
Share on other sites