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 - Hexade

#1
Alright, thanks for clearing it up.
#2
Alright, after playing around with tgui::Group for a while it seemed as though Group::draw() is just drawing the stored widgets to the group rather than the window. And it is still the Gui::draw() function that controls when the widgets are actually drawn to the screen. So I created a small demo to test how tgui::Group works a bit and ended up with this:

#include "TGUI/TGUI.hpp"

int main() {

sf::RenderWindow window(sf::VideoMode(800, 600), "Group Test");
tgui::Gui gui(window);

tgui::Button::Ptr button_1 = tgui::Button::create("Button 1");
button_1->setPosition(5, 5);

tgui::Button::Ptr button_2 = tgui::Button::create("Button 2");
button_2->setPosition(5, 30);

tgui::Group::Ptr group = tgui::Group::create();
group->setSize(400, 300);
group->add(button_1);
group->add(button_2);

while (window.isOpen()) {

sf::Event event;

while (window.pollEvent(event)) {

switch (event.type) {

case sf::Event::Closed:
window.close();
break;

}

gui.handleEvent(event);

window.clear();

group->draw(window, sf::RenderStates::Default);
                        gui.draw();

window.display();

}

}

}


Now the main part that I'd like to point your attention to are these two lines:

group->draw(window, sf::RenderStates::Default);
gui.draw();


In their current order the buttons get rendered to the screen as you would expect, changing the order so that Gui::draw() is called before Group::draw() also causes them to be rendered as normal. Commenting out the call to Group::draw() will cause nothing to be drawn to the screen as expected. But if we comment out the call to Gui::draw() whilst leaving in the call to Group::draw(), it will render the buttons to the screen but they are squashed and somewhat distorted.

Based on my first tests when trying to implement tgui::Group I thought that the call to Group::draw() was just drawing the widgets to some texture that is stored by the Group. And that it is not rendered to the screen until we call Gui::draw(). However this little demo shows the buttons are being drawn to the screen by Group::draw(), however they are not being drawn correctly.

So now I am a bit confused as to what happens when we call Group::draw()? And just to be clear I get the squashed buttons when commenting out the Gui::draw() call like so:

group->draw(window, sf::RenderStates::Default);
//gui.draw();
#3
tgui::Group definitely seems to be more along the lines of what I am looking for. I have just tried quickly implementing it but I am getting some unusual behaviour that is probably caused by things unrelated to the tgui::Group. I'll play around with it for a while and get back to you if it works out or not. Thanks.
#4
I just tried to implement a tgui::Canvas however it looks as though it is made for use with SFML's sf::Drawable class. What I am trying to render is a tgui::Picture so a canvas won't work. Ideally I would be able to create some sort of group of widgets that is attached to the main tgui::Gui, and I would be able to call Gui::draw() on that group specifically so that those widgets are rendered at a different time to the rest of the GUI. Something like:

tgui::Gui gui;
gui.setTarget(window);

tgui::WidgetGroup group_1;
tgui::WidgetGroup group_2;
group_1.add();               // Add widgets to the group similarly to Gui::add()
group_2.add();

gui.draw(group_1);           // Draw the widgets that belong to the given group only
gui.draw(group_2);


The idea is that the groups would store different widgets and you can draw the groups at any time rather than having to draw all widgets at once with Gui::draw(). I am not sure if something like this already exists within TGUI so please point me in the right direction if there is. But this is basically what I am asking to do with the original question.

I have read billarhos' suggestion as well however I haven't tried it because I am assuming calling Gui::draw() twice is going to cause all the visible widgets to get rendered twice per frame which isn't ideal. Also the location where I am calling Gui::draw() is within the main program loop so it is not going to handle setting very specific widgets to visible/invisible since those widgets do not exist from the beginning of the program. I appreciate the suggestions though.

#5
Hi,

When drawing the GUI with draw() it draws all widgets stored within the GUI. At the moment my code looks like this:
current_state->render();
gui->render();


