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_back(dl); |
---|
72 | |
---|
73 | this->repositionText(); |
---|
74 | } |
---|
75 | else |
---|
76 | { |
---|
77 | printf("grumble... must be fixed\n"); |
---|
78 | } |
---|
79 | } |
---|
80 | |
---|
81 | |
---|
82 | void GLGuiNotifier::setDisplayLineCount(unsigned int count) |
---|
83 | { |
---|
84 | unsigned int currentCount = displayLines.size() + hiddenText.size(); |
---|
85 | |
---|
86 | for (unsigned int i = currentCount; i < count; ++i) |
---|
87 | { |
---|
88 | MultiLineText* text = new MultiLineText(); |
---|
89 | this->applyTextSettings(text); |
---|
90 | this->hiddenText.push(text); |
---|
91 | } |
---|
92 | bufferDisplaySize = count; |
---|
93 | } |
---|
94 | |
---|
95 | |
---|
96 | /** |
---|
97 | * @brief repositiones all the Texts to their position. |
---|
98 | */ |
---|
99 | void GLGuiNotifier::repositionText() |
---|
100 | { |
---|
101 | int linePos = -1; |
---|
102 | std::list<DisplayLine>::iterator textIt; |
---|
103 | for (textIt = this->displayLines.begin() ; textIt != this->displayLines.end(); ++textIt ) |
---|
104 | { |
---|
105 | linePos += (*textIt).text->getLineCount(); |
---|
106 | (*textIt).text->setRelCoorSoft2D(this->calculateLinePosition(linePos), 8); |
---|
107 | // printf("%f %f\n", (*textIt).text->getAbsCoor2D().x, (*textIt).text->getAbsCoor2D().y); |
---|
108 | } |
---|
109 | } |
---|
110 | |
---|
111 | |
---|
112 | /** |
---|
113 | * @brief applies the GLGuiNotifiers Settings to a single Text of the GLGuiNotifier. |
---|
114 | * @param text the Text to apply the settings to. |
---|
115 | */ |
---|
116 | void GLGuiNotifier::applyTextSettings(MultiLineText* text) |
---|
117 | { |
---|
118 | text->setSize(this->style().textSize()); |
---|
119 | text->setLineWidth( 300 ); |
---|
120 | //text->setFont(this->fontFile, this->textSize); |
---|
121 | |
---|
122 | //text->setColor( Color(1,1,1,1)/*this->style().foregroundColor() */); |
---|
123 | if (text->getParent2D() != this) |
---|
124 | text->setParent2D(this); |
---|
125 | } |
---|
126 | |
---|
127 | |
---|
128 | void GLGuiNotifier::tick(float dt) |
---|
129 | { |
---|
130 | std::list<DisplayLine>::iterator line; |
---|
131 | for (line = this->displayLines.begin() ; line != this->displayLines.end(); ++line ) |
---|
132 | { |
---|
133 | (*line).age+=dt; |
---|
134 | if ((*line).age > 3.0f) |
---|
135 | { |
---|
136 | (*line).text->setBlending(4.0 - (*line).age); |
---|
137 | if ((*line).age > 4.0f) |
---|
138 | { |
---|
139 | std::list<DisplayLine>::iterator tmp = line; |
---|
140 | ++line; |
---|
141 | |
---|
142 | this->hiddenText.push((*tmp).text); |
---|
143 | this->displayLines.erase(tmp); |
---|
144 | } |
---|
145 | } |
---|
146 | } |
---|
147 | } |
---|
148 | |
---|
149 | |
---|
150 | /** |
---|
151 | * displays the GLGuiNotifier |
---|
152 | */ |
---|
153 | void GLGuiNotifier::draw() const |
---|
154 | { |
---|
155 | // transform for alignment. |
---|
156 | // setting the Blending effects |
---|
157 | this->beginDraw(); |
---|
158 | |
---|
159 | this->backMaterial().select(); |
---|
160 | this->drawRect(this->backRect()); |
---|
161 | this->endDraw(); |
---|
162 | } |
---|
163 | |
---|
164 | /////////////////////// |
---|
165 | // HELPER FUNCTIONS // |
---|
166 | /////////////////////// |
---|
167 | |
---|
168 | /** |
---|
169 | * @brief calculates the position of a Buffer-Display Line |
---|
170 | * @param lineNumber the lineNumber from the bottom to calculate the position from |
---|
171 | * @returns the Position of the Line. |
---|
172 | */ |
---|
173 | Vector2D GLGuiNotifier::calculateLinePosition(unsigned int lineNumber) |
---|
174 | { |
---|
175 | return Vector2D(0.0f, (float)(this->style().textSize() + this->lineSpacing)*(float)((int)this->bufferDisplaySize - (int)lineNumber - (int)1)); |
---|
176 | } |
---|
177 | |
---|
178 | |
---|
179 | void GLGuiNotifier::resize() |
---|
180 | {} |
---|
181 | |
---|
182 | /** |
---|
183 | * @brief displays some nice output from the GLGuiNotifier |
---|
184 | */ |
---|
185 | void GLGuiNotifier::debug() const |
---|
186 | { |
---|
187 | PRINT(3)("Debugging output to console (not this shell)\n"); |
---|
188 | |
---|
189 | // if (this->pressedKey != SDLK_FIRST) |
---|
190 | // printf("%s::%f %f\n", SDLKToKeyname(this->pressedKey), this->delayed, this->repeatDelay); |
---|
191 | } |
---|
192 | } |
---|