Update to latest ZWidget
This commit is contained in:
parent
640a2b2c41
commit
92b08a5c18
78 changed files with 7123 additions and 1261 deletions
73
libraries/ZWidget/src/window/ztimer/ztimer.cpp
Normal file
73
libraries/ZWidget/src/window/ztimer/ztimer.cpp
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
#include "ztimer.h"
|
||||
|
||||
ZTimer::ZTimer()
|
||||
{
|
||||
}
|
||||
|
||||
ZTimer::ZTimer(Duration duration_ms) : m_timerDuration(duration_ms)
|
||||
{
|
||||
}
|
||||
|
||||
ZTimer::ZTimer(Duration duration_ms, CallbackFunc callback)
|
||||
: m_timerDuration(duration_ms), m_callback(callback)
|
||||
{
|
||||
}
|
||||
|
||||
ZTimer::~ZTimer()
|
||||
{
|
||||
Stop();
|
||||
}
|
||||
|
||||
void ZTimer::Start()
|
||||
{
|
||||
m_startTime = Clock::now();
|
||||
m_currentTime = m_startTime;
|
||||
m_timerStarted = true;
|
||||
m_timerFinished = false;
|
||||
}
|
||||
|
||||
void ZTimer::Stop()
|
||||
{
|
||||
m_timerStarted = false;
|
||||
}
|
||||
|
||||
void ZTimer::SetDuration(Duration duration_ms)
|
||||
{
|
||||
if (m_timerStarted)
|
||||
return;
|
||||
m_timerDuration = duration_ms;
|
||||
}
|
||||
|
||||
void ZTimer::SetCallback(std::function<void()> callback)
|
||||
{
|
||||
if (m_timerStarted)
|
||||
return;
|
||||
m_callback = callback;
|
||||
}
|
||||
|
||||
void ZTimer::SetRepeating(bool value)
|
||||
{
|
||||
if (m_timerStarted)
|
||||
return;
|
||||
m_repeatingTimer = value;
|
||||
}
|
||||
|
||||
void ZTimer::Update(Duration deltaTime)
|
||||
{
|
||||
if (!m_timerStarted)
|
||||
return;
|
||||
|
||||
m_currentTime += deltaTime;
|
||||
|
||||
if (m_currentTime >= m_startTime + m_timerDuration)
|
||||
{
|
||||
m_callback();
|
||||
if (!m_repeatingTimer)
|
||||
{
|
||||
Stop();
|
||||
m_timerFinished = true;
|
||||
}
|
||||
else
|
||||
Start();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue