-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmessages.h
77 lines (63 loc) · 1.44 KB
/
messages.h
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
69
70
71
72
73
74
75
76
77
#pragma once
#include "font.h"
#include "tbal.h"
#include "bevel.h"
struct Message
{
tblib::stringref text;
int time;
Message (tblib::stringref text, int time) : text(text), time(time) {}
};
tblib::array<Message, 4> messages;
void DeleteTopMessage ()
{
for (int i=0; i<messages.size()-1; ++i)
messages[i] = messages[i+1];
messages.shrink(messages.size()-1);
}
bool operator == (tblib::stringref l, tblib::stringref r)
{
if (l.high()-l.low() != r.high()-r.low())
return false;
for (int i=0; i<l.high()-l.low(); ++i)
if (l[l.low()+i] != r[r.low()+i])
return false;
return true;
}
bool operator != (tblib::stringref l, tblib::stringref r)
{
return ! (l==r);
}
void AddMessage (tblib::stringref text, bool canrepeat)
{
if (canrepeat || messages.size()==0 || messages.back().text != text)
{
if (messages.size() == messages.capacity)
DeleteTopMessage ();
messages.emplace_back(text, 7000);
}
}
void ProcessMessages ()
{
for (int i=0; i<messages.size(); ++i)
messages[i].time -= DT;
if (messages.size()>0 && messages[0].time<0)
DeleteTopMessage ();
}
struct HalfColor
{
void operator () (tbal::Color &dst)
{
dst = dst.Half();
}
};
void ShowMessages (const tbal::Bitmap& b)
{
if (messages.size()>0)
{
tbal::Bitmap w = b.Window(b.sizeX()/40, 2, b.sizeX()*38/40, messages.size()*(b.sizeY()/20)+4);
Bevel(w, false);
for (int i=0; i<messages.size(); ++i)
f.OutText(w, 2, i*(b.sizeY()/20)+2, messages[i].text, textColor1);
}
}