-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbriefing.cpp
141 lines (115 loc) · 3.38 KB
/
briefing.cpp
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include "mastrix.hpp"
void drawWrappedString(const char *string, int x, int y, int width, void *font=GLUT_BITMAP_9_BY_15);
class BriefingHandler :public EventHandler
{
public:
BriefingHandler(std::string text);
bool handleEvent(SDL_Event *ev);
void redraw(void);
bool timepass(void);
int getPriority(void) {return 1;}
bool isOpaque(void) {return true;}
protected:
std::string briefText;
};
BriefingHandler::BriefingHandler(std::string text)
{
briefText = text;
}
bool BriefingHandler::handleEvent(SDL_Event *ev)
{
switch(ev->type)
{
case SDL_KEYDOWN:
case SDL_MOUSEBUTTONDOWN:
if(fadeInProgress) return false;
remove();
return true;
default:
return false;
}
return false;
}
const float briefingMargin = 60;
const float briefingVMargin = 100;
const float innerMargin = 10;
void BriefingHandler::redraw(void)
{
glColor3f(0, 0.8, 0);
glLineWidth(1);
glBegin(GL_LINE_LOOP);
glVertex2f(briefingMargin, briefingVMargin);
glVertex2f(graphics.getScreenWidth()-briefingMargin, briefingVMargin);
glVertex2f(graphics.getScreenWidth()-briefingMargin, graphics.getScreenHeight()-briefingVMargin);
glVertex2f(briefingMargin, graphics.getScreenHeight()-briefingVMargin);
glEnd();
glColor4f(0, 0.8, 0, 0.3);
glBegin(GL_QUADS);
glVertex2f(briefingMargin, briefingVMargin);
glVertex2f(graphics.getScreenWidth()-briefingMargin, briefingVMargin);
glVertex2f(graphics.getScreenWidth()-briefingMargin, graphics.getScreenHeight()-briefingVMargin);
glVertex2f(briefingMargin, graphics.getScreenHeight()-briefingVMargin);
glEnd();
drawWrappedString(briefText.c_str(),
briefingMargin+innerMargin,
briefingVMargin+innerMargin+15,
graphics.getScreenWidth()-(briefingMargin+innerMargin)*2);
}
bool BriefingHandler::timepass(void)
{
return true;
}
CLIENT_CONSOLE_COMMAND(briefing)
{
std::string brieftext("");
if(argc < 1) {
console.printf("Usage: briefing [text]");
return;
}
for(int ii=0; ii<argc; ii++)
brieftext += argv[ii];
BriefingHandler *h = new BriefingHandler(brieftext);
h->enable();
}
void drawWrappedString(const char *string, int x, int y, int width, void *font)
{
int ii;
int curX=0;
int tempX;
int curRow=0;
// int font_height = FontHeight();
int font_height = 15;
tempX = curX;
ii=0;
while( string[ii] != '\0' )
{
tempX += graphics.drawCharWidth(string[ii], font);
// If past the end of the line
if(tempX >= width || string[ii] == '\n') {
if(string[ii] != '\n')
{
// Back up until (a) it fits and (b) it isn't in the middle of
// a word
while(ii >= 0 && string[ii] != ' ' && tempX>0)
tempX -= graphics.drawCharWidth(string[ii--], font);
if(tempX<=0) // Overshot; this line needs to be broken on a
{ // non-word-break
while(tempX<=width)
tempX += graphics.drawCharWidth(string[++ii], font);
tempX -= graphics.drawCharWidth(string[--ii], font);
}
}
// Print it out
graphics.drawTextN(string, ii, x, y+curRow*font_height, font);
string += ii;
string++;
ii=0;
curRow++;
curX = tempX = 0;
} else {
ii++;
}
}
// Print the remainder
graphics.drawText( string, x+curX, y+curRow*font_height, font);
}