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 - Demonic Ice

#1
Hello TGUI-forum!

I recently decided to give TGUI a try and wanted to include it into my engine.
However I am not able to set it up as I want.

First of all there is my overall cpp part which calls the game to run.
Then the next called cpp file creates the new state via constructor.
The following step would be calling the state's voids:

1. An event void
Dealing with all the event points.

2. An update void
Just updating or doing whatever the state is supposed to do.

3. A draw function
Drawing all visualised things.

All these 3 are passing the arguement of the SFML window.

Now, my target is to efficiently part TGUI within this structure and not outside.

In contrast I succeeded to plainly implement TGUI into the cpp where the window itself gets defined.
Also I did succeed to implement TGUI into the draw void of the state.
However both of these ways are not in my interest of a final way of working.
The first one denies me to efficiently work with TGUI.
On the second attempt it will declare TGUI over and over again.

Therefore I tried this:

tgui::Gui gui(window);

became
tgui::Gui gui;
and got declared in the class part from the state in which I wanted to use TGUI.

Then the constructor adds all the buttons I wanted to display.

gui.setFont("assets/fonts/OpenSans-Regular.ttf");
auto play = std::make_shared<tgui::Button>();
play->setPosition(tgui::bindWidth(gui)*0.15, tgui::bindHeight(gui)*0.125);
play->setSize(tgui::bindWidth(gui)*0.7, tgui::bindHeight(gui)*0.15);
play->setText("Play");
gui.add(play);


Handling the events will then simply be stored in the handle event void.
However now I start to get to some issues.

How do I tell where the window is at for TGUI?
I tried something ugly with a bool and an if already.
Sadly I get a null pointer error once my program gets to the moment of drawing, though.

The bool thing was something like:
Quote
if (!gui_active){

gui_active = true;
tgui::Gui gui(window);

}
if (gui_active){

gui.draw();

}
The bool was set to false in first place of course. Moreover this felt really bad in terms of design.

Sadly gui.draw() lacks the possibility to pass the window as an arguement.
Therefore I am a bit clueless right now.

I would be really happy if anyone could help me out of this problem!

Thanks for taking your time to read this thread!