0

Ok, so I'm making a game using FLTK. And I have a function that prints a splash screen that is a subclass of Fl::window that I made with the buttons "Play" and "Rules". When a user clicks "Rules", it prints another Fl::window subclass with a "Back" button and the rules (obviously). My problem is first to figure out how to display the original splash screen when the user presses back. I know I can just create a second identical splash screen that pops up when the button is pressed, but then that means the user can only go from "Rules" and "Back" one time. I would prefer it to be a loop, so that the user can press "Rules"-->"Back"-->"Rules"-->"Back" as many times as he/she would like. Does that make sense? Any ideas?

UnworthyToast
  • 825
  • 5
  • 11
  • 21

1 Answers1

0

Normally each gui can represented as a nested state machine. If you go into another screen ( state ) you destroy your actual displayed widget or window and create a new one. If there is a button, which brings you "back" to the first state, you do simply the same: Destroy the actual widget or screen and create the first one again. Very simple or not :-)

If you go into a deeper hierarchy of your SM, you create a new widget over your already existing one of your higher state. Leaving this substates will delete all the widgets from this level. Changing the level of the substates only destroy the widgets of the substates and create new ones in the same level.

In c++ is it very easy to represent a state machine with classes. Entering a state creates an instance of a class and leaving it destroys the instance which represents it.

With c++11 you can use "new at" operator on a union, which "contains" all states you have in the level of your application. The union guarantees, that you have reserved enough memory and you do not need to use new/delete at all which can be a problem on small systems without MMU. I expect if you are using fltk, you have a small system :-)

With C++03 you can not use non trivial classes inside a union, so c++11 is a real simplification here!

Have fun!

Klaus
  • 24,205
  • 7
  • 58
  • 113