1 | /* |
---|
2 | orxonox - the future of 3D-vertical-scrollers |
---|
3 | |
---|
4 | Copyright (C) 2004 orx |
---|
5 | |
---|
6 | This program is free software; you can redistribute it and/or modify |
---|
7 | it under the terms of the GNU General Public License as published by |
---|
8 | the Free Software Foundation; either version 2, or (at your option) |
---|
9 | any later version. |
---|
10 | |
---|
11 | ### File Specific: |
---|
12 | main-programmer: Benjamin Grauer |
---|
13 | co-programmer: ... |
---|
14 | */ |
---|
15 | |
---|
16 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_SHELL |
---|
17 | |
---|
18 | #include "glgui_notifier.h" |
---|
19 | #include "multi_line_text.h" |
---|
20 | |
---|
21 | #include "debug.h" |
---|
22 | |
---|
23 | namespace OrxGui |
---|
24 | { |
---|
25 | |
---|
26 | /** |
---|
27 | * standard constructor |
---|
28 | */ |
---|
29 | GLGuiNotifier::GLGuiNotifier () |
---|
30 | { |
---|
31 | this->setClassID(CL_GLGUI_NOTIFIER, "GLGuiNotifier"); |
---|
32 | |
---|
33 | // Element2D and generals |
---|
34 | this->lineSpacing = 0; |
---|
35 | this->linesProcessed = 0; |
---|
36 | |
---|
37 | this->setDisplayLineCount(10); |
---|
38 | } |
---|
39 | |
---|
40 | /** |
---|
41 | * @brief standard deconstructor |
---|
42 | */ |
---|
43 | GLGuiNotifier::~GLGuiNotifier () |
---|
44 | { |
---|
45 | // delete the displayable Buffers |
---|
46 | /* while (!this->displayLines.empty()) |
---|
47 | { |
---|
48 | delete this->displayLines.front().text; |
---|
49 | this->displayLines.pop_front(); |
---|
50 | } |
---|
51 | |
---|
52 | while (!this->hiddenText.empty()) |
---|
53 | { |
---|
54 | delete this->hiddenText.top(); |
---|
55 | this->hiddenText.pop(); |
---|
56 | }*/ |
---|
57 | } |
---|
58 | |
---|
59 | void GLGuiNotifier::pushNotifyMessage(const std::string& message) |
---|
60 | { |
---|
61 | if (!this->hiddenText.empty()) |
---|
62 | { |
---|
63 | printf("%s\n", message.c_str()); |
---|
64 | DisplayLine dl; |
---|
65 | dl.text = this->hiddenText.top(); |
---|
66 | |
---|
67 | dl.text->setBlending(1.0f); |
---|
68 | dl.text->setText(message); |
---|
69 | this->hiddenText.pop(); |
---|
70 | dl.age = 0.0f; |
---|
71 | this->displayLines.push_front(dl); |
---|
72 | |
---|
73 | dl.text->setVisibility(true); |
---|
74 | dl.text->setRelCoor2D(this->calculateLinePosition(0)); |
---|
75 | this->repositionText(); |
---|
76 | } |
---|
77 | else |
---|
78 | { |
---|
79 | this->inputBuffer.push_front(message); |
---|
80 | //printf("grumble... must be fixed\n"); |
---|
81 | } |
---|
82 | } |
---|
83 | |
---|
84 | |
---|
85 | void GLGuiNotifier::setDisplayLineCount(unsigned int count) |
---|
86 | { |
---|
87 | unsigned int currentCount = displayLines.size() + hiddenText.size(); |
---|
88 | |
---|
89 | for (unsigned int i = currentCount; i < count; ++i) |
---|
90 | { |
---|
91 | MultiLineText* text = new MultiLineText(); |
---|
92 | this->applyTextSettings(text); |
---|
93 | this->hiddenText.push(text); |
---|
94 | } |
---|
95 | bufferDisplaySize = count; |
---|
96 | } |
---|
97 | |
---|
98 | |
---|
99 | /** |
---|
100 | * @brief repositiones all the Texts to their position. |
---|
101 | */ |
---|
102 | void GLGuiNotifier::repositionText() |
---|
103 | { |
---|
104 | int linePos = -1; |
---|
105 | std::list<DisplayLine>::iterator textIt; |
---|
106 | for (textIt = this->displayLines.begin() ; textIt != this->displayLines.end(); ++textIt ) |
---|
107 | { |
---|
108 | linePos += (*textIt).text->getLineCount(); |
---|
109 | (*textIt).text->setRelCoorSoft2D(this->calculateLinePosition(linePos), 8); |
---|
110 | // printf("%f %f\n", (*textIt).text->getAbsCoor2D().x, (*textIt).text->getAbsCoor2D().y); |
---|
111 | } |
---|
112 | } |
---|
113 | |
---|
114 | |
---|
115 | /** |
---|
116 | * @brief applies the GLGuiNotifiers Settings to a single Text of the GLGuiNotifier. |
---|
117 | * @param text the Text to apply the settings to. |
---|
118 | */ |
---|
119 | void GLGuiNotifier::applyTextSettings(MultiLineText* text) |
---|
120 | { |
---|
121 | text->setSize(this->style().textSize()); |
---|
122 | text->setLineWidth( 300 ); |
---|
123 | text->setFont("fonts/final_frontier.ttf", (int)this->style().textSize()); |
---|
124 | |
---|
125 | text->setColor(this->style().foregroundColor() ); |
---|
126 | if (text->getParent2D() != this) |
---|
127 | text->setParent2D(this); |
---|
128 | } |
---|
129 | |
---|
130 | |
---|
131 | void GLGuiNotifier::tick(float dt) |
---|
132 | { |
---|
133 | std::list<DisplayLine>::iterator line; |
---|
134 | for (line = this->displayLines.begin() ; line != this->displayLines.end(); ++line ) |
---|
135 | { |
---|
136 | (*line).age+=dt; |
---|
137 | if ((*line).age > 3.0f) |
---|
138 | { |
---|
139 | (*line).text->setBlending(4.0 - (*line).age); |
---|
140 | if ((*line).age > 4.0f) |
---|
141 | { |
---|
142 | std::list<DisplayLine>::iterator tmp = line; |
---|
143 | ++line; |
---|
144 | |
---|
145 | (*tmp).text->setVisibility(false); |
---|
146 | this->hiddenText.push((*tmp).text); |
---|
147 | this->displayLines.erase(tmp); |
---|
148 | |
---|
149 | if (!inputBuffer.empty()) |
---|
150 | { |
---|
151 | this->pushNotifyMessage(inputBuffer.back()); |
---|
152 | inputBuffer.pop_back(); |
---|
153 | } |
---|
154 | } |
---|
155 | } |
---|
156 | } |
---|
157 | } |
---|
158 | |
---|
159 | |
---|
160 | /** |
---|
161 | * displays the GLGuiNotifier |
---|
162 | */ |
---|
163 | void GLGuiNotifier::draw() const |
---|
164 | { |
---|
165 | // transform for alignment. |
---|
166 | // setting the Blending effects |
---|
167 | this->beginDraw(); |
---|
168 | |
---|
169 | this->backMaterial().select(); |
---|
170 | this->drawRect(this->backRect()); |
---|
171 | this->endDraw(); |
---|
172 | } |
---|
173 | |
---|
174 | /////////////////////// |
---|
175 | // HELPER FUNCTIONS // |
---|
176 | /////////////////////// |
---|
177 | |
---|
178 | /** |
---|
179 | * @brief calculates the position of a Buffer-Display Line |
---|
180 | * @param lineNumber the lineNumber from the bottom to calculate the position from |
---|
181 | * @returns the Position of the Line. |
---|
182 | */ |
---|
183 | Vector2D GLGuiNotifier::calculateLinePosition(unsigned int lineNumber) |
---|
184 | { |
---|
185 | return Vector2D(0.0f, (float)(this->style().textSize() + this->lineSpacing)*(float)((int)this->bufferDisplaySize - (int)lineNumber - (int)1)); |
---|
186 | } |
---|
187 | |
---|
188 | |
---|
189 | void GLGuiNotifier::resize() |
---|
190 | {} |
---|
191 | |
---|
192 | /** |
---|
193 | * @brief displays some nice output from the GLGuiNotifier |
---|
194 | */ |
---|
195 | void GLGuiNotifier::debug() const |
---|
196 | { |
---|
197 | PRINT(3)("Debugging output to console (not this shell)\n"); |
---|
198 | |
---|
199 | // if (this->pressedKey != SDLK_FIRST) |
---|
200 | // printf("%s::%f %f\n", SDLKToKeyname(this->pressedKey), this->delayed, this->repeatDelay); |
---|
201 | } |
---|
202 | } |
---|