I want to add a button to my window.
« on: 08 September 2013, 15:54:26 »
I am using this code from your tutorials , but its not working , it is saying that there is no addbutton() function
Code: [Select]
tgui::Button* button = window.addButton();
button->load("TGUI/objects/Button/Black");
button->setText("example button");
button->setSize(200, 50);
button->setPosition(100, 50);

, please help me ! :(

*

texus

  • *****
  • 1143
    • View Profile
    • Texus's Blog
Re: I want to add a button to my window.
« Reply #1 on: 08 September 2013, 16:00:18 »
Where did you find that code exactly? That is code for tgui v0.4, while you are either using v0.5 or v0.6.

tgui v0.5:
tgui::Button* button = window.add<tgui::Button>();
button->load("TGUI/objects/Button/Black");

tgui v0.6:
tgui::Button::Ptr button(gui);
button->load("TGUI/widgets/Black.conf");

Re: I want to add a button to my window.
« Reply #2 on: 08 September 2013, 18:17:47 »
i found this from your tutorials !  ... http://tgui.weebly.com/v05---button.html

*

texus

  • *****
  • 1143
    • View Profile
    • Texus's Blog
Re: I want to add a button to my window.
« Reply #3 on: 08 September 2013, 18:24:19 »
Ah, thanks for pointing that out. Its a small mistake in the tutorial (the tutorials were written while v0.5 was still being changed and it seems like I forgot to update that part of the tutorial after changing the add function).
It has been fixed now.

You should put most trust in the example code, it was updated more regulary.

Re: why this code is not working ?
« Reply #4 on: 08 September 2013, 18:43:44 »
Code: [Select]

#include <SFML/window.hpp>
#include <SFML/system.hpp>
#include <SFML/audio.hpp>
#include <SFML/graphics.hpp>
#include <TGUI/TGUI.hpp>
//#include <SFML/Video.hpp>
//#include <conio.h>

//#include <iostream>

int main()
{
    // Create the window
    sf::RenderWindow window(sf::VideoMode(800, 600), "Window");
    tgui::Gui gui(window);
 
    // Load the font (you should check the return value to make sure that it is loaded)
    gui.setGlobalFont("C:/Users/corleone/Documents/Visual Studio 2010/Projects/MySfml/MySfml/TGUI-0.6-alpha2-Visual-C++10-2010-32-bits/TGUI-0.6-alpha2/fonts/DejaVuSans.ttf");
 
    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 (if there would be widgets)
            gui.handleEvent(event);
        }
 
        //window.clear();
 
        // Draw all created widgets
        gui.draw();

tgui::Button::Ptr button(gui);
button->load("C:/Users/corleone/Documents/Visual Studio 2010/Projects/MySfml/MySfml/TGUI-0.6-alpha2-Visual-C++10-2010-32-bits/TGUI-0.6-alpha2/widgets/Button/BabyBlue/Normal.conf");

        window.display();
   








}
return EXIT_SUCCESS;
}



 :(


« Last Edit: 08 September 2013, 18:47:00 by Nabeel Nazir »