1
SFML projects / sigui = Simple Includable GUI
« on: March 04, 2011, 07:23:28 am »
well, since you're feeling adventurous... :twisted: ... lets jump right to using function calls.
place this before the main statement
put this after GUIinitialize
and put this in the event handler
Now when you press the escape key, the "confirm exit without saving dialog" will pop up.
:? I see that I need to change buttons so that "toggle" is false by default, since that is the typical behavior desired.
While this is bit complicated for a first taste, it does show how little you need to have in the game loop if you use function calls.
Still adventurous? Add the lines
to add color clues to the user!
place this before the main statement
Code: [Select]
// GUI invoked functions
void CloseGUIform(GUIwidget *pWidget) // close the form
{
// find parent form
while (pWidget->parent != NULL) pWidget = pWidget->parent; // find uber parent
if (pWidget->thisType == tguiForm) static_cast<GUIform*>(pWidget)->close(); // if uber parent was a form (it should be!), close it
}
void getoutahere(GUIwidget *pWidget) // close the program
{
// find parent form
while (pWidget->parent != NULL) pWidget = pWidget->parent; // find uber parent
if (pWidget->thisType == tguiForm) static_cast<GUIform*>(pWidget)->parentApp->Close(); // close the application.
}
put this after GUIinitialize
Code: [Select]
GUIform ExitDialog(App.GetWidth()/2-210, App.GetHeight()/2-100, 440, 200); // create 420x200 dialog in middle of screen
ExitDialog.showTitleBar = false; // no need for resizing, moving or closing this dialog
ExitDialog.bevelInner = bsDown; // makes it a little more decorative
GUIlabel exitText(&ExitDialog, 20, 30, "Changes unsaved, please confirm Exit (without saving).");
GUIbutton exitCancelBtn(&ExitDialog, 100, 100, "Cancel");
GUIbutton exitConfirmBtn(&ExitDialog, 240, 100, "Exit");
exitConfirmBtn.OnClick = &getoutahere;
exitCancelBtn.OnClick = &CloseGUIform;
exitCancelBtn.toggle = false;
exitConfirmBtn.toggle = false;
and put this in the event handler
Code: [Select]
if (Event.Type == sf::Event::KeyPressed)
{
if (Event.Key.Code == sf::Key::Escape) // Escape key : exit
{
ExitDialog.show();
}
}
Now when you press the escape key, the "confirm exit without saving dialog" will pop up.
:? I see that I need to change buttons so that "toggle" is false by default, since that is the typical behavior desired.
While this is bit complicated for a first taste, it does show how little you need to have in the game loop if you use function calls.
Still adventurous? Add the lines
Code: [Select]
exitConfirmBtn.faceColor = sf::Color(sf::Color::Red);
exitCancelBtn.faceColor = sf::Color(sf::Color::Green);
exitConfirmBtn.useParentColors = false;
exitCancelBtn.useParentColors = false;
to add color clues to the user!