Main Menu
Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - texus

#1626
Help requests / Re: callback not triggered
15 September 2013, 16:53:10
Callbacks can now be loaded from widget files.

The widget files need to contain lines like these:
Callback = LeftMouseClicked
CallbackId = 1


You can pass multiple callbacks by placing a comma between them:
Callback = Focused, Unfocused

Also because of how the new form builder is written, you will also be able to change the callbacks from within the form builder.
#1627
Help requests / Re: LoadFromFile() & callbacks
15 September 2013, 16:52:08
Callbacks can now be loaded from widget files.

The widget files need to contain lines like these:
Callback = LeftMouseClicked
CallbackId = 1


You can pass multiple callbacks by placing a comma between them:
Callback = Focused, Unfocused

Also because of how the new form builder is written, you will also be able to change the callbacks from within the form builder.
#1628
Quotecan i store the selected item from listBox in a character array or any character variable so that i may pass this character array in addItem() function of listBox, and it will store new animal name in the listBox !?
I have no idea what you mean with this, but lets break it down in smaller parts.

Quotecan i store the selected item from listBox in a character array
std::string selectedItem = listBox->getSelectedItem();

Quoteso that i may pass this character array in addItem() function of listBox
listBox->addItem(selectedItem);
#1629
Quotehmmm, i didn't get you !
You want to be able to keep your added animals even after the program was quit, right?

So at the beginning of the program you have something like this:
std::ifstream ifile("animals.txt");
if (ifile.is_open())
{
    // Read the contents of the file and put the read animals in the listbox with addItem
}


At the end of the program you save the animals that you have in your listbox to a file, so that the next time you start the program you will still have all animals.
std::ofstream ofile("animals.txt");
if (ifile.is_open())
{
    auto& items = listBox->getItems();
    for (auto& item : items)
    {
        ofile << item.toAnsiString() << std::endl;
    }
}


Again, this code is only for guidance and may contain mistakes. I also deliberately left out the way to load the text file so that I don't give you the complete solution.

Edit: just realized that that for loop is only supported since VS2012. It will be like this for you:
for (auto it = items.cbegin(); it != items.cend(); ++it)
{
    ofile << it->toAnsiString() << std::endl;
}
#1630
Quotebut when i close my window and compile my code again it will not show the recently added animal in the list box !
Obviously. What you want to do is save a the contents of the list in a text file and load it again when starting the program (look at std::ifstream and std::ofstream).
#1631
Adding an edit box is the same as adding a button or a list box:
tgui::EditBox::Ptr editBox(gui);
editBox->load("...");

And then look at the documentation for the other functions you can use. But you probably only need setPosition and setSize.

When the "Add animal" button gets pressed, you can use the addItem function to add the contents of the edit box to the list box (editBox->getText() for getting text in edit box).

The animal will be added to the back of the list box, but it still has to be selected.
listBox->setSelectedItem(listBox->getItems().size()-1); // Select the last item in the list box

----------
What follows below is a suggestion of what you can do to play the sound. I didn't test it as I wrote it so it might contain mistakes, and it definately isn't the only way. But you might get some ideas from it.

Now you can even make the sound load dynamically. At the beginning of the program you define this:
std::list<sf::SoundBuffer> buffers;
std::list<sf::Sound> sounds;


When adding a new item to the list box, e.g. with the "Add animal" button then you load the sound. This has the limitation that the sound needs to have the exact name as the animal though (if CAT is entered in the edit box then it will load CAT.wav).
buffers.push_back(sf::SoundBuffer());
buffers.back().loadFromFile(editBox->getText() + ".wav");

sounds.push_back(sf::Sound());
sounds.back().setBuffer(buffers.back());
sounds.back().setPitch(1.5f);
sounds.back().setVolume(80);


And then when the speak button is pressed, you play the correct sound. There are just as many sounds as there are items in the list box, and e.g. the third item in the list box matches the third sound in the list, so you can use listBox->getSelectedItemIndex().
auto it = sounds.begin();
std::advance(it, listBox->getSelectedItemIndex());
it->play();
#1632
Please post on either the sfml forum or on this forum but not on both.
There is no need to ask the same question twice, by the time one replies you might already have a reply on the other forum.

I read both forums anyway.
#1633
I guess you understand it by now with the other reply on the sfml forum?
#1634
You'll have to wait till someone responds on the sfml forum, because I can't help with that.
#1635
Seems like the wav file is currupted. Try with another file and see if it works.
#1636
Does it print something in the command prompt? Its probably going to say that cat.wav can't be found.

If I remember correctly, then for Visual Studio you have to place the file in either "C:\Users\corleone\Documents\Visual Studio 2010\Projects\MySfml\MySfml\Debug" or "C:\Users\corleone\Documents\Visual Studio 2010\Projects\MySfml\MySfml\Release" depending on whether you are building in debug or release mode.
#1637
Help requests / Re: callback not triggered
09 September 2013, 16:23:02
The callback id does get set, but it is the binding that doesn't happen.
So in your code you should have this:
gui.get("btnName")->bindCallback(tgui::Button::LeftMouseClicked);

Thats the part that isn't done automatically yet when loading from a file.
#1638
Help requests / Re: callback not triggered
09 September 2013, 16:00:10
Take a look at this topic for my answer: https://forum.tgui.eu/index.php/topic,134.0.html
#1639
You are recreating the SoundBuffer every frame.

The sound is temporary as well.
else {
    sf::Sound sound;        // <-  Sound object gets created
    sound.setBuffer(buffer);
    sound.play();
}   // <- Sound object gets destroyed as it goes out of scope


You should declare the SoundBuffer and Sound objects at the beginning of the main function.
So these lines should be moved to earlier in your program (anywhere above the main loop).
sf::SoundBuffer buffer;
sf::Sound sound;
#1640
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.
#1641
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.
#1642
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?
#1643
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.
#1644
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:
#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:
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: https://tgui.eu/dcmtn/v0.6/classtgui_1_1ListBox.html.
#1645
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.
#1646
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:
Code (cpp) Select
tgui::Button* button = window.add<tgui::Button>();
button->load("TGUI/objects/Button/Black");


tgui v0.6:
Code (cpp) Select
tgui::Button::Ptr button(gui);
button->load("TGUI/widgets/Black.conf");
#1647
You have added the widgets, but you don't remove them.
When returning from the function you should also call w.removeAllObjects().

Otherwise the widgets from player1 are still drawn behind the ones from player2.
#1648
Feature requests / Re: Logo for TGUI=)
07 September 2013, 16:16:29
I would use a button or checkbox as logo. Something that can be associated with a gui.
The only words I think of at the moment are simple and easy.
#1649
Feature requests / Re: Logo for TGUI=)
07 September 2013, 13:40:31
That would indeed be nice.

But I'm not sure if anyone is going to volunteer to make a logo, and I'm not creative enough to do draw one myself.
#1650
You aren't linking to the tgui library.

g++ main.o -o app -L ../TGUI/lib  -L ../SFML/lib -lsfml-graphics -lsfml-window -lsfml-system
should just be
g++ main.o -o app -L ../TGUI/lib  -L ../SFML/lib -ltgui -lsfml-graphics -lsfml-window -lsfml-system