Callback help!
« on: 04 July 2013, 14:47:02 »
Hello! I have writed next code:
Code: [Select]
Handler::Handler()
{
window.create(sf::VideoMode(800,600),"SpeedCuber Challenge");
window.setFramerateLimit(60);

Menu menu(window);

while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
                window.close();
}
menu.callback();
window.clear(sf::Color(203,201,207));
menu.draw();
window.display();
}
}

Menu::Menu(sf::RenderWindow& window): guiWindow(window)
{
stage = 0;

guiWindow.globalFont.loadFromFile("res/Font/DejaVuSans.ttf");
changeMenu();
}

void Menu::draw()
{
guiWindow.draw();
}

void Menu::callback()
{
tgui::Callback callback;
    while (guiWindow.getCallback(callback))
    {
#ifdef DEBUG
    std::cout << callback.callbackID << "\n";
#endif
    switch (callback.callbackID)
        {
            case 2:
            {
            // Make sure the button was pressed
            if (callback.trigger == tgui::Callback::mouseClick)
            {
            ++stage;
            changeMenu();
            exit(1);
            }
            break;
            }
        }
    }
}

void Menu::changeMenu()
{
switch (stage)
{
case 0:
{
guiWindow.removeAllObjects();

tgui::Button* BTNserver = guiWindow.add<tgui::Button>();
BTNserver->load("res/Button/Black");
BTNserver->setSize(200,100);
BTNserver->setPosition(400-BTNserver->getSize().x/2,100);
BTNserver->setText("Server");
BTNserver->callbackID = 1;

tgui::Button* BTNclient = guiWindow.add<tgui::Button>();
BTNclient->load("res/Button/Black");
BTNclient->setSize(200,100);
BTNclient->setPosition(400-BTNclient->getSize().x/2,200);
BTNclient->setText("Client");
BTNclient->callbackID = 2;
break;
}
case 2:
{
guiWindow.removeAllObjects();

tgui::Label* LBLaddress = guiWindow.add<tgui::Label>();
LBLaddress->setText("Address:");
LBLaddress->setPosition(1,1);

tgui::EditBox* EDBaddress = guiWindow.add<tgui::EditBox>();
EDBaddress->load("res/EditBox/Black");
EDBaddress->setPosition(20,20);
EDBaddress->setSize(100,40);
break;
}
}
}

And can't figure out how to make the BTNclient(ID=2) to work... When I click on him doesn't happen nothing. When I click need to increment the stage and redraw another objects( changeMenu()).
The code is the sample from my 2 classes( Handler, Menu).

----
I'm on Linux and tried to install it bun when I finished and tryed the example I got error: "TGUI/TGUI.hpp can't find". So the headers(include folder) can't be finded so I verified in /usr/local/include and there was no TGUI folder with headers so I copied the folder from include and putted in /usr/local/include to can figure out the problem.

*

texus

  • *****
  • 1161
    • View Profile
    • Texus's Blog
Re: Callback help!
« Reply #1 on: 04 July 2013, 14:56:51 »
I didn't look at the code in detail, but you aren't calling window.handleEvent in your event loop which is probably the problem.

In tgui v0.5 the headers aren't installed and you have to either copy the folder yourself like you did or set the path to the include folder in your code blocks settings (or as '-I' parameter to the compiler when using g++ directly).
In tgui v0.6 I have already changed it so that the files are installed correctly when calling "make install".

Re: Callback help!
« Reply #2 on: 04 July 2013, 15:02:13 »
Thanks!