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

Topics - Dnake

#1
Hi texus,

I downloaded the latest snapshots of TGUI and SFML on Github and I installed them by running the following commands:

mkdir build
cd build
cmake ..
make -j2
sudo make install
sudo ldconfig #Just to be sure

And then I wrote a very simple program, like this:

#include <TGUI/Label.hpp>
int main(){}

and I compiled it with g++ -std=c++11 -ltgui -lsfml-graphics -lsfml-window -lsfml-system main.cpp
But g++ does not think in that way, and say to me:

In file included from /usr/local/include/TGUI/Label.hpp:30:0,
                 from main.cpp:1:
/usr/local/include/TGUI/ClickableWidget.hpp:90:29: error: ‘virtual tgui::Widget::Ptr tgui::ClickableWidget::clone()’ marked ‘override’, but does not override
         virtual Widget::Ptr clone() override
                             ^
In file included from main.cpp:1:0:
/usr/local/include/TGUI/Label.hpp:99:22: error: ‘virtual void tgui::Label::setPosition(const tgui::Layout&)’ marked ‘override’, but does not override
         virtual void setPosition(const Layout& position) override;
                      ^
/usr/local/include/TGUI/Label.hpp:118:22: error: ‘virtual void tgui::Label::setSize(const tgui::Layout&)’ marked ‘override’, but does not override
         virtual void setSize(const Layout& size) override;
                      ^
/usr/local/include/TGUI/Label.hpp:329:22: error: ‘virtual void tgui::Label::initialize(tgui::Container*)’ marked ‘override’, but does not override
         virtual void initialize(Container *const container) override;
                      ^
/usr/local/include/TGUI/Label.hpp:354:22: error: ‘virtual void tgui::Label::update()’ marked ‘override’, but does not override
         virtual void update() override;
                      ^
In file included from /usr/include/x86_64-linux-gnu/c++/5/bits/c++allocator.h:33:0,
                 from /usr/include/c++/5/bits/allocator.h:46,
                 from /usr/include/c++/5/string:41,
                 from /usr/local/include/TGUI/Exception.hpp:30,
                 from /usr/local/include/TGUI/Global.hpp:32,
                 from /usr/local/include/TGUI/Widget.hpp:30,
                 from /usr/local/include/TGUI/ClickableWidget.hpp:30,
                 from /usr/local/include/TGUI/Label.hpp:30,
                 from main.cpp:1:
/usr/include/c++/5/ext/new_allocator.h: In instantiation of ‘void __gnu_cxx::new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = tgui::ClickableWidget; _Args = {tgui::ClickableWidget&}; _Tp = tgui::ClickableWidget]’:
/usr/include/c++/5/bits/alloc_traits.h:256:4:   required from ‘static std::_Require<typename std::allocator_traits<_Alloc>::__construct_helper<_Tp, _Args>::type> std::allocator_traits<_Alloc>::_S_construct(_Alloc&, _Tp*, _Args&& ...) [with _Tp = tgui::ClickableWidget; _Args = {tgui::ClickableWidget&}; _Alloc = std::allocator<tgui::ClickableWidget>; std::_Require<typename std::allocator_traits<_Alloc>::__construct_helper<_Tp, _Args>::type> = void]’
/usr/include/c++/5/bits/alloc_traits.h:402:16:   required from ‘static decltype (_S_construct(__a, __p, (forward<_Args>)(std::allocator_traits::construct::__args)...)) std::allocator_traits<_Alloc>::construct(_Alloc&, _Tp*, _Args&& ...) [with _Tp = tgui::ClickableWidget; _Args = {tgui::ClickableWidget&}; _Alloc = std::allocator<tgui::ClickableWidget>; decltype (_S_construct(__a, __p, (forward<_Args>)(std::allocator_traits::construct::__args)...)) = <type error>]’
/usr/include/c++/5/bits/shared_ptr_base.h:522:39:   required from ‘std::_Sp_counted_ptr_inplace<_Tp, _Alloc, _Lp>::_Sp_counted_ptr_inplace(_Alloc, _Args&& ...) [with _Args = {tgui::ClickableWidget&}; _Tp = tgui::ClickableWidget; _Alloc = std::allocator<tgui::ClickableWidget>; __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2u]’
/usr/include/c++/5/bits/shared_ptr_base.h:617:4:   required from ‘std::__shared_count<_Lp>::__shared_count(std::_Sp_make_shared_tag, _Tp*, const _Alloc&, _Args&& ...) [with _Tp = tgui::ClickableWidget; _Alloc = std::allocator<tgui::ClickableWidget>; _Args = {tgui::ClickableWidget&}; __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2u]’
/usr/include/c++/5/bits/shared_ptr_base.h:1097:35:   required from ‘std::__shared_ptr<_Tp, _Lp>::__shared_ptr(std::_Sp_make_shared_tag, const _Alloc&, _Args&& ...) [with _Alloc = std::allocator<tgui::ClickableWidget>; _Args = {tgui::ClickableWidget&}; _Tp = tgui::ClickableWidget; __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2u]’
/usr/include/c++/5/bits/shared_ptr.h:319:64:   required from ‘std::shared_ptr<_Tp>::shared_ptr(std::_Sp_make_shared_tag, const _Alloc&, _Args&& ...) [with _Alloc = std::allocator<tgui::ClickableWidget>; _Args = {tgui::ClickableWidget&}; _Tp = tgui::ClickableWidget]’
/usr/include/c++/5/bits/shared_ptr.h:614:39:   required from ‘std::shared_ptr<_Tp1> std::allocate_shared(const _Alloc&, _Args&& ...) [with _Tp = tgui::ClickableWidget; _Alloc = std::allocator<tgui::ClickableWidget>; _Args = {tgui::ClickableWidget&}]’
/usr/include/c++/5/bits/shared_ptr.h:629:39:   required from ‘std::shared_ptr<_Tp1> std::make_shared(_Args&& ...) [with _Tp = tgui::ClickableWidget; _Args = {tgui::ClickableWidget&}]’
/usr/local/include/TGUI/ClickableWidget.hpp:92:59:   required from here
/usr/include/c++/5/ext/new_allocator.h:120:4: error: invalid new-expression of abstract class type ‘tgui::ClickableWidget’
  { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
    ^
In file included from /usr/local/include/TGUI/Label.hpp:30:0,
                 from main.cpp:1:
/usr/local/include/TGUI/ClickableWidget.hpp:55:20: note:   because the following virtual functions are pure within ‘tgui::ClickableWidget’:
     class TGUI_API ClickableWidget : public Widget
                    ^
In file included from /usr/local/include/TGUI/ClickableWidget.hpp:30:0,
                 from /usr/local/include/TGUI/Label.hpp:30,
                 from main.cpp:1:
/usr/local/include/TGUI/Widget.hpp:564:29: note: virtual tgui::Widget::Ptr tgui::Widget::clone() const
         virtual Widget::Ptr clone() const = 0;
                             ^
In file included from /usr/include/x86_64-linux-gnu/c++/5/bits/c++allocator.h:33:0,
                 from /usr/include/c++/5/bits/allocator.h:46,
                 from /usr/include/c++/5/string:41,
                 from /usr/local/include/TGUI/Exception.hpp:30,
                 from /usr/local/include/TGUI/Global.hpp:32,
                 from /usr/local/include/TGUI/Widget.hpp:30,
                 from /usr/local/include/TGUI/ClickableWidget.hpp:30,
                 from /usr/local/include/TGUI/Label.hpp:30,
                 from main.cpp:1:
/usr/include/c++/5/ext/new_allocator.h: In instantiation of ‘void __gnu_cxx::new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = tgui::Label; _Args = {tgui::Label&}; _Tp = tgui::Label]’:
/usr/include/c++/5/bits/alloc_traits.h:256:4:   required from ‘static std::_Require<typename std::allocator_traits<_Alloc>::__construct_helper<_Tp, _Args>::type> std::allocator_traits<_Alloc>::_S_construct(_Alloc&, _Tp*, _Args&& ...) [with _Tp = tgui::Label; _Args = {tgui::Label&}; _Alloc = std::allocator<tgui::Label>; std::_Require<typename std::allocator_traits<_Alloc>::__construct_helper<_Tp, _Args>::type> = void]’
/usr/include/c++/5/bits/alloc_traits.h:402:16:   required from ‘static decltype (_S_construct(__a, __p, (forward<_Args>)(std::allocator_traits::construct::__args)...)) std::allocator_traits<_Alloc>::construct(_Alloc&, _Tp*, _Args&& ...) [with _Tp = tgui::Label; _Args = {tgui::Label&}; _Alloc = std::allocator<tgui::Label>; decltype (_S_construct(__a, __p, (forward<_Args>)(std::allocator_traits::construct::__args)...)) = <type error>]’
/usr/include/c++/5/bits/shared_ptr_base.h:522:39:   required from ‘std::_Sp_counted_ptr_inplace<_Tp, _Alloc, _Lp>::_Sp_counted_ptr_inplace(_Alloc, _Args&& ...) [with _Args = {tgui::Label&}; _Tp = tgui::Label; _Alloc = std::allocator<tgui::Label>; __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2u]’
/usr/include/c++/5/bits/shared_ptr_base.h:617:4:   required from ‘std::__shared_count<_Lp>::__shared_count(std::_Sp_make_shared_tag, _Tp*, const _Alloc&, _Args&& ...) [with _Tp = tgui::Label; _Alloc = std::allocator<tgui::Label>; _Args = {tgui::Label&}; __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2u]’
/usr/include/c++/5/bits/shared_ptr_base.h:1097:35:   required from ‘std::__shared_ptr<_Tp, _Lp>::__shared_ptr(std::_Sp_make_shared_tag, const _Alloc&, _Args&& ...) [with _Alloc = std::allocator<tgui::Label>; _Args = {tgui::Label&}; _Tp = tgui::Label; __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2u]’
/usr/include/c++/5/bits/shared_ptr.h:319:64:   required from ‘std::shared_ptr<_Tp>::shared_ptr(std::_Sp_make_shared_tag, const _Alloc&, _Args&& ...) [with _Alloc = std::allocator<tgui::Label>; _Args = {tgui::Label&}; _Tp = tgui::Label]’
/usr/include/c++/5/bits/shared_ptr.h:614:39:   required from ‘std::shared_ptr<_Tp1> std::allocate_shared(const _Alloc&, _Args&& ...) [with _Tp = tgui::Label; _Alloc = std::allocator<tgui::Label>; _Args = {tgui::Label&}]’
/usr/include/c++/5/bits/shared_ptr.h:629:39:   required from ‘std::shared_ptr<_Tp1> std::make_shared(_Args&& ...) [with _Tp = tgui::Label; _Args = {tgui::Label&}]’
/usr/local/include/TGUI/Label.hpp:347:49:   required from here
/usr/include/c++/5/ext/new_allocator.h:120:4: error: invalid new-expression of abstract class type ‘tgui::Label’
  { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
    ^
In file included from main.cpp:1:0:
/usr/local/include/TGUI/Label.hpp:47:20: note:   because the following virtual functions are pure within ‘tgui::Label’:
     class TGUI_API Label : public ClickableWidget, public WidgetBorders, public WidgetPadding
                    ^
In file included from /usr/local/include/TGUI/ClickableWidget.hpp:30:0,
                 from /usr/local/include/TGUI/Label.hpp:30,
                 from main.cpp:1:
/usr/local/include/TGUI/Widget.hpp:564:29: note: virtual tgui::Widget::Ptr tgui::Widget::clone() const
         virtual Widget::Ptr clone() const =  0;
                             ^


As though all methods from base class were not know in children classes, so making overriding tests fail.
The version of g++ is 5.2.1, and I'm on Ubuntu 15.10.

Any idea of why is that happening ?
#2
Feature requests / Layout container
30 May 2015, 19:40:09
Hey Texus, I wrote a class that allow user of TGUI to layout widget more easily than with bindWidth, bindHeight and so on.
It's juste like QBoxLayout in Qt, there is two class: HorizontalLayout and VerticalLayout. Both class have the same interface as Container, but automatically resize and position widgets, allowing this kind of code:

auto layout = tgui::VerticalLayout::create();
layout->setSize(bindWidth(gui), bindHeight(gui));
gui.add(layout);
//...
layout->add(button1);
layout->add(button2);
layout->add(button3);

And now the three buttons fill the whole window, juste like bindWidth(gui, 0.33f) but in a more intuitive way, and without the need to write floating literal.
It is also possible to insert widget, between two already added widgets.

If you're interested in theses classes, I can implement more features, like weight for each element, borders, fixed size widget and space elements.
This is not redundant with the Grid, because the grid actually only position elements, and theses layouts also resize them.

Edit: I know that the copy constructor/assignement operator sounds bad, because widgets are copied, removed and copied again, but that's the only way I seen to don't have to write a addWidget method like you did with Grid.
And maybe I written some methods the wrong way, like mouseOnWidget, I copy-pasted alot and I don't understand all mechanisms of TGUI. This is just a design proposal.
#3
Help requests / Get Grid working
29 May 2015, 13:06:35
Hello,
The solution should be obvious, but I cannot get a Grid working properly:

#include <TGUI/Gui.hpp>
#include <TGUI/Label.hpp>
#include <TGUI/Grid.hpp>
#include <TGUI/Panel.hpp>

int main()
{
using tgui::bindWidth;
using tgui::bindHeight;
sf::RenderWindow window(sf::VideoMode(400, 300), "TGUI window");
tgui::Gui gui(window);
gui.setGlobalFont("DejaVuSans.ttf");

auto grid = tgui::Grid::create();
grid->setSize(bindWidth(gui), bindHeight(gui));
gui.add(grid);

std::vector<std::vector<sf::String>> itemListList = {{"Hello", "The", "World"}, {"TGUI", "is", "great!"}, {"Roses", "are", "red"}};
for(unsigned i{0}; i < itemListList.size(); ++i)
{
for(unsigned j{0}; j < itemListList[i].size(); ++j)
{
tgui::Label::Ptr label = tgui::Label::create();
label->setTextSize(10);
label->setText(itemListList[i][j]);
label->setTextColor(sf::Color::Black);
grid->addWidget(label, i, j);
}
}
    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
            gui.handleEvent(event);
        }
        window.clear(sf::Color::White);
        gui.draw();
        window.display();
    }
    return 0;
}


