diff options
author | Stijn Buys <ingar@osirion.org> | 2008-10-19 16:03:56 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2008-10-19 16:03:56 +0000 |
commit | 1d580ed36893b24b618ff1e6f9023e497c62498c (patch) | |
tree | ac942e5fd15811c6ea2fa449f88f5c4cc4187d30 /src/client/notifications.cc | |
parent | 56cdfd3822d2800abdd2f912ab7f76a5764793a7 (diff) |
on-screen notifications
Diffstat (limited to 'src/client/notifications.cc')
-rw-r--r-- | src/client/notifications.cc | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/client/notifications.cc b/src/client/notifications.cc new file mode 100644 index 0000000..b7c11fd --- /dev/null +++ b/src/client/notifications.cc @@ -0,0 +1,62 @@ +/* + client/notifications.cc + This file is part of the Osirion project and is distributed under + the terms and conditions of the GNU General Public License version 2 +*/ + +#include "client/notifications.h" +#include "core/application.h" + +namespace client +{ + +const size_t NOTIFY_LOG_SIZE = 256; +const unsigned long NOTIFY_TIMEOUT = 7000; //timeout in microseconds + +Notifications::Notifications(ui::Widget *parent) : ui::Widget(parent) +{ + set_label("notifications"); + set_border(false); + + notify_scrollpane = new ui::ScrollPane(this, notify_log); + notify_scrollpane->set_border(false); +} + +Notifications::~Notifications() +{ +} + +void Notifications::event_text(const std::string & text) +{ + while (notify_log.size() >= NOTIFY_LOG_SIZE) { + notify_log.pop_front(); + notify_timestamp.pop_front(); + } + + notify_log.push_back(text); + notify_timestamp.push_back(core::application()->timestamp()); +} + +void Notifications::draw() +{ + Timestamps::iterator t = notify_timestamp.begin(); + while ( (t != notify_timestamp.end()) && ( core::application()->timestamp() > (*t) + NOTIFY_TIMEOUT )) { + + notify_log.pop_front(); + notify_timestamp.pop_front(); + + t = notify_timestamp.begin(); + } + + const float margin = 8.0f; + math::Vector2f s(size()); + s.x -= margin*2; + s.y -= margin*2; + + notify_scrollpane->set_location(margin, margin); + notify_scrollpane->set_size(s.x, s.y ); +} + + +} + |