Jump to content
  • Advertisement
Sign in to follow this  
ManaStone

Need advice for building a window/button class.

This topic is 4932 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

I am in the process of building a window and button class. Should I just make one button class and have the RightClick() and LeftClick() process a function pointer data member, or should I have all of my buttons I plan to use derived off of the basic button class and use virtual functions? I’d appreciate any advice on designing these classes.

Share this post


Link to post
Share on other sites
Advertisement
Well, I assume you're trying to build a GUI system yourself, and that you need a button class.

I would not go for any of the solutions you're giving. The first one is a bit messy, and you'll be quickly lost in your function calls. The second may look nicer, but you would need to create as many classes as you have buttons, which is too much.

So, just copy what exists and work well!

Windows uses an event system. This means that when you click on the button, an event is generated, which is added to an event queue. These events are then dispatched, and can call functions.

If your buttons are all in the same screen (like a configuration screen, for example), you can have a general event queue at the screen level. When you create a button, you give them an ID, and a reference to the event queue. When the user clicks on the button, the button class adds the event "clicked" to the queue. Your screen class will have a method update, that you call from your general main loop. You extract the events, and make actions depending on it, for example changing a number on your Configuration screen.

The nice thing about events is that you can very easely add controls: just create a new control class, add the corresponding event codes, and process them into your main screen.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!