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

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

0 Members and 4 Guests are viewing this topic.

texus

  • Sr. Member
  • ****
  • Posts: 499
    • View Profile
    • TGUI
    • Email
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #345 on: January 02, 2013, 03:45:38 pm »
Sure, just change its callbackID and it should start sending callbacks on click.
TGUI: C++ SFML GUI

texus

  • Sr. Member
  • ****
  • Posts: 499
    • View Profile
    • TGUI
    • Email
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #346 on: January 04, 2013, 08:25:52 pm »
I followed the suggestions to improve the new callback system.

Here is what you can do with it now.
Because a boost::function is now accepted as parameter, you can of course do more.
void function1() {}
void function2(const tgui::Callback& callback) {}

struct myClass {
    void function3() {};
    void function4(const tgui::Callback& callback) {};
} myObj;

auto function5 = []() {};
auto function6 = [](const tgui::Callback& callback) {};

struct myFunctor {
    void operator()() {}
} function7;

unsigned int trigger = tgui::Button::LeftMouseClicked;

button->bindCallback(function1, trigger);
button->bindCallbackEx(function2, trigger);
button->bindCallback(&myClass::function3, &myObj, trigger);
button->bindCallbackEx(&myClass::function4, &myObj, trigger);
button->bindCallback(function5, trigger);
button->bindCallbackEx(function6, trigger);
button->bindCallback(function7, trigger);
button->bindCallback(trigger); // just handle the callback the old way
TGUI: C++ SFML GUI

netrick

  • Full Member
  • ***
  • Posts: 174
    • View Profile
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #347 on: January 06, 2013, 10:50:32 am »
Nice! You are doing very nice job!
I have a performance question regarding buttons. If button texture files are 256x256 and I set button's size to 32x32, the textures will be cut internally by TGUI for drawing, yes?

texus

  • Sr. Member
  • ****
  • Posts: 499
    • View Profile
    • TGUI
    • Email
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #348 on: January 06, 2013, 11:49:11 am »
No, the setSize function doesn't cut the texture, it just scales it.
TGUI: C++ SFML GUI

netrick

  • Full Member
  • ***
  • Posts: 174
    • View Profile
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #349 on: January 06, 2013, 12:02:13 pm »
Okay. Anyway, is there a chance that clickable rectangle object will be added anytime soon? I think that it's just needed to remove some code from button and it would help me, as messing with transparent buttons isn't the clean way.

texus

  • Sr. Member
  • ****
  • Posts: 499
    • View Profile
    • TGUI
    • Email
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #350 on: January 06, 2013, 12:40:09 pm »
I wasn't really planning on adding them soon.
But it shouldn't be difficult to write it, so I'll see if I can get this done today.
TGUI: C++ SFML GUI

netrick

  • Full Member
  • ***
  • Posts: 174
    • View Profile
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #351 on: January 06, 2013, 02:12:58 pm »
I have a question. From source it seems that click callbacks are send on mouse release rather than on mouse down. Is there a way to have the callback on the press without waiting for release?

texus

  • Sr. Member
  • ****
  • Posts: 499
    • View Profile
    • TGUI
    • Email
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #352 on: January 06, 2013, 02:25:33 pm »
Only in tgui v0.6 is this possible without making any changes yourself.

If you want it in v0.5 then you will have to change the source code.
Just add the following lines to the leftMousePressed function of the object:
if (callbackID > 0)
{
    Callback callback;
    callback.object = this;
    callback.callbackID = callbackID;
    callback.trigger = Callback::mouseDown;
    callback.mouseButton = sf::Mouse::Left;
    callback.mouseX = x - getPosition().x;
    callback.mouseY = y - getPosition().y;
    m_Parent->addCallback(callback);
}
TGUI: C++ SFML GUI

netrick

  • Full Member
  • ***
  • Posts: 174
    • View Profile
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #353 on: January 06, 2013, 02:26:33 pm »
Thanks. If I add that code, do I need to remove callback code from leftMouseReleased?

texus

  • Sr. Member
  • ****
  • Posts: 499
    • View Profile
    • TGUI
    • Email
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #354 on: January 06, 2013, 02:33:58 pm »
That depends on what you want to do.

If you leave the code in leftMouseReleased then you will get 2 callbacks: one when the mouse went down and one when the mouse was released again. The callback.trigger is different, so you are perfectly able to distinguish the callbacks from each other.

If you only need callback on mouse down then you can remove the code.
TGUI: C++ SFML GUI

netrick

  • Full Member
  • ***
  • Posts: 174
    • View Profile
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #355 on: January 06, 2013, 02:41:03 pm »
Thank you, it works.
« Last Edit: January 06, 2013, 02:44:19 pm by netrick »

netrick

  • Full Member
  • ***
  • Posts: 174
    • View Profile
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #356 on: January 06, 2013, 08:00:03 pm »
Just a question not related to my problem which I pm'ed you - when I have objects that I add to the panel, is there a way to set their position relatively to the tgui window instead of panel? That would be quite useful.

texus

  • Sr. Member
  • ****
  • Posts: 499
    • View Profile
    • TGUI
    • Email
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #357 on: January 06, 2013, 08:09:15 pm »
No, the whole idea of a Panel was to allow objects to be placed on a relative position instead of an absolute position on the window.

All you can do is subtract the panel's position from the object.
object->setPosition(sf::Vector2f(300, 200) - panel->getPosition());
TGUI: C++ SFML GUI

netrick

  • Full Member
  • ***
  • Posts: 174
    • View Profile
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #358 on: January 06, 2013, 08:16:59 pm »
That's enough, thanks. I need the windows coordinates because as you know I draw images with sfml and then I need them to be tgui clickable objects.

netrick

  • Full Member
  • ***
  • Posts: 174
    • View Profile
Re: TGUI: a c++ GUI for SFML (with Form Builder)
« Reply #359 on: January 07, 2013, 06:52:46 pm »
Is there a way to disallow user to click on checkbox? I mean I controll if it's checked/unchecked and the user can only see it and can't click on it.

EDIT:
Also, is there a way to have a group of checkboxes in which only one of them can be checked at once? It's quite important feature.
« Last Edit: January 07, 2013, 07:02:53 pm by netrick »