Sign in to follow this  

GUI button clicking.

This topic is 4095 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I am trying to make a GUI for my game. I don't know if the way im doing is is the most efficent. For example. I have made a button class. GUIButton. The button contains a Render Methold ( to draw it, called from the renderloop ) and a MouseMove(MouseEventArgs e), MouseDown(MouseEventArgs e) methold. In the form class I've 2 events.. and both look like this: void this_mouseDown(object sender, MouseEventArgs e) { gUIButton.MouseDown(e); } Are the other ways to implant this system ? ( I don't like this one :D) Thanks for (trying :'() to read this!

Share this post


Link to post
Share on other sites
I'm in the process of writing a (small) multi-platform GUI system, so that I don't have to worry about Windows to Linux conversions at uni next semester. I decided on writing a generic EventCommander pattern. It has a list of Event Handlers, which may be functions, or even member functions (bound to an instance of a class with boost::bind). What this means is that I can then derive my GUIButton from EventCommander<MouseEvent>, and have many instances of GUIButton in the code. Something like this:



void handle_A(const MouseEvent& e)
{
}

class SomethingElse
{
public:
void handle_B(const MouseEvent& e)
{
}
};

int main()
{
SomethingElse se;
GUIButton g;

g.addHandler(&handle_A);
g.addHandlerMF(&se, &SomethingElse::handle_B);

for (;;)
{
// main loop
}
}



And now, whenever a mouse event is sent via the GUI to that particular button (button object g), it will call both handle_A and handle_B (with the instance se), which will handle the event (first in, first served).

Your other option is to have a class like GUIButton, with lots of onClick-like virtual functions, that people then have to write overloads for. This means, however, that you have to write a whole new subclass for each different button you want. That's why I went with the above. Hope that helps.

Share this post


Link to post
Share on other sites

This topic is 4095 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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