GTimer.h 819 B

1234567891011121314151617181920212223242526272829303132
  1. #pragma once
  2. #include <LibGUI/GObject.h>
  3. #include <AK/Function.h>
  4. class GTimer final : public GObject {
  5. public:
  6. explicit GTimer(GObject* parent = nullptr);
  7. virtual ~GTimer() override;
  8. void start();
  9. void start(int interval);
  10. void stop();
  11. bool is_active() const { return m_active; }
  12. int interval() const { return m_interval; }
  13. void set_interval(int interval) { m_interval = interval; }
  14. bool is_single_shot() const { return m_single_shot; }
  15. void set_single_shot(bool single_shot) { m_single_shot = single_shot; }
  16. Function<void()> on_timeout;
  17. virtual const char* class_name() const override { return "GTimer"; }
  18. private:
  19. virtual void timer_event(GTimerEvent&) override;
  20. bool m_active { false };
  21. bool m_single_shot { false };
  22. int m_interval { 0 };
  23. };