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

#1396
Help requests / Re: drawing sprites
04 May 2014, 10:40:34
If you have an sf::Texture that you want to display as a background of the child window, then you can use the setBackgroundTexture function.

Otherwise you have to create a Canvas widget inside the child window. The Canvas class is a wrapper around sf::RenderTexture, so you use it in the same way.
tgui::Canvas::Ptr canvas(*child);
canvas->setSize(child->getSize().x, child->getSize().y);

// This code is executed every time the sprite/texture changes.
// Either once when the sprite is a static image, or every frame when constantly changing the image.
canvas->clear();
canvas->draw(sprite);
canvas->display();
#1397
Help requests / Re: editbox in childwindow
03 May 2014, 19:00:08
tgui::EditBox::Ptr name(*create);
That line is wrong.

What you are doing there is creating a new editbox variable, instead of using the one from the Menu class.

Replace that line (and the ones below it which have the same mistake) by the following:
create->add(name);

An alternative would be to call the constructor of the variable in the initialize list of the constructor of your Menu class, but that will just make it a lot more complicated in this case because the child window would not yet be fully initialized when initializing the edit box.
#1398
Help requests / Re: editbox in childwindow
03 May 2014, 18:36:18
The getText function should work. Could you write a minimal but complete example code that reproduces the issue?

Btw, I really recommend using meaningful variable names, because you are making it ten times harder for someone else to understand your code by just using letters for variables.
#1399
Help requests / Re: childwindow
03 May 2014, 16:30:21
When creating a button you pass its parent. So normally you have a line like this that will add the button to the gui.
tgui::Button::Ptr button(gui);

The only difference is that instead of the gui you now just pass the child window.
tgui::ChildWindow::Ptr child(gui);
tgui::Button::Ptr button(*child);
#1400
This is actually the first time that I notice that I have been talking to different persons in this topic :).

QuoteOtherwise, I'm happy to wait until your updated release.
I try to not make multiple releases in less than a month, especially not for one small bug. Creating these precompiled libraries is too time consuming. I have automated the compilation, but there is still a lot of work to do on every release. So you shouldn't expect a v0.6.4 release soon.

There are two ways to get the changes from github. The first way is to go to the github page and click the "Download ZIP" button. Then follow the CMake tutorial for VS or the CMake tutorial for C::B. In short, you run cmake which creates a project file which you then open and build which will provide you with the libraries.

The other way is slightly more work, but will make it a lot faster to recompile the libraries if I make another change. You will need to download git and then clone my repository (running "git clone https://github.com/texus/TGUI" from the command line will create the TGUI folder). Then follow the same steps as in the other option. But if I make a change afterwards, then all you need to do is pull the latest changes ("git pull" from the command line). The cmake step is no longer needed, you can directly open the project file and rebuild it.
I usually do it all from a terminal as I'm used of doing this on linux, but there are also graphical interfaces available on windows to make it even easier.
#1401
I've made a commit on github that should hopefully fix your problems.

