瀏覽代碼

LibCore: Add Core::Timer::set_active(bool)

This calls either start() or stop() depending on the boolean argument.
Andreas Kling 3 年之前
父節點
當前提交
d0df249666
共有 2 個文件被更改,包括 10 次插入0 次删除
  1. 8 0
      Userland/Libraries/LibCore/Timer.cpp
  2. 2 0
      Userland/Libraries/LibCore/Timer.h

+ 8 - 0
Userland/Libraries/LibCore/Timer.cpp

@@ -58,6 +58,14 @@ void Timer::stop()
     m_active = false;
     m_active = false;
 }
 }
 
 
+void Timer::set_active(bool active)
+{
+    if (active)
+        start();
+    else
+        stop();
+}
+
 void Timer::timer_event(TimerEvent&)
 void Timer::timer_event(TimerEvent&)
 {
 {
     if (m_single_shot)
     if (m_single_shot)

+ 2 - 0
Userland/Libraries/LibCore/Timer.h

@@ -37,6 +37,8 @@ public:
     void restart(int interval_ms);
     void restart(int interval_ms);
     void stop();
     void stop();
 
 
+    void set_active(bool);
+
     bool is_active() const { return m_active; }
     bool is_active() const { return m_active; }
     int interval() const { return m_interval_ms; }
     int interval() const { return m_interval_ms; }
     void set_interval(int interval_ms)
     void set_interval(int interval_ms)