GUI implementation help needed
Hi all,
I am planning out how to implement the GUI system for my game and I have a question.. how to handle GUI button presses. Obviously the press must translate into some action in the game logic. The two ways I thought of are...
1. define a callback function for each button.
2. define a value for each button, which is returned when the button is pressed - then the value is ''switched'' by the game logic.
The first solution seems more elegant, any opinions on the subject?
thanks,
BrianH
I personally dislike the call back method. I find that it clutters my source files, and takes a lot more coding to accomplish it. Also, with the call back method, it is more complicated if you want to pass special parameters to the function handling the button press. You need to defind the call back as having certain arguments, then stick data in.
In my applications, I just poll the button to see if it is pressed. The logic is easy then. You can put whatever code you want in an ''if'' block, so doing just a couple lines is simple.
For example:
if( Button.IsPressed() )
{
bSetting1 = TRUE;
DoSpiffyFunction();
}
Just my opinion. I tend to stay away from callbacks when something else can be easily used.
In my applications, I just poll the button to see if it is pressed. The logic is easy then. You can put whatever code you want in an ''if'' block, so doing just a couple lines is simple.
For example:
if( Button.IsPressed() )
{
bSetting1 = TRUE;
DoSpiffyFunction();
}
Just my opinion. I tend to stay away from callbacks when something else can be easily used.
For the actual in-game controls, I would use either DirectInput or GetAsyncKeyState(). You can use either of them to get the value of any key or mouse button. If you actually want intput (like an edit box...), I would handle the WM_CHAR windows message. That is what I use for the hotkeys, because it is only called if the key isn''t repeating or if the repeat count is above a certian value. I have a little message proc function that takes the key code and a bool value representing if it is repeating or not. It is that easy Look up GetAsyncKeyState() in MSDN for how to actually use it.
--------------------
You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming
--------------------
You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming
You are unique. Just like everybody else.
"Mechanical engineers design weapons; civil engineers design targets."
Visit the ROAD Programming Website for more programming help.
--------------------
You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming
You are unique. Just like everybody else.
"Mechanical engineers design weapons; civil engineers design targets."
"Sensitivity is adjustable, so you can set it to detect elephants and other small creatures." -- Product Description for a vibration sensor
You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming
You are unique. Just like everybody else.
"Mechanical engineers design weapons; civil engineers design targets."
"Sensitivity is adjustable, so you can set it to detect elephants and other small creatures." -- Product Description for a vibration sensor
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement