Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: TGUI: a c++ GUI for SFML (with Form Builder)  (Read 286899 times)

0 Members and 6 Guests are viewing this topic.

Cpl.Bator

  • Hero Member
  • *****
  • Posts: 540
    • View Profile
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #375 on: February 04, 2013, 12:46:44 am »
Very good job Texus.
i think is more easy for final user ( not you ;) ) to use simple image for customize the gui.
did you plan to include this feature ?


texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #376 on: February 04, 2013, 04:06:54 pm »
I am planning to do that in the future for ListBox, ComboBox and MenuBar (all others are already loaded with images).

But I wouldn't really know what images should be loadable. I still have to make dicisions about whether it should be just a background image or seperate images for all items.
For now you will just have to work with a simple background color for these objects.
TGUI: C++ SFML GUI

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #377 on: February 05, 2013, 08:07:57 pm »
Now that the callback system is finished, I plan to make another design change.

When getting the objects from the window you would only get pointers to the base classes. And because not all functions are available on that level you would have to cast the object to the correct type. Some time ago, this led to a little discussion on how to figure out what the type of the object is.

I want to propose a different design in my gui that will get rid of this problem.
Until now, the objects have always been stored inside the window. This had the great advantage of not having to store the objects on your own. You could let your pointer go out of scope and get it back from the window when you needed it. However, the window would not be able to distinguish the objects from each other and a cast was required.

What I want to ask is whether it is really necessary to give the window full control of the object?
It is nice that you don't have to store it yourself, but is this really needed?
Storing those objects isn't that much of a problem and you will be able to access the correct object when you need it (when you have a good design). So there will be no problem with casting because you decide where and how you store the objects.

If I make the change that I am planning then the following things will happen:
- You will be responsible for keeping the object alive (you may not let the pointer to it get out of scope)
- The get functions will most likely be removed from the window (or kept, but not intended to be used)
- The remove functions won't be needed either in most cases: just delete the object (if using a pointer to it).
- I will be able to simplify the add function so you no longer have to explicitly give the template type.

tl;dr Is it really necessary for the window to store the objects?
Might it not be better if you stored the objects yourself and keep full control of them?

EDIT: This change will make it impossible to copy groups of objects or to load objects from a file.
This will make my form builder obsolete unless I add a way to load single objects from a file.
« Last Edit: February 07, 2013, 01:46:54 pm by texus »
TGUI: C++ SFML GUI

netrick

  • Full Member
  • ***
  • Posts: 174
    • View Profile
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #378 on: February 09, 2013, 01:52:34 pm »
I think that for simplicity and easy-to-use the window should keep to store widgets. What do you need to do is to have containers in the window for every type of widget. You can hard-code container for every type and make specialized templated version of get and add.

But if you want, there is a simpler solution (creating containers on the fly on runtime!). Look at this question on stackoverflow and the top answer (selected one). LINK: http://stackoverflow.com/questions/14781901/class-that-creates-new-containers-for-type-known-from-its-template-member-functi

I believe that would be the best. This way, if users calls add<tgui::one> the container is created and the next time it is there. If the user doesn't add object of this type, the container doesn't exist. The code is very simple and you don't have to hard code function for every type. What do you think?

Also, I don't know any gui lib which requires you to manually store the widgets. It's just so uncomfortable.
« Last Edit: February 09, 2013, 01:55:09 pm by netrick »

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #379 on: February 09, 2013, 02:11:44 pm »
Thanks for the link, it looks interesting indeed.

I am currently looking to see how to implement a way with shared pointers which should solve this problem.
I guess I should take a look at how sfgui handles this exactly.
TGUI: C++ SFML GUI

netrick

  • Full Member
  • ***
  • Posts: 174
    • View Profile
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #380 on: February 09, 2013, 02:29:06 pm »
You can also have a look at Qt and wxWidgets.

Kaev

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #381 on: February 09, 2013, 08:41:53 pm »
Hello,

i'm using v0.6-dev and cant draw a label or sf::Text from a class.
When i put the code in my main.cpp, it works well.
Maybe a bug?

// Interface class
        Interface(tgui::Window &Spiel)
        {
                // Ebene
                tgui::Label* Ebene = Spiel.add<tgui::Label>("label");
                Ebene->setText("Ebene 0");
                Ebene->setPosition(360, 25);
                Ebene->setTextColor(sf::Color::White);
                Ebene->setTextSize(12);
       }
 

