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

#1601
You commented out too much code when callback.id is 2. You should still add the sound to the list when clicking the 'add animal' button.

I removed some of the commented parts during searching for the mistake.
#include <SFML/Audio.hpp>
#include <TGUI/TGUI.hpp>
#include <fstream>

int main()
{
std::list<sf::SoundBuffer> buffers;
std::list<sf::Sound> sounds;

    sf::RenderWindow window(sf::VideoMode(800, 600), "Window");
    tgui::Gui gui(window);

std::string name;

tgui::ListBox::Ptr listBox(gui);

tgui::EditBox::Ptr editBox(gui);
std::ifstream ifile;
ifile.open("animals.txt");
if(ifile.is_open())
{
while(ifile>>name)
{

ifile.ignore(10,'\n');
listBox->addItem(name);

buffers.push_back(sf::SoundBuffer());
buffers.back().loadFromFile(name + ".wav");

sounds.push_back(sf::Sound());
sounds.back().setBuffer(buffers.back());

}

}
else
{
std::cout<<"ifile.txt does not open properly!"<<std::endl;
}
ifile.close();


    // 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");
button->setPosition(280, 250);
    button->setText("SPEAK");
    button->setSize(200, 40);


listBox->load("TGUI/widgets/Black.conf");
listBox->setSize(150, 120);
    listBox->setItemHeight(30);
    listBox->setPosition(300, 30);
listBox->setCallbackId(3);

tgui ::Callback callback;

button->bindCallback(tgui::Button::LeftMouseClicked);
button->setCallbackId(1);


    editBox->load("TGUI/widgets/Black.conf");
    editBox->setBorders(6, 4, 6, 4);
    editBox->setPosition(230, 350);
    editBox->setText("Add Animal Name Here!");
editBox->setSize(360, 40);

tgui::Button::Ptr button1(gui);
    button1->load("TGUI/widgets/Black.conf");
button1->setPosition(280, 450);
    button1->setText("Add Animal");
    button1->setSize(200, 40);

button1->bindCallback(tgui::Button::LeftMouseClicked);
button1->setCallbackId(2);


    while (window.isOpen())
    {
/////////////////////////////////////////////////////

while (gui.pollCallback(callback))
{

if(callback.id==1)
{
    if (listBox->getSelectedItemIndex() != -1)
                    {
                        auto it = sounds.begin();
                        std::advance(it, listBox->getSelectedItemIndex());
                        it->play();
                    }
}

if(callback.id==2)
{
name=editBox->getText();
listBox->addItem(name);

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);
/*
auto it = sounds.begin();
std::advance(it, listBox->getSelectedItemIndex());
it->play();
*/

}


}

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

}

std::ofstream ofile("animals.txt");
if (ofile.is_open())
{
auto& items = listBox->getItems();
for (auto it = items.cbegin(); it != items.cend(); ++it)
{
ofile << it->toAnsiString() << std::endl;
}
}
else
{
std::cout<<"ofile does not open properly !"<<std::endl;
}
ofile.close();

return EXIT_SUCCESS;
}
#1602
I don't think there are any other, but if you find others than just let me know.

Changes to these functions and the updated documentation will be uploaded in half an hour or so.
#1603
Ah, I though that the problem was that there were two functions with the same name.

So making the remove and focusWidget functions no longer internal (which I needed to do anyway) will solve this whole discussion? I was starting to to get afraid that I would have to change a lot of code.
#1604
The best option that I can think of so far is name the functions like this:
remove(Widget::Ptr);
removeWidget(Widget*);


But I took a look at the get functions and I don't even want to change that.
Although I do realize that the template one could be dropped and that you could type tgui::Button::Ptr(gui.get("widget")) instead of gui.get<tgui::Button>("widget").
#1605
Ah, I misread your first post. I read that you didn't find it a good way to add internal to the functions.
But I think I'm just going to do it for the duplicate functions at first (focusWidget, get, remove, ...) and not for functions like initialize, mouseOnWidget, leftMousePressed, ...

Anyway that would just be temporary until I get a better design and can do a better job.


But I see problems with removing some of the internal functions. I even have reasons to no longer make them internal.
In the widget callbacks, I am forced to use a Widget* instead of Widget::Ptr (to avoid the big memory leak that I had). But that means that Container will need a remove function that takes a Widget*. But I also want you to remove a Widget::Ptr without first calling the get function on it to retrieve the Widget*. That is why I believe that both remove functions should stay.
#1606
I have to look into this, because it isn't that easy and it definately isn't a small change.
The difference with sfml is that my classes highly depend on each other, so it can't be fixed that easily.

If I would be able to declare a namespace inside a class it would be fixed a lot faster, but I can't so I'll have to look for other solutions.
#1607
Actually I realized that too, I just couldn't find a better name than getLines.
I was thinking about things like getNumberOfLines or getAmountOfLines but I didn't like them. But getLineAmount should do.
#1608
Help requests / Re: [SOLVED] sf::View and TGUI
18 September 2013, 18:25:17
I decided to make it a bit easier.

