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, 19:10:54 by Nabeel Nazir »

Re:
« Reply #1 on: 08 September 2013, 19:03:52 »
Please also tell me how can i make list Box in this code ???
and secondly why font file is not loading in this code ???? I need help  ! :(

*

texus

  • *****
  • 1143
    • View Profile
    • Texus's Blog
You are creating a button every frame. You should only create it once.
You should also call the window.clear function (you should uncomment it). In sfml you must redraw every frame entirely.

The code should look more like this:
Code: [Select]
#include <SFML/Audio.hpp>
#include <TGUI/TGUI.hpp>
#include <conio.h>

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("TGUI/fonts/DejaVuSans.ttf");

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

    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();

        window.display();
}
return EXIT_SUCCESS;
}


What errors are you getting in the command prompt?

To create a list box, just do like you would create a button:
Code: [Select]
tgui::ListBox::Ptr listBox(gui);
listBox->load("TGUI/widgets/Black.conf");
And then use setSize to give it the correct size, addItem function to add items to it, ...
Here is the list of other function you can call on the listbox: http://tgui.eu/dcmtn/v0.6/classtgui_1_1ListBox.html.

this is the error on console !

*

texus

  • *****
  • 1143
    • View Profile
    • Texus's Blog
Obviously your program should be able to find the files.

It is looking for "TGUI/fonts/DejaVuSans.ttf" and if I am not mistaking then VS look for it next to the executable. So you need a folder called TGUI next to your executable (in the Debug or Release folder). Or use a full path like you were using, but then the program doesn't work on other computers.

Edit: In your current setup it should be something like "../TGUI-0.6-alpha2/fonts/DejaVuSans.ttf" at the moment.
« Last Edit: 08 September 2013, 19:25:03 by texus »

*

texus

  • *****
  • 1143
    • View Profile
    • Texus's Blog
The error is quite clear, so I can only ask one thing: "Are you 100% sure that that file exists?"

Try with "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/Black.conf", which is the default style and should work. If that works then you can try with creating your own config file. But if this is just a small test project then you might want to keep the default Black style until you have more experience with tgui.

Edit: Did you just delete your previous post?
« Last Edit: 08 September 2013, 19:51:31 by texus »

thanks a lot ... now its working ! :))) !
that's why i remove other reply's !
yeah this is a small project given by my university professor...
this project is simple but complex and i am sure you guys will help me in completing this task :))
the project is about to create a list box which contains different animal names .. and a button.. when a particular name of animal  is selected .. and button is pressed then voice of that animal should be played ! 

*

texus

  • *****
  • 1143
    • View Profile
    • Texus's Blog
Good to hear that it is working now.

But I changed my forum settings now so you can no longer delete posts, its really confusing if posts are suddenly missing.

Re:
« Reply #8 on: 08 September 2013, 21:30:07 »
I have made the button and list box .. now its time to move on to the next step !
is there any way to add a ".wav" sound file in this code ? so that when a particular animal is selected and speak button is pressed then the selected animal's voice will be played ? i need help !

*

texus

  • *****
  • 1143
    • View Profile
    • Texus's Blog
I think I can write your assignment in less than 100 lines, so I can't give to many details (otherwise I will be making half of your assignment).

You need to load the sounds with sfml.
Then insert the names of the animals into the list box with the addItem function.
When receiving callback from the button (see part 3 of introcuction tutorial for more information about callbacks), you should check which animal is selected with the getSelectedItem function. And depending on the string that the function returns you should play the corresponding sound.

Re:
« Reply #10 on: 09 September 2013, 07:25:35 »
thanks ! :)
 
« Last Edit: 09 September 2013, 07:30:59 by Nabeel Nazir »