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

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

0 Members and 5 Guests are viewing this topic.

Xurix

  • Newbie
  • *
  • Posts: 14
    • MSN Messenger - Luixsia@crimasi.com
    • AOL Instant Messenger - Luixsia
    • Yahoo Instant Messenger - Luixsia@yahoo.com
    • View Profile
    • http://www.crimasi.com
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #165 on: August 25, 2012, 05:10:51 pm »
Texus can you make Panel's draw function public? It's just I'd like to be able to use Panels to layer the order in which i draw things, so I can draw things outside of TGUI in-between the drawing of the GUI. I'd rather not have to make a new object just so I can draw things in the correct order.
Sorry if I'm being an idiot and missed something to let me do this already.

Turns out I'm an idiot who should have tested window.draw(PanelName); before posting this.

Also can I request a feature for the form builder? The feature being the ability to use percentage based values for size and position. I'd like to use form builder generated/self made text files for all my interfaces but I simply can't while allowing my program to have different resolutions set for it.
« Last Edit: August 25, 2012, 05:44:56 pm by Xurix »
SFML - Simply Fun on Many Levels

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #166 on: August 25, 2012, 05:46:44 pm »
I don't really understand what you are trying to do with the Panel, but the draw function doesn't has to be public.
To draw an object you can just do this:
window.draw(myPanel);
But if you don't let the gui handle the objects and you draw them manually then you will soon find some limitations.

I can't add the feature to the form builder right now. It is not something that can be added very easily and I will have to rewrite the whole form builder in the future anyway. But when I do rewrite it, I will see if I can implement something like this. However chances are big that you can already do this directly in tgui itself by that time.

But maybe I could make a small workaround for now.
Would it be enough for you to be able to define the window size at the top of the object file and for the position and size just put a calculation instead of a number? You will of course have to write the object files yourself, but you could let the form builder generate one so that you only have to change the position and sizes.
Like this, you will only have to change the window size in the file and all objects will be repositioned.
TGUI: C++ SFML GUI

Xurix

  • Newbie
  • *
  • Posts: 14
    • MSN Messenger - Luixsia@crimasi.com
    • AOL Instant Messenger - Luixsia
    • Yahoo Instant Messenger - Luixsia@yahoo.com
    • View Profile
    • http://www.crimasi.com
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #167 on: August 25, 2012, 05:57:19 pm »
Yeah sorry about asking a stupid question when the answer was already there.
What limitations will I run into?

That workaround would work fine :)
SFML - Simply Fun on Many Levels

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #168 on: August 25, 2012, 06:10:35 pm »
If you call drawGUI then all objects will be drawn, even the object that you are drawing manually earlier or later. This might no be what you want. You can always try to not add the object to the window at all and then draw it, but then the objects won't receive any events.
I just don't see why you are drawing an object yourself. Unless you are drawing all the objects manually.

I'll see if I can make that workaround.
I just have to allow calculations as it is already possible to define numbers.
Edit: Don't expect this today. I am resizing my partition and it is going to take more than two hours before I can access it again.
« Last Edit: August 25, 2012, 06:25:21 pm by texus »
TGUI: C++ SFML GUI

Xurix

  • Newbie
  • *
  • Posts: 14
    • MSN Messenger - Luixsia@crimasi.com
    • AOL Instant Messenger - Luixsia
    • Yahoo Instant Messenger - Luixsia@yahoo.com
    • View Profile
    • http://www.crimasi.com
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #169 on: August 25, 2012, 06:30:12 pm »
Oh It's not I'm trying to stop an object from being drawn, as I could easily hide and disable it. What i'm trying to do is draw Spritesheets as one layer in a Panel, then draw Particles from Thor, then draw the interface Panel ontop of it all.

So i'd be doing this

 
draw()
{
      window.draw(*worldpanel);
      window.draw(particles);
      window.draw(*interfacepanel);
}
 

I'm not worried too much about having it today, I can make due with doing the interface in code as I have it atm till you're done. :)
SFML - Simply Fun on Many Levels

model76

  • Full Member
  • ***
  • Posts: 231
    • View Profile
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #170 on: August 25, 2012, 08:47:27 pm »
Hi texus,

I seem to have run into a problem with the text scaling now.. Is there currently any way to re-size an EditBox in TGUI without scaling the text? I wanted to make a small EditBox, but the text became so blurry that it was hardly readable.

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #171 on: August 25, 2012, 11:00:13 pm »
You could try to set the text size yourself with setTextSize.
TGUI: C++ SFML GUI

