Clapkit
Loading...
Searching...
No Matches
ckTimer.h
Go to the documentation of this file.
1/*
2 *
3 * Clapkit
4 * ----------------------------------------------------------------------
5 * A wrapper for creating a 'generalized' app for Classic MacOS
6 * that (hopefully) can be ported easily to other platforms.
7 *
8 * CKTimer
9 * ----------------------------------------------------------------------
10 * Defines a timer.
11 *
12 */
13
14#pragma once
15
16#include "ckObject.h"
17#include <MacTypes.h>
18
19using CKTimerCallbackFunc = std::function<void(void*)>;
20
21class CKApp;
22
27class CKTimer : public CKObject {
28
29 public:
30 CKTimer();
31 virtual ~CKTimer();
32 bool Update();
33 void Start();
34 void Stop();
35
36 public:
37 bool enabled = false; // Will actually fire?
38 bool multiRun = true; // Fires more than once?
39 UInt16 interval = 1000; // Interval in milliseconds
40 UInt32 nextRun; // When will it run next time?
41 CKTimerCallbackFunc callback; // Callback function
42 void* userData = nullptr; // Optional context pointer
43 CKObject* owner = nullptr; // Used to stop the timer when the owner is out of scope
44 CKApp* app = nullptr; // Used to stop the timer when the owner is out of scope
45};
std::function< void(void *)> CKTimerCallbackFunc
Definition ckTimer.h:19
Defines the main entry point for a Clapkit application.
Definition ckApp.h:57
Defines the base class for all controls and objects.
Definition ckObject.h:43
Defines a timer that can execute code on a pre-defined interval.
Definition ckTimer.h:27
void * userData
Definition ckTimer.h:42
CKObject * owner
Definition ckTimer.h:43
void Stop()
Definition ckTimer.cpp:57
CKTimerCallbackFunc callback
Definition ckTimer.h:41
bool multiRun
Definition ckTimer.h:38
UInt16 interval
Definition ckTimer.h:39
UInt32 nextRun
Definition ckTimer.h:40
bool Update()
Let the timer check if its appropriate to run.
Definition ckTimer.cpp:32
void Start()
Definition ckTimer.cpp:51
CKApp * app
Definition ckTimer.h:44
virtual ~CKTimer()
Definition ckTimer.cpp:20
bool enabled
Definition ckTimer.h:37
CKTimer()
Definition ckTimer.cpp:17