Sign in to follow this  
derefed

Problems with structuring a GUI

Recommended Posts

Okay, so I've decided to make a mostly text-based game, but needed a minimal GUI to facilitate text entry and viewing and such. I was playing around with wxWidgets for a bit, but it got to be too complicated for what I needed. I would've had to use threads to make my game code run in parallel, and the display was acting up in weird ways. I decided that if I wrote my own GUI code, I could keep a better control over all of that, so I went with SDL in C++, with which I have some experience. Building the GUI has been all right thus far; I have a widget class which all controls derive from, I have a GUI class which holds all controls as widget pointers and calls their handle_input functions when it receives input, etc.. My problem is that I have no idea how to properly structure my GUI in terms of objects and such beyond that. I want to be able to create an event table like in wxWidgets, where I can supply an ID to a control and a function pointer to a handler, and it will be called when a certain event fires. I believe I have all the code written up to do that, except for the function pointer part. I've written it up, but I'd like the handler function to be a member of my Frame class, which holds all the controls for my particular app. Passing &GUI_Frame::Handler as a param to the Set_Callback() function doesn't exactly work though, because it's not expecting a member function. Changing the code of Set_Callback() to accept a function from GUI_Frame also fails, because it creates a cyclic dependency. Basically, I have the feeling that I'm going about this all the wrong way. I just want to be able to create some controls, and create some special functions for any given app that uses the GUI that are called when certain events are fired. I'd rather not use inheritance, as I don't want to have to make a separate class for each control that only requires a minor change in handling code. If anyone has any suggestions, or I haven't explained this well enough and need me to be more elaborate about certain details, I'd be grateful.

Share this post


Link to post
Share on other sites
Quote:
Original post by LessBread
If your game is mostly text based, why not simply use the console?


The nature of the game is something like a MUD, only for single player. As such, in-game events happen in real-time, and are not dependent on when next the user enters in their command.

I've thought long and hard on how to implement this, and this is really the best way that suits my project. I just need some guidance in terms of event handling in a custom GUI. I'll no doubt be attempting a graphical game some time in the near future, and will need those GUI skills there as well. I've looked at a bunch of tutorials on the net, but I can't really seem to find an answer to my problem.

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