Advertisement
Guest User

TGUI Forum Bug Example

a guest
May 30th, 2016
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. include <TGUI/TGUI.hpp>
  2.  
  3. void receiveMessage(tgui::ChatBox::Ptr chatBox, sf::Clock& clock)
  4. {
  5.     while (true)
  6.     {
  7.         std::size_t number = 0;
  8.         while (clock.getElapsedTime().asMilliseconds() >= 100)
  9.         {
  10.             clock.restart();
  11.             chatBox->addLine(std::to_string(number++));
  12.         }
  13.     }
  14. }
  15.  
  16. int main()
  17. {
  18.     sf::RenderWindow window({ 400, 400 }, "TGUI Forum Bug Example");
  19.     tgui::Gui gui(window);
  20.  
  21.     tgui::ChatBox::Ptr chatBox = std::make_shared<tgui::ChatBox>();
  22.     chatBox->setTextSize(18);
  23.     chatBox->setSize(400, 400);
  24.     gui.add(chatBox);
  25.  
  26.     sf::Clock clock;
  27.     sf::Thread thread(std::bind(&receiveMessage, chatBox, std::ref(clock)));
  28.     thread.launch();
  29.  
  30.     while (window.isOpen())
  31.     {
  32.         sf::Event event;
  33.         while (window.pollEvent(event))
  34.         {
  35.             if (event.type == sf::Event::Closed) window.close();
  36.             gui.handleEvent(event);
  37.         }
  38.  
  39.         window.clear();
  40.         gui.draw();
  41.         window.display();
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement