Game Development Reference
In-Depth Information
'
and it works a hell of a lot better than hard-coded positions and widths. Now we
re
ready to add controls to the dialog member, and you ' ll see that in the calls to Add-
Static() for the message text and AddButton() for the buttons.
One thing you should notice right away in the call to add buttons is no hard-coded text:
m_UI.AddButton( IDOK, g_pApp->GetString(IDS_OK).c_str(),
iX, iY - border, btnWidth, btnHeight );
I mentioned this back in the application layer discussion. Instead of seeing the naked
text
you see a call into the application layer to grab a string identified by IDOK .
The application layer is responsible for grabbing text for anything that will be pre-
sented to the player because you might have multiple foreign language versions of
your game. You could create this text grabber in any number of ways, but for PC
games I prefer using an XML file with all the strings and their hot keys defined.
The cool thing about XML files is they are easy for translators to edit, and you can
easily add XML files to your game as you support more languages. They even sup-
port Asian languages like Chinese.
In the event of a device restoration event like a full-screen/windowed mode swap, it
OK,
s
a good idea to tell the DirectX dialog how big it is and where it is on the screen,
which you can do through the VOnRestore API :
'
HRESULT MessageBox::VOnRestore()
{
m_UI.SetLocation( m_PosX, m_PosY );
m_UI.SetSize( m_Width, m_Height );
return S_OK;
}
The render method for our screen class simply calls CDXUTDialog::OnRender .If
you create your own GUI system, this is where you
'
d iterate through the list of con-
trols and draw them:
HRESULT MessageBox::VOnRender(double fTime, float fElapsedTime)
{
m_UI.OnRender( fElapsedTime );
return S_OK;
};
You feed Windows messages to the DirectX GUI controls through the VOnMsgProc()
method. If you create your own GUI, you
d have to iterate through your controls and
have them process messages. A good example of that would be to highlight the con-
trol if the mouse moved over it or change the graphic to depress the control if the
mouse went down over the control
'
'
s area:
Search WWH ::




Custom Search