Where I have implemented a state machine so that each state has control over the sf::Texts and sf::Sprites being rendered. The issue that I am having is that I am rendering text that needs to go on top of a widget, but since I am rendering the GUI after the text, the widget is being drawn on top of the text preventing you from seeing it. I did get around this in an earlier project by simply creating a second GUI so that I could store the overlapping widgets within the second GUI and render that prior to rendering the text. However I have read in past forum posts that you probably shouldn't be creating multiple instances of tgui::Gui.

So, I am wondering what is the best way to go about controlling when specific widgets are rendered (like how I am controlling the text / sprites being rendered with the state machine) rather than having them all render at the same time. Thanks.
#6
Alright, that clears everything up then. Thanks a lot for the help and clarification.
#7
Hi,

I am having trouble understanding how to use std::bind to call a function as part of tgui::SignalWidgetBase::connect(). I was looking at the "Introduction to signals" tutorial for version 0.7 where you show this example (It's probably worth noting that I am using version 0.8.5):

int getNum() { return 5; }

void func1(int i);
void func2(int value);

picture->connect("clicked", func1, std::bind(getNum));
button->connect("pressed", func2, std::bind(&tgui::Slider::getValue, slider));


My need for std::bind is a bit more complex than this example and this is my first time using std::bind so I have been spending the day learning about std::bind and std::function. This is what my function looks like at the moment:

void TitleMenuButton::SetFunctions(bool& button_selected, std::string& current_button, std::function<Button&(std::string)> get_button_function) {

button_image->connect("MouseEntered", &TitleMenuButton::ButtonFocused, this, std::ref(button_selected), std::ref(current_button), std::bind(get_button_function, current_button));
button_image->connect("MouseLeft", &TitleMenuButton::ButtonUnfocused, this, std::ref(button_selected), std::ref(current_button));

}


This function belongs to the TitleMenuButton class that stores a tgui::Picture (button_image), the function simply calls connect() on the tgui::Picture and connects the TitleMenuButton::ButtonFocused() and TitleMenuButton::ButtonUnfocused() functions. The issue lies with my attempt at using std::bind to bind the function ButtonList::GetButton().

This function belongs to a ButtonList class that stores x amount of TitleMenuButtons. It is designed to make creating the buttons much faster and easier, so this TitleMenuButton::SetFunctions() function is called from within the ButtonList class as such:

std::function<Button&(std::string)> get_button_function = std::bind(&ButtonList::GetButton, this, std::placeholders::_1);
button->SetFunctions(is_focusing_button, current_button, get_button_function);


Lastly, the function I am attempting to bind is ButtonList::GetButton() that returns a reference to one of the buttons stored within the ButtonList.

public:
Button& GetButton(std::string button_name) { return *button_list.at(button_name); }

private:
std::unordered_map<std::string, std::unique_ptr<Button>> button_list;


So the idea behind all of this code is that the ButtonList creates and stores instances of TitleMenuButton and keeps track of which button is currently "active" (Being hovered over with the mouse / keyboard). During the creation process of the TitleMenuButtons we need to connect functions to the various signals to give them functionality. Now on to the actual error I am getting.

Visual Studio seems to like the code and doesn't produce any red squiggly lines, however when I try to compile it I receive 2 errors.

'operator __surrogate_func': no matching overloaded function found
Failed to specialize function template 'unknown-type std::Mem_fn<void (__thiscall TitleMenuButton::* )(bool &,std::string &,Button &)>::operator ()(_Types &&...) noexcept(<expr>) const'


Both of these errors occur in signalimpl.hpp at lines 89 and 88 respectively. Unfortunately both of these error messages are lost on me and I can't figure out what I am doing wrong. I have tried a plethora of methods of passing the function from an instance of ButtonList to an instance of TitleMenuButton but none of them have worked. This seems to be my best attempt so far and I don't think I am that far off from getting it working. However the error messages that point me to TGUI files don't help me much.

If you need to see more of the code then just ask although I hope I have covered everything. Thanks.