TGUI
0.9.5
|
Executes callbacks after a certain amount of time. More...
#include <TGUI/Timer.hpp>
Public Types | |
typedef std::shared_ptr< Timer > | Ptr |
Public Member Functions | |
Timer (const Timer &)=delete | |
Timer & | operator= (const Timer &)=delete |
void | setInterval (Duration interval) |
Changes the interval at which a timer callback is send. | |
Duration | getInterval () const |
Returns the interval at which a timer callback is send. | |
void | setEnabled (bool enabled) |
Starts or stops a timer. | |
bool | isEnabled () const |
Returns whether the timer is running. | |
void | setCallback (const std::function< void()> &callback) |
Changes the callback function that should be called by the timer at each interval. | |
void | setCallback (const std::function< void(std::shared_ptr< Timer >)> &callback) |
Changes the callback function that should be called by the timer at each interval. | |
void | restart () |
Restarts the timer. | |
Static Public Member Functions | |
static std::shared_ptr< Timer > | create (const std::function< void()> &callback, Duration interval, bool enable=true) |
Sets the time that the mouse has to stand still before the tooltip becomes visible. | |
static std::shared_ptr< Timer > | create (const std::function< void(std::shared_ptr< Timer >)> &callback, Duration interval, bool enable=true) |
Sets the time that the mouse has to stand still before the tooltip becomes visible. | |
static void | scheduleCallback (std::function< void()> callback, Duration interval=Duration()) |
Starts a timer. | |
static bool | updateTime (Duration elapsedTime) |
static Optional< Duration > | getNextScheduledTime () |
static void | clearTimers () |
Executes callbacks after a certain amount of time.
The static create method will create a timer object that you can start and stop. The static scheduleCallback method is for when the timer only needs to be triggered a single time.
This timer is not intended to be used when high accuracy is required. If the callback is e.g. a millisecond too late then this extra time is NOT subtracted from the next scheduled time.
|
static |
Sets the time that the mouse has to stand still before the tooltip becomes visible.
callback | Function without parameters, to be called at every interval when the timer is enabled |
interval | How often the callback should be called |
enable | Should the timer be started immediately? |
|
static |
Sets the time that the mouse has to stand still before the tooltip becomes visible.
callback | Function that takes the timer as parameter, to be called at every interval when the timer is enabled |
interval | How often the callback should be called |
enable | Should the timer be started immediately? |
Duration tgui::Timer::getInterval | ( | ) | const |
Returns the interval at which a timer callback is send.
bool tgui::Timer::isEnabled | ( | ) | const |
Returns whether the timer is running.
|
static |
Starts a timer.
callback | Function to call at every interval when the timer is enabled |
interval | Time until callback should occur. Don't pass this parameter to call the callback at the next update. |
There is no way to cancel a scheduled call. If you need this functionality then you should create a proper timer (with the create function) which you then stop when the callback happens.
void tgui::Timer::setCallback | ( | const std::function< void()> & | callback | ) |
Changes the callback function that should be called by the timer at each interval.
callback | Function without parameters, to be called at every interval when the timer is enabled |
void tgui::Timer::setCallback | ( | const std::function< void(std::shared_ptr< Timer >)> & | callback | ) |
Changes the callback function that should be called by the timer at each interval.
callback | Function that takes the timer as parameter, to be called at every interval when the timer is enabled |
void tgui::Timer::setEnabled | ( | bool | enabled | ) |
Starts or stops a timer.
When enabling a timer that is already enabled, the timer will be restarted.
void tgui::Timer::setInterval | ( | Duration | interval | ) |
Changes the interval at which a timer callback is send.
interval | How often the callback should be called |