Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: 256f1101c6b261ddb0c0f35ad529a827415baec0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
   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::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 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 );
}


}