TGUI
=
=
Download
Tutorials
1.x
0.9
0.8
Documentation
1.x
0.9
0.8
Examples
1.x
0.9
0.8
Community
TGUI
1.x-dev
Toggle main menu visibility
Loading...
Searching...
No Matches
include
TGUI
Timer.hpp
1
2
//
3
// TGUI - Texus' Graphical User Interface
4
// Copyright (C) 2012-2026 Bruno Van de Velde (vdv_b@tgui.eu)
5
//
6
// This software is provided 'as-is', without any express or implied warranty.
7
// In no event will the authors be held liable for any damages arising from the use of this software.
8
//
9
// Permission is granted to anyone to use this software for any purpose,
10
// including commercial applications, and to alter it and redistribute it freely,
11
// subject to the following restrictions:
12
//
13
// 1. The origin of this software must not be misrepresented;
14
// you must not claim that you wrote the original software.
15
// If you use this software in a product, an acknowledgment
16
// in the product documentation would be appreciated but is not required.
17
//
18
// 2. Altered source versions must be plainly marked as such,
19
// and must not be misrepresented as being the original software.
20
//
21
// 3. This notice may not be removed or altered from any source distribution.
22
//
24
25
#ifndef TGUI_TIMER_HPP
26
#define TGUI_TIMER_HPP
27
28
#include <TGUI/Config.hpp>
29
30
#include <TGUI/Duration.hpp>
31
#include <TGUI/Optional.hpp>
32
33
#include <functional>
34
#include <memory>
35
#include <vector>
36
38
39
namespace
tgui
40
{
50
class
TGUI_API Timer :
public
std::enable_shared_from_this<Timer>
51
{
52
public
:
53
using
Ptr = std::shared_ptr<Timer>;
// Only provided for potential consistence in user code
54
55
Timer(
const
Timer&) =
delete
;
56
Timer& operator=(
const
Timer&) =
delete
;
57
67
[[nodiscard]]
static
std::shared_ptr<Timer>
create
(
const
std::function<
void
()>& callback,
Duration
interval,
bool
enable =
true
);
68
78
[[nodiscard]]
static
std::shared_ptr<Timer>
create
(
const
std::function<
void
(std::shared_ptr<Timer>)>& callback,
79
Duration
interval,
80
bool
enable =
true
);
81
91
static
void
scheduleCallback
(
const
std::function<
void
()>& callback,
Duration
interval =
Duration
());
92
98
void
setInterval
(
Duration
interval);
99
104
[[nodiscard]]
Duration
getInterval
()
const
;
105
111
void
setEnabled
(
bool
enabled);
112
117
[[nodiscard]]
bool
isEnabled
()
const
;
118
124
void
setCallback
(
const
std::function<
void
()>& callback);
125
131
void
setCallback
(
const
std::function<
void
(std::shared_ptr<Timer>)>& callback);
132
136
void
restart
();
137
144
static
bool
updateTime(
Duration
elapsedTime);
145
151
[[nodiscard]]
static
Optional<Duration> getNextScheduledTime();
152
157
static
void
clearTimers();
158
160
161
protected
:
163
// Default constructor, used by static create and scheduleCallback functions
165
Timer() =
default
;
166
168
169
private
:
170
static
std::vector<std::shared_ptr<Timer>> m_activeTimers;
171
172
bool
m_repeats =
false
;
173
bool
m_enabled =
false
;
174
Duration
m_interval;
175
std::function<void()> m_callback;
176
177
Duration
m_remainingDuration;
178
};
179
}
// namespace tgui
180
181
#endif
// TGUI_TIMER_HPP
tgui::Duration
Wrapper for durations.
Definition
Duration.hpp:52
tgui::Timer::isEnabled
bool isEnabled() const
Returns whether the timer is running.
tgui::Timer::getInterval
Duration getInterval() const
Returns the interval at which a timer callback is send.
tgui::Timer::create
static std::shared_ptr< Timer > create(const std::function< void()> &callback, Duration interval, bool enable=true)
Creates a new timer.
tgui::Timer::setCallback
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.
tgui::Timer::restart
void restart()
Restarts the timer.
tgui::Timer::setInterval
void setInterval(Duration interval)
Changes the interval at which a timer callback is send.
tgui::Timer::setEnabled
void setEnabled(bool enabled)
Starts or stops a timer.
tgui::Timer::scheduleCallback
static void scheduleCallback(const std::function< void()> &callback, Duration interval=Duration())
Starts a timer.
tgui::Timer::setCallback
void setCallback(const std::function< void()> &callback)
Changes the callback function that should be called by the timer at each interval.
tgui::Timer::create
static std::shared_ptr< Timer > create(const std::function< void(std::shared_ptr< Timer >)> &callback, Duration interval, bool enable=true)
Creates a new timer.
tgui
Namespace that contains all TGUI functions and classes.
Definition
AbsoluteOrRelativeValue.hpp:37
Generated on
for TGUI by
1.18.0