If you no longer need objects then you can use the remove function from Gui to remove them. And then you just create the new objects like you created the old ones.
But it is probably better to use panels. So you create a panel for the login screen and a panel for your other screen. In those panels you add the objects you want (just like you added them to the gui). And then you just hide all panels except the login screen. When the login button is clicked, all that you have to do is hide the panel with your login screen and show the other one.
Edit: Here is a small example of what I am trying to say:
But it is probably better to use panels. So you create a panel for the login screen and a panel for your other screen. In those panels you add the objects you want (just like you added them to the gui). And then you just hide all panels except the login screen. When the login button is clicked, all that you have to do is hide the panel with your login screen and show the other one.
Edit: Here is a small example of what I am trying to say:
Code (cpp) Select
#include <TGUI/TGUI.hpp>
void loadLoginScreen( tgui::Gui& gui )
{
tgui::Panel::Ptr loginScreen(gui, "LoginScreen");
loginScreen->setSize(800, 600);
// Create the background image
tgui::Picture::Ptr picture(*loginScreen);
picture->load("xubuntu_bg_aluminium.jpg");
picture->setSize(800, 600);
// Create the username label
tgui::Label::Ptr labelUsername(*loginScreen);
labelUsername->setText("Username:");
labelUsername->setPosition(200, 100);
// Create the password label
tgui::Label::Ptr labelPassword(*loginScreen);
labelPassword->setText("Password:");
labelPassword->setPosition(200, 250);
// Create the username edit box
tgui::EditBox::Ptr editBoxUsername(*loginScreen, "Username");
editBoxUsername->load("TGUI/widgets/Black.conf");
editBoxUsername->setSize(400, 40);
editBoxUsername->setPosition(200, 140);
// Create the password edit box (we will copy the previously created edit box)
tgui::EditBox::Ptr editBoxPassword = loginScreen->copy(editBoxUsername, "Password");
editBoxPassword->setPosition(200, 290);
editBoxPassword->setPasswordCharacter('*');
// Create the login button
tgui::Button::Ptr button(*loginScreen);
button->load("TGUI/widgets/Black.conf");
button->setSize(260, 60);
button->setPosition(270, 440);
button->setText("Login");
button->bindCallback(tgui::Button::LeftMouseClicked);
button->setCallbackId(1);
}
void loadOtherScreen( tgui::Gui& gui )
{
tgui::Panel::Ptr otherScreen(gui, "OtherScreen");
otherScreen->setSize(800, 600);
// Create the background image
tgui::Picture::Ptr picture(*otherScreen);
picture->load("xubuntu_bg_aluminium.jpg");
picture->setSize(800, 600);
}
int main()
{
// Create the window
sf::RenderWindow window(sf::VideoMode(800, 600), "TGUI window");
tgui::Gui gui(window);
// Load the font (you should check the return value to make sure that it is loaded)
gui.setGlobalFont("TGUI/fonts/DejaVuSans.ttf");
// Load the widgets
loadLoginScreen(gui);
loadOtherScreen(gui);
// The login screen is the only panel that should be visible
gui.get("LoginScreen")->show();
gui.get("OtherScreen")->hide();
// Main loop
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
// Pass the event to all the widgets
gui.handleEvent(event);
}
// The callback loop
tgui::Callback callback;
while (gui.pollCallback(callback))
{
// Make sure tha callback comes from the button
if (callback.id == 1)
{
// Get the login screen
tgui::Panel::Ptr loginScreen = gui.get("LoginScreen");
// Get the username and password
tgui::EditBox::Ptr editBoxUsername = loginScreen->get("Username");
tgui::EditBox::Ptr editBoxPassword = loginScreen->get("Password");
sf::String username = editBoxUsername->getText();
sf::String password = editBoxPassword->getText();
// Show the other screen
loginScreen->hide();
gui.get("OtherScreen")->show();
}
}
window.clear();
// Draw all created widgets
gui.draw();
window.display();
}
return EXIT_SUCCESS;
}