Skip to content

Application

Nathan S edited this page Jun 16, 2020 · 7 revisions

The Application class is what holds the global state of your app. It has a number of useful methods - see the class header for that.

The view stack

An application is actually made of a view tree stack, rather than a single view tree. It means that you can overlay views on top of others by pushing them on the stack (for instance a dialog or a popup frame). Popping the bottom view in the stack is equivalent to quitting the app (you can tweak that behavior to prevent popping it instead).

Pushing a view on the stack will lay it out and give it focus immediately. If the new view is not focusable then the focus highlight will disappear until the view is popped. When you pop a view, it gives focus back to the last focused view prior to pushing the one you just popped (so there is also a focus stack next to the view stack).

There can also be different animations played, based on the transparency settings of the different views (View::isTranslucent). For instance, pushing a translucent view on top of a non-translucent one will do a simple fade-in, however pushing a non-translucent view on top of any view will trigger a more complex fade-out-fade-in animation. The same goes for the other way around (popping views).

Main loop throttler

The main loop has a built-in throttler that prevents taking 100% of the CPU when running. It works by yielding the process to prevent looping more than X times a second.

The aim is NOT to accurately lock at a given framerate or wait for VBLANK. The animations engine is already framerate independant and will give smooth animations regardless of the loop speed.

You can control the throttler by calling Application::setMaximumFPS(). Using 0 will disable the throttler. Default value is 60FPS, which means a frame interval of 16.6666ms. Again, this is not accurate so don't expect perfect 60FPS locking.

Clone this wiki locally