I simply get a white screen, without text at all.

I'm using last TGUI and SFML versions.
#4
Hello,
I found a bug occurring in following situation:
-A widget is inside a Panel
-This widget overlap the bounds of the panel (so it should be clipped).
-A Canvas is also somewhere else.
In this case, the widget is not clipped at all at the bounds of the the Panel.
Have a look at this code:

#include <TGUI/Gui.hpp>
#include <TGUI/Panel.hpp>
#include <TGUI/Button.hpp>
#include <TGUI/Canvas.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(400, 300), "TGUI window");
    tgui::Gui gui(window);
    gui.setGlobalFont("DejaVuSans.ttf");

auto panel = tgui::Panel::create();
panel->setSize(tgui::bindWidth(gui.getContainer(), 0.5f), tgui::bindHeight(gui.getContainer(), 0.5f));
panel->setBackgroundColor(sf::Color::Transparent);
gui.add(panel);

    auto play = tgui::Button::create();
    play->setSize(tgui::bindWidth(gui.getContainer()), tgui::bindHeight(gui.getContainer()));
    play->setText("Play");
    panel->add(play);

    tgui::Canvas::Ptr canvas = tgui::Canvas::create({300, 300});
    gui.add(canvas);
    sf::Texture tex;
    tex.loadFromFile("Linux.jpg");
    sf::Sprite spr(tex);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
            else if (event.type == sf::Event::Resized)
                gui.setView(sf::View{{0, 0, (float)event.size.width, (float)event.size.height}});
            gui.handleEvent(event);
        }
        window.clear();
        canvas->clear();
        canvas->draw(spr);
        canvas->display();
        gui.draw();
        window.display();
    }
    return EXIT_SUCCESS;
}

