-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththoughtbubble.cpp
235 lines (191 loc) · 6.96 KB
/
thoughtbubble.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#include "thoughtbubble.h"
#define TB_INDICATOR_TOTAL_WIDTH 64.0
#define TB_INDICATOR_TOTAL_HEIGHT 32.0
#define TB_INDICATOR_WIDTH 35.0
#define TB_INDICATOR_HEIGHT 22.0
#define TB_CORNER_WIDTH 6.0
#define TB_CORNER_HEIGHT 6.0
#define TB_CORNER_TOTAL_WIDTH 8.0
#define TB_CORNER_TOTAL_HEIGHT 8.0
#define TB_FONT_HEIGHT 12.0
#define TB_FONT_WIDTH 11.0
#define TB_FONT_PADDING 4.0
#define TB_WIDTH 200.0
#define TB_ROW_WIDTH TB_WIDTH - ( TB_FONT_PADDING * 2.0 )
void ThoughtBubble::init()
{
resourceMgr = ResourceMgr::getInstance();
resourceMgr->loadImage( FILE_THOUGHT_BUBBLE_INDICATOR, "tbIndicator" );
resourceMgr->loadImage( FILE_THOUGHT_BUBBLE_CORNER, "tbCorner" );
resourceMgr->loadImage( FILE_THOUGHT_BUBBLE_BORDER, "tbBorder" );
totalWidth = TB_WIDTH;
totalHeight = TB_FONT_HEIGHT;
}
void ThoughtBubble::draw( Point indicatorTip )
{
double indicatorUlX = indicatorTip.getX() - ( TB_INDICATOR_WIDTH / 2.0 );
double indicatorUlY = indicatorTip.getY() + TB_INDICATOR_HEIGHT;
double left = indicatorUlX - ( ( totalWidth - TB_INDICATOR_WIDTH ) / 2.0 );
double right = indicatorUlX + TB_INDICATOR_WIDTH +
( ( totalWidth - TB_INDICATOR_WIDTH ) / 2.0 );
double top = indicatorUlY + totalHeight;
double bottom = indicatorUlY;
//Draw background
glEnable ( GL_BLEND );
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4f( 0.1529, 0.1529, 0.1529, 0.72 );
glBegin( GL_QUADS );
glVertex2f( left , top );
glVertex2f( right , top );
glVertex2f( right , bottom - 1 );
glVertex2f( left , bottom - 1 );
glEnd();
glColor4f( 1.0, 1.0, 1.0, 1.0 );
glDisable( GL_BLEND );
glEnd();
//Draw indicator
resourceMgr->drawImage( "tbIndicator",
indicatorUlX,
indicatorUlX + TB_INDICATOR_TOTAL_WIDTH,
indicatorUlY - TB_INDICATOR_TOTAL_HEIGHT,
indicatorUlY );
//glColor3f(0,0,0);
//Draw bottom left border
drawBottomBorder( left, indicatorUlX, bottom , true);
//Draw bottom right border
drawBottomBorder( indicatorUlX + TB_INDICATOR_WIDTH, right, bottom , false);
//Draw top border
drawTopBorder( left, right, top );
//Draw left border
drawLeftBorder( left, top, bottom );
//Draw right border
drawRightBorder( right, top, bottom );
glColor3f(1,1,1);
drawText( Point( left, top ) );
}
void ThoughtBubble::drawBottomBorder( double leftX, double rightX, double bottomY , bool left )
{
glBegin( GL_LINES );
//Draw black lines
glColor3f(0.0,0.0,0.0);
glVertex2f( leftX , bottomY + 2 );
glVertex2f( rightX , bottomY + 2 );
glVertex2f( leftX , bottomY + 1 );
glVertex2f( rightX , bottomY + 1 );
//Draw white line
glColor3f(1.0,1.0,1.0);
glVertex2f( leftX , bottomY );
glVertex2f( rightX , bottomY );
glEnd();
/*
if(left)
{
resourceMgr->drawImage("tbCorner", leftX + 32, leftX, bottomY, bottomY + 32);
resourceMgr->drawImage("tbBorder", leftX + 31, rightX, bottomY, bottomY + 3);
}
else
{
resourceMgr->drawImage("tbCorner", rightX - 32, rightX, bottomY, bottomY + 32);
resourceMgr->drawImage("tbBorder", leftX, rightX - 31, bottomY, bottomY + 3);
}*/
}
void ThoughtBubble::drawTopBorder( double leftX, double rightX, double topY )
{
glBegin( GL_LINES );
//Draw black lines
glColor3f(0.0,0.0,0.0);
glVertex2f( leftX , topY - 2 );
glVertex2f( rightX , topY - 2 );
glVertex2f( leftX , topY - 1 );
glVertex2f( rightX , topY - 1 );
//Draw white line
glColor3f(1.0,1.0,1.0);
glVertex2f( leftX , topY );
glVertex2f( rightX , topY );
glEnd();
//resourceMgr->drawImage("tbBorder", leftX + 31, rightX - 31, topY - 3, topY);
}
void ThoughtBubble::drawLeftBorder( double leftX, double topY, double bottomY )
{
glBegin( GL_LINES );
//Draw black lines
glColor3f(0.0,0.0,0.0);
glVertex2f( leftX + 2 , topY - 1 );
glVertex2f( leftX + 2 , bottomY + 1 );
glVertex2f( leftX + 1 , topY - 2 );
glVertex2f( leftX + 1 , bottomY + 2 );
//Draw white line
glColor3f(1.0,1.0,1.0);
glVertex2f( leftX, topY );
glVertex2f( leftX, bottomY );
glEnd();
//resourceMgr->drawImage("tbCorner", leftX + 32, leftX, topY, topY - 32);
//resourceMgr->drawImage("tbBorder", leftX, leftX + 3, bottomY + 31, topY - 31);
}
void ThoughtBubble::drawRightBorder( double rightX, double topY, double bottomY )
{
glBegin( GL_LINES );
//Draw black lines
glColor3f(0.0,0.0,0.0);
glVertex2f( rightX - 2 , topY - 2 );
glVertex2f( rightX - 2 , bottomY + 2 );
glVertex2f( rightX - 1 , topY - 1);
glVertex2f( rightX - 1 , bottomY + 1 );
//Draw white line
glColor3f(1.0,1.0,1.0);
glVertex2f( rightX, topY );
glVertex2f( rightX, bottomY );
glEnd();
//resourceMgr->drawImage("tbCorner", rightX - 32, rightX, topY, topY - 32);
//resourceMgr->drawImage("tbBorder", rightX - 3, rightX, bottomY + 31, topY - 31);
}
void ThoughtBubble::setText( string text )
{
vector<string> words;
stringstream textBlock;
string row;
textBlock << text;
textRows.clear();
//Split the string into seperate words.
while( !textBlock.eof() )
{
string tempString;
textBlock >> tempString;
tempString += " ";
words.push_back( tempString );
}
////Combine the words into rows
for( unsigned int i = 0; i < words.size(); ++i )
{
double curRowWidth = ( row.size() + words[i].size() ) * TB_FONT_WIDTH;
//If adding this word makes the row too long
//skip adding the word to the row and add the
//string to the rows vector.
if( curRowWidth > TB_ROW_WIDTH )
{
textRows.push_back( row );
row.clear();
}
row += words[i];
//If we've gone though all the words but haven't
//exceeded a row width add the current row to the
//rows vector.
if( i == ( words.size() - 1 ) )
{
textRows.push_back( row );
}
}
//Account for row height
totalHeight = textRows.size() * TB_FONT_HEIGHT;
totalHeight += ( textRows.size() + 1 ) * TB_FONT_PADDING;
}
void ThoughtBubble::drawText( Point ul )
{
double curX = ul.getX() + TB_FONT_PADDING;
double curY = ul.getY() - TB_FONT_HEIGHT - TB_FONT_PADDING;
for( unsigned int i = 0; i < textRows.size(); ++i )
{
resourceMgr->drawText( "MONACO", textRows[i], curX, curY );
curY -= TB_FONT_HEIGHT + TB_FONT_PADDING;
}
}