gui.draw now has a parameter to reset the view. By default false will be passed and the current view will be used. But you can pass true to render the widgets with the default view. After the gui has been drawn, your old view will be restored.

So you no longer have to set a separate view for sfml and tgui every frame, just set your view once for sfml and pass true to gui.draw.
#1609
An option has been added to cmake. I only tested it on linux so far though.
#1610
It was planned, I even added the doxyfile, but I didn't look further into it yet.

It can't be that hard, copying a few lines from the sfml cmake script should be enough.

I'll see what I can do.
#1611
Ok, it now has a getLines function which will return the amount of lines in the chat box.
#1612
The changes have been made.

addLine no longer returns anything, everything passed to addLine is considered to be a single line.
#1613
The "if(callback.id==1)" part in your code still contains old code. You should clean up your code a bit more, because you aren't using half of the code anymore.

You now simply need something like this:
if(callback.id==1)
{
    auto it = sounds.begin();
    std::advance(it, listBox->getSelectedItemIndex());
    it->play();
}
#1614
You don't just have to load the animal names from the text file, you also need to load the sound that belongs to the animal.

Something like this (untested)
while(ifile>>name)
{
    ifile.ignore(10,'\n');
    listBox->addItem(name);

    buffers.push_back(sf::SoundBuffer());
    buffers.back().loadFromFile(name + ".wav");

    sounds.push_back(sf::Sound());
    sounds.back().setBuffer(buffers.back());
}
#1615
Ok, I figured out what is happening. You are loading stuff so you are adding items to the list box. But no sound is being loaded that belongs to these items. So the amount of items in the list box will be bigger than the amount of loaded sounds.

So instead of just adding the read line to the list box, you should also load the corresponding sound.
while(ifile>>name)
{
    ifile.ignore(10,'\n');

    // Do something here similar to what you do when pressing the 'add animal' buttons.
}
#1616
- When creating the ofile, you are checking if the ifile is open. You should check ofile instead.

- Close ifile when you are done with it. It is automatically closed when going out of scope, but because everything is inside the main function, this will be when the program quits. And you don't want the file to still be open for reading when at the same time opening it for writing.

- The following lines don't work correctly.
while(!ifile.eof())
{
    ifile>>name;


You should change it to the following to get the desired effect.
while(ifile>>name)
{
#1617
You must have downloaded it right before I fixed it. Try downloading the latest tgui version again, it should be fixed.
#1618
Installation help / Re: [MSVC 2010] Build errors
17 September 2013, 01:41:26
The latest version should compile again.

I haven't been able to test it myself though, as my VC++10 compiler is suddenly 'broken', even though I had been using it earlier to reproduce the fact that the code didn't compile.
#1619
Installation help / Re: [MSVC 2010] Build errors
16 September 2013, 21:03:45
It will take some time to fix this, I will at least need one day.

I was going to send a link to to the v0.6-alpha2, but everything seems to be going wrong today. I can't login to my wordpress anymore and my last backup is like a month old. So I'll have more things to do tomorrow then just getting the code to compile on VS2010 again.

All I can do for now is send v0.6-alpha1 which I still had on my pc. It has a known memory leak, so this is only temporary until I get this issue solved (I'll post here when that happens).
#1620
Installation help / Re: [MSVC 2010] Build errors
16 September 2013, 20:39:49
That means that I wrote code that VS2010 didn't support yet. You can't do anything about that.

I'm currently booting up my windows, I'll fix this as soon as possible.
#1621
Installation help / Re: [MSVC 2010] Build errors
16 September 2013, 20:20:57
Damn, I hate windows.
I am using ptr_fun for only one reason: windows.h does something strange with the to_lower function so that it can't work cross-platform. And now it seems that I can't even use it in VS2010 (which is strange because I have build precompiled VS2010 binaries without facing this problem).

For now you should change "std::ptr_fun<int, int>(std::tolower)" into "std::tolower" or even "tolower" on the places where the compiler complains (use 'replace all' on all files).

In the meantime I will look for an alternative way to convert a string to lowercase.
#1622
You are writing to the file every frame.

You should move the code that opens and writes to the file to after the "while (window.isOpen())" loop.
#1623
Installation help / Re: [MSVC 2010] Build errors
16 September 2013, 19:51:33
The first error is in Widget.cpp on line 442, so lets focus on that one first.

Could you try to add the following line to the top of the file and try again?
#include <functional>
#1624
I edited my post later because I realized that this was going to happen. VS2010 has only very limited c++11 support.

Quote from: texus on 15 September 2013, 11:55:10Edit: 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;
}
#1625
Which part about the file handling isn't working exactly (the code looks good at first sight)? Does the text file get written correctly? What gets placed in the list box when trying to load from a file?

If you want to store the animals, even after the program has quit, then there is no other option than storing it in a text file on the hard disk.