model76

  • Full Member
  • ***
  • Posts: 231
    • View Profile
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #172 on: August 26, 2012, 04:13:23 am »
I did try that, but the text didn't event display. I guessed it was because the scaling was still applied, and now the text was simply much smaller to begin with.

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #173 on: August 26, 2012, 05:01:07 am »
I was afraid of that.
This will be another thing to fix when rewriting EditBox.
But I was already planning to see if I could fix the blurry text during the rewrite, so with a little bit of luck you won't even have to set the text size yourself.

This might take a few days to get fixed.
TGUI: C++ SFML GUI

model76

  • Full Member
  • ***
  • Posts: 231
    • View Profile
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #174 on: August 26, 2012, 05:46:53 am »
Sounds good, texus.

Now I have another problem, though. Well, actually 2, also with EditBox:

First of all, it would be nice with a "lost focus" event. I can simulate that by checking if an sf::Event::MouseButtonPressed happened outside a focussed EditBox, before passing the event to TGUI.
It would be more practical if it could happen automatically, though.

Second, I would like to unfocus an EditBox when the return key is pressed, but I can't figure out how to do so. I tried objectUnfocused(), but that seems to do nothing.

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #175 on: August 26, 2012, 07:05:16 am »
The problem with the events is that I don't want to slow the program down by sending too many events. There are so many events that are missing and that might be useful in certain situations, but I can't send all of them. So right now, only the most important events are send and this will stay until I find a good method to choose the needed events.

The objectUnfocused funtion is called automatically when the object gets unfocused but it doesn't unfocus the object itself.
I though I had added focus and unfocus functions to the objects, but apparently I didn't. So you will have to ask the parent object to unfocus the object for now.
window.unfocus(myEditbox);
TGUI: C++ SFML GUI

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #176 on: August 26, 2012, 01:44:34 pm »
It is now possible to make calculations in the position and size of the objects inside the object files.

You will have to use left/top/width/height instead of position/size to make use of it.
You should also note that a calculation has to be inside quotes, while a fixed number should be written without quotes.

Here is an example to create a picture that is centered and has a size of a third of the window.
// Set the size of the window
// You are currently limited to lowercase characters in the define
define: window_width  = 800
define: window_height = 600

Window:
{
    Picture: "myPicture"
    {
        // Load the image
        Filename = "ThinkLinux.jpg"

        // The image size will be a third of the window
        Width = "window_width / 3"
        Height = "window_height / 3"

        // Position the image in the center of the window
        Left  = "(window_width - (window_width / 3)) / 2"
        Top   = "(window_height - (window_height / 3)) / 2"
    }
}
TGUI: C++ SFML GUI

model76

  • Full Member
  • ***
  • Posts: 231
    • View Profile
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #177 on: August 26, 2012, 04:09:27 pm »
... you will have to ask the parent object to unfocus the object for now.
window.unfocus(myEditbox);
I tried that, but I can't make it work. Here is a minimal example of what I am trying to do:
#include <SFML/Graphics.hpp>
#include <TGUI/TGUI.hpp>

int main()
{
        sf::RenderWindow window( sf::VideoMode( 1024, 768 ), "TGUI" );
       
        sf::Font myFont;
        myFont.loadFromFile( "resource/TGUI/DejaVuSans.ttf" );
       
        tgui::Form gui( window );
        gui.globalFont = myFont;
       
        tgui::EditBox *myEditBox = gui.add<tgui::EditBox>( "" );
        myEditBox->load( "resource/TGUI/objects/EditBox/Black" );
        myEditBox->callbackID = 1;

        while( window.isOpen() )
        {
                sf::Event event;
                while( window.pollEvent( event ) )
                {

                        if( event.type == sf::Event::Closed )
                                window.close();

                        else if( event.type == sf::Event::KeyPressed &&
                                 event.key.code == sf::Keyboard::Return )
                                gui.unfocus( myEditBox );
                       
                        gui.handleEvent( event );
                }

                tgui::Callback callback;
                while( gui.getCallback( callback ) )
                {
                        std::cout << "There was a callback event" << std::endl;
                }

                window.clear();
                gui.draw();
                window.display();
        }
       
    return EXIT_SUCCESS;
}

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #178 on: August 26, 2012, 04:26:14 pm »
I am an idiot. I was telling the event manager to focus the object instead of unfocusing it.
It is fixed now and I have also added focus and unfocus functions to all objects.
« Last Edit: August 26, 2012, 04:28:39 pm by texus »
TGUI: C++ SFML GUI

model76

  • Full Member
  • ***
  • Posts: 231
    • View Profile
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #179 on: August 26, 2012, 04:40:16 pm »
Don't be so hard on yourself.

I once spent an hour debugging a condition in an if statement that would seemingly always evaluate to 'true'. I tried everything I could think of, but the code in the pointy brackets would always execute, no matter what I did.

Then I noticed the semicolon after the close parenthesis.

Programming is a humbling experience. :)