0.7 Strategy on multiple tgui::GUI objects

Started by Heinrich, 09 October 2014, 13:59:07

Heinrich

Are there pitfalls on having multiple GUI objects? Or is it recommended to have one and only one GUI object (and access it via Singleton or something).

texus

You are not meant to use multiple Gui objects (at least not on the same window).

If you would, each would have its own list of widgets and you have to call handleEvent and draw on the correct gui. So this is only good for when you have multiple windows as well.

In order to have multiple screens in a single window, you should use the Panel widget. You create several panels, each for the different game states. Then you hide all of them except one. When changing state, you just hide the visible panel and show another one.

rbenn674

Furthering this question, I would like to use 2 GUI objects so that I can move the view of one GUI, and leave the view of the other gui the same so that it stays on top since it has the file menu header and scroll bars etc.. Does this seem logical or would it be more beneficial to do this in 1 gui object?

I haven't found a good way to make the individual groups or panels move correctly within a single GUI. Normally with a window you can update the view and move it around a larger image. You can do this with a single gui but it moves the whole gui, however I'm not sure about moving individual groups or panels or canvases.

texus

You are allowed to use multiple Gui objects for this, but I don't recommend it.

If part of the gui should be stationary then put all those widgets in a Group widget and keep the group at a fixed location. The stuff that needs a different "view", which needs to move around, is put into a different group. You simply change the position of the second group whenever you need to move it around. The only widgets that are added directly to the gui would be the two groups, all other widgets would be added to one of the two groups.

rbenn674

#4
So the problem with this is the following:

Say I have a group with positon 0, 0 but my button in the group is at 150, 150. As I scroll the screen down the group needs to move up and off the screen, however this would require the positon to be subtracted from 0, ie a negative number. When entering a new positon of a negative number an error will appear.

Also, I don't see any function to change the positon of the group currently available.

I suppose I could create a double large window, say 4096 x 4096, instead of 2048 x 2048, move the window view to start at 2048, 2048 instead of 0, 0  to allow objects to move up off the screen, but that seems a bit inefficient as well... But maybe the larger window isn't inefficient as long as the view is smaller.

texus

Negative positions should work fine. What error do you get?

rbenn674

#6
Initially
group1->setPosition(0,-scrollValue);Error:   C4146   unary minus operator applied to unsigned type, result still unsigned         


Changed to
group1->setPosition(0,0-scrollValue);
This worked, however as soon as scrollValue goes positive from 0 the group disappears completely and will not return onto the screen even when scrollValue is returned to 0.

Actually tried setting position to any value and it disapears. Not sure what I am missing.

rbenn674

Fixed it. The unsigned int was throwing it off. Changed it to

group1->setPosition(10, (-(float)scrollValue));
with success.

Thanks for the help.