From 1d580ed36893b24b618ff1e6f9023e497c62498c Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 19 Oct 2008 16:03:56 +0000 Subject: on-screen notifications --- src/client/notifications.cc | 62 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/client/notifications.cc (limited to 'src/client/notifications.cc') 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 ); +} + + +} + -- cgit v1.2.3