The button fills totally the window but the panel owning the button don't.

I'm using TGUI-0.7dev, SFML-2.3 (both latest snapshot) and gcc-4.9.
#5
Hi,
When I run the following code, I get a segfault at the end of the program, I guess when the tgui::Gui instance is destroyed.

#include <TGUI/TGUI.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(800, 600), "TGUI window");
    tgui::Gui gui(window);
    tgui::Picture::Ptr pic = tgui::Picture::create("Black.png");
    pic->setPosition(bindWidth(pic), 0.f);
    gui.add(pic);
    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
            gui.handleEvent(event);
        }
        window.clear(sf::Color::White);
        gui.draw();
        window.display();
    }
    return 0;
}


The debugger tells me that the segfault comes from the line 110 in SFML's Texture.cpp (that's the only relevant information that the call stack gives), at this line:
110        glCheck(glDeleteTextures(1, &texture));

The code above is the minimal one that can reproduces the segfault, the image doesn't matter.
It seems to be related to the bindWidth(pic), when I give an expression independant from pic as layout for setPosition(), the segfault dissapears.

Note: I have to run the project two times to get the segfault, the first time everything works fine.

I run on Windows 7, with TGUI 0.7 and last SFML sources, with Mingw GCC 4.8.

Thanks :)
#6
Feature requests / Viewport in v0.7dev
03 October 2014, 09:00:57
I noticed that the new view system doesn't take in account the viewport. Or if it does, I have issues to correctly set the view of TGUI.
In the exemple, I have a resizable window, and a function that set a viewport every time the window is resized. The goal is to keep a certain ratio in the view of the window. That trick works fine with native SFML stuff and TGUI 0.6, but since the last version I'm not longer able to do this.

