Game Development Reference
In-Depth Information
You might be asking yourself two things at this point. First, this seems an awful lot of
trouble to implement a modal dialog box that can be called with one line of code.
Second, how would I do this on non-Windows platforms? There is another way
—
easier in some ways to implement, but a little more hassle to call and ask the player
a simple yes or no question. The answer is to do this asynchronously.
First, you set up a dialog box as a screen just like we did above. You instantiate it and
launch it and set up a flag in your application to basically pause the game while this
screen is active. When the player presses the button and registers a response, it sends a
message to the subsystem that needed the player to answer a question. You
'
ll see more
about how game messages can be created, sent, and interpreted in the next chapter.
Controls have lots of permutations, but most of them share similar properties. I
ve
seen push buttons, radio buttons, check boxes, combo boxes, edit boxes, expandable
menus, and all sorts of stuff. I
'
m sad to say.
Luckily, the DirectX Framework has already implemented most of the standard GUI
controls for you:
'
ve also coded quite a few of them, I
'
n
CDXUTButton
: A simple push button, like
“
OK
”
or
“
Cancel
”
n
CDXUTStatic
: A static text control for putting non-active text on a dialog
n
CDXUTCheckBox
: A check box control for selecting on/off status for different items
n
CDXUTRadioButton
: A radio button control for selecting one thing out of
many choices
n
CDXUTComboBox
: A combo box uses one line but can drop down a list box of
choices
n
CDXUTSlider
: A simple slider to do things like volume controls
n
CDXUTEditBox
: A text edit box for doing things like entering your name or a
console command
n
CDXUTIMEEditBox
: A foreign language edit box
n
CDXUTListBox
: A list of choices displayed with a scroll bar
n
CDXUTScrollBar
: A vertical or horizontal scroll bar
You can attach any of these controls to a
CDXUTDialog
object to create your own
user interface, and as you saw in the
CMessageBox
example in the previous section,
these interfaces can be modal or modeless.