Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [SOLVED]tgui 6.0 editbox don't work  (Read 2026 times)

0 Members and 1 Guest are viewing this topic.

Soul

  • Newbie
  • *
  • Posts: 44
    • View Profile
[SOLVED]tgui 6.0 editbox don't work
« on: April 06, 2013, 11:42:20 pm »
hey, i have a little problem with editbox it doesn't work...
when i compile sample project it work, but in my game not...
what is wrong?

#include "include/Client.h"
#include <TGUI/TGUI.hpp>
int main()
{
    Client client;
    sf::RenderWindow window(sf::VideoMode(800, 600), "Client");
    tgui::Form Menu( window );
    tgui::Form Create( window );
    Menu.setGlobalFont( "Font/djvs.ttf");
    Create.setGlobalFont( "Font/djvs.ttf");
    tgui::Button::Ptr connect(Menu);
    tgui::Button::Ptr disconnect(Menu);
    tgui::Button::Ptr createaccount(Menu);
    tgui::Button::Ptr create(Create);
    tgui::Label::Ptr labelUsername(Create);
    labelUsername->setText("Username:");
    labelUsername->setPosition(200, 100);
    tgui::Label::Ptr labelPassword(Create);
    labelPassword->setText("Password:");
    labelPassword->setPosition(200, 250);
    tgui::Label::Ptr labelMail(Create);
    labelMail->setText("E-Mail:");
    labelMail->setPosition(200, 400);
    tgui::EditBox::Ptr editBoxUsername(Create, "Username");
    editBoxUsername->load("gui/EditBox/Black");
    editBoxUsername->setSize(400, 40);
    editBoxUsername->setPosition(200, 140);
    tgui::EditBox::Ptr editBoxPassword = Create.copy(editBoxUsername, "Password");
    editBoxPassword->setPosition(200, 290);
    editBoxPassword->setSize(400, 40);
    editBoxPassword->setPasswordChar('*');
    tgui::EditBox::Ptr editBoxMail(Create, "E-Mail");
    editBoxMail->load("gui/Editbox/Black");
    editBoxMail->setSize(400,40);
    editBoxMail->setPosition(200, 440);

    createaccount->load("gui/Button/Black");
    createaccount->setSize(260, 60);
    createaccount->setPosition(270, 280);
    createaccount->setText("Create Account");
    createaccount->bindCallback(tgui::Button::LeftMouseClicked);
    createaccount->setCallbackId(1);
    connect->load("gui/Button/Black");
    connect->setSize(260, 60);
    connect->setPosition(270, 340);
    connect->setText("Connect");
    connect->bindCallback(tgui::Button::LeftMouseClicked);
    connect->setCallbackId(2);
    disconnect->load("gui/Button/Black");
    disconnect->setSize(260, 60);
    disconnect->setPosition(270, 400);
    disconnect->setText("Disconnect");
    disconnect->bindCallback(tgui::Button::LeftMouseClicked);
    disconnect->setCallbackId(3);
    create->load("gui/Button/Black");
    create->setSize(260, 60);
    create->setPosition(270, 700);
    create->setText("Create Account");
    create->bindCallback(tgui::Button::LeftMouseClicked);
    create->setCallbackId(1);
    int menu = 2;
    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();

            Menu.handleEvent(event);
        }

        tgui::Callback callback;
        switch( menu)
        {
            case 1:
            {
                while( Create.pollCallback(callback))
                {
                    switch( callback.callbackId)
                    {
                        case 1:
                        {
                            editBoxUsername = Create.get("Username");
                            editBoxPassword = Create.get("Password");
                            editBoxMail = Create.get("E-Mail");
                            sf::String username = editBoxUsername->getText();
                            sf::String password = editBoxPassword->getText();
                            sf::String email = editBoxMail->getText();
                            menu==2;
                            break;
                        }
                    }
                }
                break;
            }

            case 2:
            {
                while (Menu.pollCallback(callback))
                {
                    switch( callback.callbackId)
                    {
                        case 1:
                        {
                            if( client.init( "127.0.0.1", 6667 ))
                            menu = 1;
                            else menu=2;
                            break;
                        }
                        case 2:
                        {
                            client.init( "127.0.0.1", 6667 );
                            menu=2;
                            break;
                        }
                        case 3:
                        {
                        client.Disconnect();
                        menu=2;
                        break;
                        }
                    }
                }
                break;
            }
        }

        window.clear();
        switch(menu)
        {
            case 1:
            {
                Create.draw();
                break;
            }
            case 2:
            {
                Menu.draw();
                break;
            }
        }
        window.display();
    }
}
 
« Last Edit: April 07, 2013, 12:38:41 am by Soul »

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
Re: tgui 6.0 editbox don't work
« Reply #1 on: April 07, 2013, 12:26:12 am »
You are sending all your events to the menu, the create form doesn't get any events.

Actually Form wasn't made for this and you actually needed the Panel objects, but this way might be just as good.

PS: There is a line with "menu==2;", you might have put one '=' too much here.
TGUI: C++ SFML GUI

Soul

  • Newbie
  • *
  • Posts: 44
    • View Profile
Re: tgui 6.0 editbox don't work
« Reply #2 on: April 07, 2013, 12:38:24 am »
oh now i see... silly me xD
solved :3

 

anything