JNGL
Easy to use cross-platform 2D game library
Loading...
Searching...
No Matches
work.hpp
Go to the documentation of this file.
1// Copyright 2012-2026 Jan Niklas Hasse <jhasse@bixense.com>
2// For conditions of distribution and use, see copyright notice in LICENSE.txt
4#pragma once
5
6#include "Vec2.hpp"
7#include "job.hpp"
8
9#include <memory>
10
11namespace jngl {
12
14class Work : public Job {
15public:
40 virtual void onBackEvent();
41
58 virtual void onQuitEvent();
59
66 virtual void onControllerBack();
67
72 virtual void onPauseEvent();
73
75 virtual void onLoad();
76
78 virtual void onUnload();
79
87 virtual void onToggleFullscreen();
88
125 virtual bool supportsScreenSize(Vec2 screenSize) const;
126};
127
130
133[[deprecated("Use setScene(std::shared_ptr<Scene>) instead")]]
135
137template <class T, class... Args> T& setWork(Args&&... args) {
138 auto shared = std::make_shared<T>(std::forward<Args>(args)...);
139 auto& rtn = *shared;
140 setScene(std::move(shared));
141 return rtn;
142}
143
149
150} // namespace jngl
Contains jngl::Vec2 class.
Background job which stays part of the main loop independent of the active jngl::Scene.
Definition job.hpp:62
Two-dimensional vector.
Definition Vec2.hpp:36
Active state of the game, e.g. a menu or the game itself.
Definition work.hpp:14
virtual void onPauseEvent()
Gets called when the main window loses focus or the app is put in the background.
virtual void onQuitEvent()
Gets called when the user closes the main window or quit() has been called.
virtual void onControllerBack()
Gets called when the "Back" button is pressed on any connected controller (Android only)
virtual bool supportsScreenSize(Vec2 screenSize) const
Gets asked by JNGL whether this Scene could be shown with screenSize instead of letter-boxing.
virtual void onLoad()
Gets called when the Work is activated by the main loop.
virtual void onUnload()
Gets called when the Work is deactivated by the main loop.
virtual void onToggleFullscreen()
Gets called when the user pressed Alt + Enter
virtual void onBackEvent()
Gets called on Android's "back" gesture or when the Esc key is pressed.
T forward(T... args)
Contains jngl::Job class and related functions.
T make_shared(T... args)
JNGL's main namespace.
void resetFrameLimiter()
Resets the automatic frame limiter of App::mainLoop().
std::shared_ptr< Work > getWork()
Returns the current active Work or nullptr if none has been set.
void setWork(std::shared_ptr< Work > work)
Sets the passed Work to be active in the main loop.
void setScene(std::shared_ptr< Scene >)
Sets the passed Scene to be active in the main loop for the next frame.