I started same topic on SFML forum. But i think this topic should be written here since its tGui realted.
so:
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(400, 300), "win");
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed) window.close();
}
window.setPosition(sf::Vector2i(100 + rand() % 25, 100 + rand() % 25));
window.clear(sf::Color::Black);
window.display();
}
return 0;
}
that code is working, its pure SFML. It produces shaking the entire window.
Then implemented in SFML with tGui doesnt work:
while (screen.isOpen())
{
sf::Event event;
while (screen.pollEvent(event))
{
if (event.type == sf::Event::Closed)
screen.close();
// Pass the event to all the tgui stuff
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 username and password
tgui::EditBox::Ptr editBoxUsername = gui.get("Username");
tgui::EditBox::Ptr editBoxPassword = gui.get("Password");
sf::String username = editBoxUsername->getText();
sf::String password = editBoxPassword->getText();
if (username == "" && password == "")
{
// clear the entire window and set new stuff to draw.
}
}
if (callback.id == 2)
{
screen.setPosition(sf::Vector2i(100 + rand() % 25, 100 + rand() % 25));
} // end if callback.id == 2
}
screen.clear();
// Draw all created tgui stuff
gui.draw();
screen.display();
}
So basic idea is: when somebody click login with wrong username or password i want window to shake left - right - left - right like in most linux program when you miss the pasword / username.
if (callback.id == 2) - Thats tGui button, its button [labeled: exit] but i will implement stuff there and when its working will move it to (callback.id == 1) which is actual login button. So my code wont shake the window. It just move the screen one time. If needed i can provide entire code, or entire working directory.