The change is not finished yet (Tab widget hasn't been changed yet, and I still have to actually test the code), but I hope that it will work for what you need so that you don't have any problems with this anymore.

After I finish the change (hopefully tomorrow) I'll make sure to fully test it with different viewports, view sizes and view centers to make sure that my code finally supports every combination.
#1402
Damn. I'll make sure to look for a different way to do the clipping in v0.7.

The Label has to know its absolute position on the screen, but it currently only knows its relative position.
I'll see if I can fix it this evening.

Edit: the bug seems to be a little trickier than I thought. I'll try to have it fixed tonight or tomorrow though.
#1403
Strange. I just tested creating a Label like this and I could not reproduce it.
tgui::Label::Ptr label(gui);
label->setText("Hello");


After compiling SFML, did you compile TGUI again with the new SFML libraries?
Depending on your compiler you could also just use the precompiled libraries.
#1404
You forgot to load a font.

Add this after creating the gui:
gui.setGlobalFont("data/TGUI/fonts/DejaVuSans.ttf");

I had to add that to even get the text in the buttons and editbox to show up.

But on top of this, the labels are white, so is your background. So also try changing the text color:
labelUsername->setTextColor(sf::Color::Black);
#1405
The fix has been made on the master branch on github (https://github.com/texus/TGUI), which will be released as v0.6.3 later this weekend.

QuoteI don't totally understand your code
That piece of code isn't meant to be understood. Its meant to be written once and hope that you never have to change it again :).
The reason why it is so complex is because I need the coordinate on the sceen with the bottom left corner being the origin. To find that point I have to take into account that sfml has its origin in the top left corner, the view size can be different than the window and I also have to watch the viewport apparently.
Maybe if SFML issue #1 gets added one day it would become a lot easier.

Quote(You just wrote m_background and m_size in place of m_Background and m_Size :p)
Thats because I was developing on the v0.7 branch, I made a small naming convention change there. Luckily you could see the mistake yourself here, in other widgets there were differences like m_LeftBorder vs m_borders.left.
#1406
I didn't notice that the Label was inside a Panel at first. The Panel is also doing some clipping.

The changes that have to be made are in the calculation of topLeftPosition and bottomLeftPosition. These calculations did not take the viewport into account. When I wrotes these formulas once I hoped that I would never have to touch them again, but it seems that they weren't perfect after all.

The code in Label.cpp has to be
sf::Vector2f topLeftPosition
    = states.transform.transformPoint(((getPosition().x - target.getView().getCenter().x + (target.getView().getSize().x / 2.f)) * target.getView().getViewport().width) + (target.getView().getSize().x * target.getView().getViewport().left),
                                      ((getPosition().y - target.getView().getCenter().y + (target.getView().getSize().y / 2.f)) * target.getView().getViewport().height) + (target.getView().getSize().y * target.getView().getViewport().top));
sf::Vector2f bottomRightPosition
    = states.transform.transformPoint((getPosition().x + m_background.getSize().x - target.getView().getCenter().x + (target.getView().getSize().x / 2.f)) * target.getView().getViewport().width + (target.getView().getSize().x * target.getView().getViewport().left),
                                      (getPosition().y + m_background.getSize().y - target.getView().getCenter().y + (target.getView().getSize().y / 2.f)) * target.getView().getViewport().height + (target.getView().getSize().y * target.getView().getViewport().top));


And in Panel.cpp
sf::Vector2f topLeftPosition
    = states.transform.transformPoint(((getPosition().x - target.getView().getCenter().x + (target.getView().getSize().x / 2.f)) * target.getView().getViewport().width) + (target.getView().getSize().x * target.getView().getViewport().left),
                                      ((getPosition().y - target.getView().getCenter().y + (target.getView().getSize().y / 2.f)) * target.getView().getViewport().height) + (target.getView().getSize().y * target.getView().getViewport().top));
sf::Vector2f bottomRightPosition
    = states.transform.transformPoint((getPosition().x + m_size.x - target.getView().getCenter().x + (target.getView().getSize().x / 2.f)) * target.getView().getViewport().width + (target.getView().getSize().x * target.getView().getViewport().left),
                                      (getPosition().y + m_size.y - target.getView().getCenter().y + (target.getView().getSize().y / 2.f)) * target.getView().getViewport().height + (target.getView().getSize().y * target.getView().getViewport().top));


I'm going to sleep now, but I'll continue this tomorrow. Other widgets will need the same fix, and I somehow feel that there is also something wrong when changing the view size.

I'm surprised that a bug as big is this one hasn't been noticed before. I guess nobody needed to change the viewport in his program until now.
#1407
Ok, I can reproduce it but I'll look into this in more detail tomorrow.

The only thing you can do now is comment out line 378 in Label.cpp (the one with glScissor) and compile the changed tgui version. That will disable the clipping in Label, which is not really needed in 99.9% of the cases anyway.

But some other widgets are going to have the same problem, so I'll try to fix this as soon as possible.
#1408
This is most likely a bug in tgui. The viewort isn't used in calculations.

But I can't immediately reproduce it, could you send a small example code the produces the error?

Quote(Texus: I speak french at first, and I can see you're belgian, so can I speak with you in french?)
Nope, I speak dutch. I know a little french, but not enough to really communicate with it.

Edit: I've been able to reproduce it. I'm looking into it.
Edit2: I can only reproduce a similar bug, not yet the exact same thing. So I can still use an example so that I can test whether my fix holds in your situation as well (which I doubt).
#1409
Help requests / Re: Draggable Panel
09 April 2014, 10:03:19
QuoteI changed this part though, still look good?
Yep, that still looks good.

Quote// <---since we already found a widget, why keep going, why not break out of loop; ?
As you can see, when the boolean is false, the mouseNotOnWidget() function is called.
Imagine the following situation:
You move the mouse on the background picture, and then continue to move the mouse over a button (which is on top of the picture). Since we are looping over the widgets backwards, we will find the button. But the picture will never be told that the mouse is no longer on top of it. Hence once we find the widget, we tell all remaining ones that the mouse can't be on them.

Edit: I though about it a bit longer and you can indeed use the shorter code. Its only inside tgui that the longer version is required.
#1410
Help requests / Re: Draggable Panel
08 April 2014, 21:41:23
As said, option 1 isn't that hard:
#include <TGUI/TGUI.hpp>

///////////////////////////////////////////////////////////////////////

tgui::Widget::Ptr mouseOnWhichWidget(float x, float y, std::vector<tgui::Widget::Ptr>& widgets)
{
    bool widgetFound = false;
    tgui::Widget::Ptr widget = nullptr;

    // Loop through all widgets
    for (std::vector<tgui::Widget::Ptr>::reverse_iterator it = widgets.rbegin(); it != widgets.rend(); ++it)
    {
        // Check if the widget is visible and enabled
        if (((*it)->isVisible()) && ((*it)->isEnabled()))
        {
            if (widgetFound == false)
            {
                // Return the widget if the mouse is on top of it
                if ((*it)->mouseOnWidget(x, y))
                {
                    widget = *it;
                    widgetFound = true;
                }
            }
            else // The widget was already found, so tell the other widgets that the mouse can't be on them
                (*it)->mouseNotOnWidget();
        }
    }

    return widget;
}

///////////////////////////////////////////////////////////////////////

int main()
{
    sf::RenderWindow window(sf::VideoMode(930, 700), "TGUI window");
    tgui::Gui gui(window);

    if (gui.setGlobalFont("TGUI/fonts/DejaVuSans.ttf") == false)
        return 1;

    tgui::Widget::Ptr draggingWidget = nullptr;
    sf::Vector2f draggingPosition;

    tgui::Panel::Ptr panel1(gui);
    tgui::Panel::Ptr panel2(gui);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
            else
            {
                if (event.type == sf::Event::MouseButtonPressed)
                {
                    tgui::Widget::Ptr widget = mouseOnWhichWidget(event.mouseButton.x, event.mouseButton.y, gui.getWidgets());
                    if ((widget.get() == panel1.get()) || (widget.get() == panel2.get()))
                    {
                        if (mouseOnWhichWidget(event.mouseButton.x, event.mouseButton.y, tgui::Panel::Ptr(widget)->getWidgets()) == nullptr)
                        {
                            draggingWidget = widget;
                            draggingPosition = sf::Vector2f(event.mouseButton.x, event.mouseButton.y);
                        }
                    }
                }
                else if (event.type == sf::Event::MouseButtonReleased)
                {
                    draggingWidget = nullptr;
                }
                else if (event.type == sf::Event::MouseMoved)
                {
                    if (draggingWidget != nullptr)
                    {
                        draggingWidget->setPosition(draggingWidget->getPosition().x + event.mouseMove.x - draggingPosition.x,
                                                    draggingWidget->getPosition().y + event.mouseMove.y - draggingPosition.y);

                        draggingPosition = sf::Vector2f(event.mouseMove.x, event.mouseMove.y);
                    }
                }
            }

            gui.handleEvent(event);
        }

        window.clear();
        gui.draw();
        window.display();

        sf::sleep(sf::milliseconds(1));
    }

    return 0;
}


While writing the code I even found a bug in tgui :). Trying to compare two widget pointers is not possible (function can't access private variable). That is why you have to use the '.get()' like in the above code.