Also doesn't work when i create tgui::Label* Ebene at my attributes, doesn't work when i call Spiel.drawGUI() in my drawmethod.. it doesnt draw sf::Text also anymore.
Any help would be nice.

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #382 on: February 09, 2013, 08:50:18 pm »
If you can't draw sf::Text either then I don't think the problem will be with tgui.
Did you load a font?

I don't see anything wrong with that code, so if you are sure that you loaded the global font, could you provide a bit more code then?
TGUI: C++ SFML GUI

Kaev

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #383 on: February 09, 2013, 08:58:24 pm »
When i use sf::RenderWindow instead of tgui::Window, i can draw sf::Text.

// Main.cpp
tgui::Window Spiel(sf::VideoMode(640, 500, 32), "Spiel", sf::Style::Close);
...
        Spiel.globalFont.loadFromFile("Font/Seagram tfb.ttf");
...
        // Textbox works well in main.cpp
        tgui::TextBox* textbox = Spiel.add<tgui::TextBox>("textbox");
        textbox->load(150, 100, 12, "graphics/Black");
        textbox->setPosition(485, 320);
        textbox->changeColors(sf::Color(193, 177, 140), sf::Color::Black, sf::Color::Black, sf::Color::Transparent);
        textbox->setText("TEXT");

        // When i insert my Label here, it works also

...

Spiel.clear();
Spiel.drawGUI();
Spiel.display();

 

// Interface class
    Interface(tgui::Window &Spiel)
    {
        // Label Ebene doesn't work in class, but works in main.cpp
        // sf::Text doesn't work anymore in a class
        tgui::Label* Ebene = Spiel.add<tgui::Label>("label");
        Ebene->setText("Ebene 0");
        Ebene->setPosition(360, 25);
        Ebene->setTextColor(sf::Color::White);
        Ebene->setTextSize(12);
       }
 
 

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #384 on: February 09, 2013, 09:35:12 pm »
The following code works fine for me:
#include <TGUI/TGUI.hpp>

class Interface
{
public:

    Interface(tgui::Window& window)
    {
        tgui::Label* Ebene = window.add<tgui::Label>("label");
        Ebene->setText("Ebene 0");
        Ebene->setPosition(360, 25);
        Ebene->setTextColor(sf::Color::White);
        Ebene->setTextSize(12);
    }
};

int main()
{
    tgui::Window window(sf::VideoMode(800, 600), "TGUI window");
    window.globalFont.loadFromFile("TGUI/Fonts/DejaVuSans.ttf");

    Interface i(window);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();

            window.handleEvent(event);
        }

        window.clear();
        window.drawGUI();
        window.display();
    }

    return 0;
}

Does the above code works for you?
Either you will have to add some code to this until it no longer works or start removing code from your own project until it works again. You will have to narrow the problem down because I can't help much if I can't reproduce the problem.
TGUI: C++ SFML GUI

Kaev

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #385 on: February 09, 2013, 09:50:26 pm »
Doesn't work for me.

Testing around now, when i found on anything, i'll tell you.

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #386 on: February 10, 2013, 09:51:10 am »
If you answer these questions then I'll try to test it in the same environment as you (I currently only tested on linux).
What OS are you using?
Which compiler?
Do you use dynamic or static linking?

Here are a few things that you could still try:
- Don't use a class, but use a simple function (does it fails because it is in a class or because it isn't in main?)
- If you are using precompiled libraries, could you try rebuilding them yourself?
- I am not sure if this will have any influence, but do you have the latest drivers intalled?
- Try running the above code with v0.5. If that still doesn't work then at least I am sure that it isn't a bug in recent changes.
TGUI: C++ SFML GUI

netrick

  • Full Member
  • ***
  • Posts: 174
    • View Profile
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #387 on: February 10, 2013, 08:50:11 pm »
I need to display a lot of texts which will be visible only for a few second then disappear forever. I could do it manually but tgui labels are more handfull. But my question is, how can I delete (not just hide) the label?
« Last Edit: February 10, 2013, 08:52:51 pm by netrick »

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #388 on: February 10, 2013, 08:54:25 pm »
window.remove(myLabel) should do the trick.
TGUI: C++ SFML GUI

netrick

  • Full Member
  • ***
  • Posts: 174
    • View Profile
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #389 on: February 10, 2013, 08:57:30 pm »
Thank you.