I assume that the concerned code is between line 101 and 106 of Gui.cpp.
#7
I've a little issue when I resize my viewport. I explain: I allow the player of my game to resize the window, and my view should keep a 16:9 ratio. So I write a little fonction who resize the viewport when a window resizing event is thrown, and allow the view to be always in 16:9. The fonction return the float rect to assign to the viewport, and here is its code:

FloatRect handleResize(Event::SizeEvent size)
{
    unsigned int iw = size.width;
    unsigned int ih = size.height;
    float fh(ih), fw(iw);//If size is in a 16:9 ratio, it won't change.
    if(iw/16 < ih/9)//Taller than a 16:9 ratio
        fh = iw * (9.0/16.0);
    else if(iw/16 > ih/9)//Larger than a 16:9 ratio
        fw = ih * (16.0/9.0);
    float scalex = fw/iw;
    float scaley = fh/ih;
    return FloatRect((1-scalex)/2.0f, (1-scaley)/2.0f, scalex, scaley);
}

But that make a litlle problem, the widget are strangely resized, like you can see inn the attached file, and that clip the content, here a label. The background of the label is grey in the picture. The proportions in the picture between the two windows are preserved. How can I fix that? Should I handle the resize in another way, or disable the resizing?
(Texus: I speak french at first, and I can see you're belgian, so can I speak with you in french?)
#8
In my project I need to draw the gui with some render states, and I seen that that's no possible in TGUI v0.6.
So I changed a bit Gui.cpp, and now I can do stuff like this in my project:

Transform transform;
transform.scale(Vector2f(scalingFactor, scalingFactor));
m_gui.draw(true, transform);

But I don't know if you purposely don't implemented this feature. Is that a good idea?
I attached the modified files.