diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-03-30 21:40:27 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-03-30 21:40:57 +0100 |
commit | 25f28a54a131c4aa188ba2c4c453c1b1648d02c6 (patch) | |
tree | 20aa3bde47473ff6c451adf5add30c20225d7ec1 /LibGUI | |
parent | 245c4bd7c89733d940b0b12bf4e8ebf11bbb6e64 (diff) | |
download | serenity-25f28a54a131c4aa188ba2c4c453c1b1648d02c6.zip |
Terminal+LibGUI: Make the terminal cursor blink.
Added a GTimer class to help with this. It's just a simple GObject subclass
that sets up an event loop timer and invokes a callback on timeout.
Diffstat (limited to 'LibGUI')
-rw-r--r-- | LibGUI/GTimer.cpp | 39 | ||||
-rw-r--r-- | LibGUI/GTimer.h | 32 | ||||
-rw-r--r-- | LibGUI/Makefile | 1 |
3 files changed, 72 insertions, 0 deletions
diff --git a/LibGUI/GTimer.cpp b/LibGUI/GTimer.cpp new file mode 100644 index 0000000000..9edd58bd7a --- /dev/null +++ b/LibGUI/GTimer.cpp @@ -0,0 +1,39 @@ +#include <LibGUI/GTimer.h> + +GTimer::GTimer(GObject* parent) + : GObject(parent) +{ +} + +GTimer::~GTimer() +{ +} + +void GTimer::start() +{ + start(m_interval); +} + +void GTimer::start(int interval) +{ + if (m_active) + return; + start_timer(interval); + m_active = true; +} + +void GTimer::stop() +{ + if (!m_active) + return; + stop_timer(); + m_active = false; +} + +void GTimer::timer_event(GTimerEvent&) +{ + if (m_single_shot) + stop(); + if (on_timeout) + on_timeout(); +} diff --git a/LibGUI/GTimer.h b/LibGUI/GTimer.h new file mode 100644 index 0000000000..604c5042df --- /dev/null +++ b/LibGUI/GTimer.h @@ -0,0 +1,32 @@ +#pragma once + +#include <LibGUI/GObject.h> +#include <AK/Function.h> + +class GTimer final : public GObject { +public: + explicit GTimer(GObject* parent = nullptr); + virtual ~GTimer() override; + + void start(); + void start(int interval); + void stop(); + + bool is_active() const { return m_active; } + int interval() const { return m_interval; } + void set_interval(int interval) { m_interval = interval; } + + bool is_single_shot() const { return m_single_shot; } + void set_single_shot(bool single_shot) { m_single_shot = single_shot; } + + Function<void()> on_timeout; + + virtual const char* class_name() const override { return "GTimer"; } + +private: + virtual void timer_event(GTimerEvent&) override; + + bool m_active { false }; + bool m_single_shot { false }; + int m_interval { 0 }; +}; diff --git a/LibGUI/Makefile b/LibGUI/Makefile index 218b344b39..9660229968 100644 --- a/LibGUI/Makefile +++ b/LibGUI/Makefile @@ -57,6 +57,7 @@ LIBGUI_OBJS = \ GTreeView.o \ GFileSystemModel.o \ GSplitter.o \ + GTimer.o \ GWindow.o OBJS = $(SHAREDGRAPHICS_OBJS) $(LIBGUI_OBJS) |