/* 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" #include "ui/ui.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); notify_scrollpane->set_alignment(ui::AlignTop); } Notifications::~Notifications() { } void Notifications::clear() { notify_log.clear(); notify_timestamp.clear(); } 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 padding = ui::UI::padding; math::Vector2f s(size()); s[0] -= padding * 2; s[1] -= padding * 2; notify_scrollpane->set_location(padding, padding); notify_scrollpane->set_size(s.x(), s.y()); } }