Changeset 8503 in orxonox.OLD for branches/gui
- Timestamp:
- Jun 15, 2006, 10:35:59 PM (18 years ago)
- Location:
- branches/gui/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/gui/src/defs/class_id.h
r8271 r8503 277 277 CL_OBB = 0x00720000, 278 278 CL_BOUNDING_SPHERE = 0x00740000, 279 279 280 280 281 281 … … 304 304 CL_HEIGHT_MAP = 0x0000090a, 305 305 CL_GRID = 0x0000090b, 306 CL_BSP_MODEL = 0x0000090c, //!FIXME 307 306 CL_BSP_MODEL = 0x0000090c, //!FIXME 307 308 308 CL_MATERIAL = 0x00000810, 309 309 CL_SHADER = 0x00000811, … … 361 361 CL_GLGUI_IMAGE = 0x00000b70, 362 362 363 CL_GLGUI_NOTIFIER = 0x00000b80, 364 363 365 // QT_GUI 364 366 CL_GUI_SAVEABLE = 0x00b10000, -
branches/gui/src/lib/gui/gl/specials/glgui_notifier.cc
r8499 r8503 16 16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_SHELL 17 17 18 18 #include "glgui_notifier.h" 19 19 #include "multi_line_text.h" 20 20 21 #include "graphics_engine.h"22 #include "material.h"23 #include "event_handler.h"24 21 #include "debug.h" 25 22 26 namespace Orx Shell23 namespace OrxGui 27 24 { 28 25 … … 30 27 * standard constructor 31 28 */ 32 Shell::Shell()29 GLGuiNotifier::GLGuiNotifier () 33 30 { 34 this->setClassID(CL_GLGUI_NOTIFIER, " Shell");31 this->setClassID(CL_GLGUI_NOTIFIER, "GLGuiNotifier"); 35 32 36 33 // Element2D and generals … … 43 40 * @brief standard deconstructor 44 41 */ 45 Shell::~Shell()42 GLGuiNotifier::~GLGuiNotifier () 46 43 { 47 44 // delete the displayable Buffers … … 53 50 } 54 51 55 /**56 * @brief activates the shell57 *58 * This also feeds the Last few lines from the main buffers into the displayBuffer59 */60 void Shell::activate()61 {62 if (this->bActive == true)63 PRINTF(3)("The shell is already active\n");64 this->bActive = true;65 this->activate2D();66 52 67 EventHandler::getInstance()->pushState(ES_SHELL);68 69 this->setRelCoorSoft2D(0, 0, 5);70 71 this->linesProcessed = this->shellBuffer->getLineCount();72 std::list<std::string>::const_iterator textLine = this->bufferIterator = this->shellBuffer->getBuffer().begin();73 for (std::list<MultiLineText*>::iterator text = this->bufferText.begin(); text != this->bufferText.end(); ++text)74 {75 (*text)->setVisibility(true);76 if (textLine != this->shellBuffer->getBuffer().end())77 {78 (*text)->setText((*textLine));79 textLine++;80 }81 else82 (*text)->setText("");83 }84 this->shellInput.setVisibility(true);85 this->updateResolution( GraphicsEngine::getInstance()->getResolutionX());86 this->repositionText();87 }88 89 /**90 * @brief deactiveates the Shell.91 */92 void Shell::deactivate()93 {94 if (this->bActive == false)95 PRINTF(3)("The shell is already inactive\n");96 this->bActive = false;97 this->deactivate2D();98 99 EventHandler::getInstance()->popState();100 101 this->setRelCoorSoft2D(0, -(int)this->shellHeight, 5);102 103 for (std::list<MultiLineText*>::iterator text = this->bufferText.begin(); text != this->bufferText.end(); ++text)104 (*text)->setVisibility(false);105 this->shellInput.setVisibility(false);106 107 // Go to the End again.108 this->bufferIterator = this->shellBuffer->getBuffer().begin();109 }110 111 /**112 * @brief sets the File to load the fonts from113 * @param fontFile the file to load the font from114 *115 * it is quite important, that the font pointed too really exists!116 * (be aware that within orxonox fontFile is relative to the Data-Dir)117 */118 void Shell::setFont(const std::string& fontFile)119 {120 this->fontFile = fontFile;121 122 this->applySettings();123 }124 125 /**126 * @brief sets the size of the text and spacing127 * @param textSize the size of the Text in Pixels128 * @param lineSpacing the size of the Spacing between two lines in pixels129 *130 * this also rebuilds the entire Text, inputLine and displayBuffer,131 * to be accurate again.132 */133 void Shell::setTextSize(unsigned int textSize, unsigned int lineSpacing)134 {135 this->textSize = textSize;136 this->lineSpacing = lineSpacing;137 138 this->applySettings();139 }140 141 /**142 * @brief sets the color of the Font.143 * @param r: red144 * @param g: green145 * @param b: blue146 * @param a: alpha-value.147 */148 void Shell::setTextColor(float r, float g, float b, float a)149 {150 this->textColor[0] = r;151 this->textColor[1] = g;152 this->textColor[2] = b;153 this->textColor[3] = a;154 155 this->applySettings();156 }157 158 /**159 * @brief sets the color of the Backgrond.160 * @param r: red161 * @param g: green162 * @param b: blue163 * @param a: alpha-value.164 */165 void Shell::setBackgroundColor(float r, float g, float b, float a)166 {167 this->backgroundMaterial.setDiffuse(r, g, b);168 this->backgroundMaterial.setTransparency(a);169 }170 171 /**172 * @brief sets a nice background image to the Shell's background173 * @param fileName the filename of the Image to load174 */175 void Shell::setBackgroundImage(const std::string& fileName)176 {177 this->backgroundMaterial.setDiffuseMap(fileName);178 }179 180 181 /**182 * @brief updates the Shell's Width183 * @param width the new Width.184 */185 void Shell::updateResolution(unsigned int width)186 {187 if (width == this->getSizeX2D())188 return;189 this->setSizeX2D(width);190 for (std::list<MultiLineText*>::iterator textIt = this->bufferText.begin(); textIt != this->bufferText.end(); ++textIt)191 {192 (*textIt)->setLineWidth(width);193 }194 }195 53 196 54 /** 197 55 * @brief repositiones all the Texts to their position. 198 56 */ 199 void Shell::repositionText()57 void GLGuiNotifier::repositionText() 200 58 { 201 59 int linePos = -1; … … 210 68 211 69 /** 212 * @brief applies the Shells Settings to a single Text of the Shell.70 * @brief applies the GLGuiNotifiers Settings to a single Text of the GLGuiNotifier. 213 71 * @param text the Text to apply the settings to. 214 72 */ 215 void Shell::applyTextSettings(Text* text)73 void GLGuiNotifier::applyTextSettings(Text* text) 216 74 { 217 text->setSize(this->textSize);75 /* text->setSize(this->textSize); 218 76 text->setFont(this->fontFile, this->textSize); 219 77 text->setColor(this->textColor[0], this->textColor[1], this->textColor[2]); … … 221 79 text->setLayer(this->getLayer()); 222 80 if (text->getParent2D() != this) 223 text->setParent2D(this); 81 text->setParent2D(this);*/ 224 82 } 225 83 226 /** 227 * @brief resets the Values of all visible shell's commandos to the Shell's stored values 228 * 229 * this functions synchronizes the stored Data with the visible one. 230 */ 231 void Shell::applySettings() 84 85 void GLGuiNotifier::tick(float dt) 232 86 { 233 this->applyTextSettings(&this->shellInput);234 this->shellInput.setRelCoor2D(15, (this->textSize + this->lineSpacing)*(this->bufferDisplaySize));235 236 /* Here we create a Copy of the Buffer, so that we do not f**k up the List when some237 * output is routed from Some other Thread or by Changing any Values.238 */239 std::list<MultiLineText*> bufferTextCopy = this->bufferText;240 for (std::list<MultiLineText*>::iterator textIt = bufferTextCopy.begin(); textIt != bufferTextCopy.end(); ++textIt)241 {242 this->applyTextSettings(*textIt);243 (*textIt)->setLineSpacing(this->lineSpacing);244 (*textIt)->setLineWidth(this->getSizeX2D() * GraphicsEngine::getInstance()->getResolutionX());245 }246 this->repositionText();247 248 this->shellHeight = (this->textSize + this->lineSpacing) * (bufferDisplaySize+1);249 }250 251 /**252 * @brief sets The count of Lines to display in the buffer.253 * @param bufferDisplaySize the count of lines to display in the Shell-Buffer.254 */255 void Shell::setBufferDisplaySize(unsigned int bufferDisplaySize)256 {257 unsigned int oldSize = this->bufferText.size();258 if (oldSize > bufferDisplaySize)259 {260 for (unsigned int i = bufferDisplaySize; i <= oldSize; i++)261 {262 delete this->bufferText.back();263 this->bufferText.pop_back();264 }265 }266 else if (oldSize < bufferDisplaySize)267 {268 for (unsigned int i = oldSize; i <= bufferDisplaySize; i++)269 {270 this->bufferText.push_back(new MultiLineText);271 }272 }273 this->bufferDisplaySize = bufferDisplaySize;274 this->applySettings();275 }276 277 /**278 * @brief deletes all the Buffers279 */280 void Shell::flush()281 {282 for (std::list<MultiLineText*>::iterator textIt = this->bufferText.begin(); textIt != this->bufferText.end(); ++textIt)283 {284 (*textIt)->setText(""); // remove all chars from the BufferTexts.285 }286 this->shellBuffer->flush();287 // BUFFER FLUSHING288 }289 290 /**291 * @brief prints out some text to the input-buffers292 * @param text the text to output.293 */294 void Shell::printToDisplayBuffer(const std::string& text)295 {296 // Remove Last Entry and prepend it to the front.297 this->bufferText.push_front(this->bufferText.back());298 this->bufferText.pop_back();299 300 // Set the new Text.301 this->bufferText.front()->setText(text);302 this->bufferIterator = this->shellBuffer->getBuffer().begin();303 304 // The LineCount will be started here.305 306 // The First Line gets a special Animation307 this->bufferText.front()->setRelCoor2D(this->calculateLinePosition(0)- Vector2D(-1000,0));308 309 // Move all lines one Entry up.310 this->repositionText();311 87 } 312 88 313 89 314 90 /** 315 * @brief moves the Display buffer (up + or down - ) 316 * @param lineCount the count by which to shift the InputBuffer. 317 * 318 * @todo make this work 91 * displays the GLGuiNotifier 319 92 */ 320 void Shell::moveDisplayBuffer(int lineCount) 321 { 322 // moving the iterator to the right position (counting the steps) 323 int moves = 0; 324 while (moves != lineCount) 325 { 326 if (moves < lineCount) 327 { 328 if(this->bufferIterator == --this->shellBuffer->getBuffer().end()) 329 break; 330 ++moves; 331 ++this->bufferIterator; 332 } 333 else 334 { 335 if (this->bufferIterator == this->shellBuffer->getBuffer().begin()) 336 break; 337 --moves; 338 --this->bufferIterator; 339 } 340 } 341 342 343 // redisplay the buffers 344 std::list<MultiLineText*>::iterator textIt; 345 346 // Give a Graphical Representation that no move is possible. 347 if (moves == 0) 348 { 349 int linePos = -1; 350 for (textIt = this->bufferText.begin(); textIt != this->bufferText.end(); ++textIt) 351 { 352 linePos += (*textIt)->getLineCount(); 353 (*textIt)->setRelCoor2D(this->calculateLinePosition(linePos)+ Vector2D(20,0)); 354 (*textIt)->setRelCoorSoft2D(this->calculateLinePosition(linePos), 10); 355 } 356 return; 357 } 358 359 // Move all the Lines. 360 int linePos = moves; 361 std::list<std::string>::const_iterator it = this->bufferIterator; 362 for (textIt = this->bufferText.begin(); textIt != this->bufferText.end(); ++textIt, ++it) 363 { 364 if (it == this->shellBuffer->getBuffer().end()) 365 { 366 PRINTF(1)("LAST LINE REACHED\n"); 367 break; 368 } 369 370 371 (*textIt)->setRelCoor2D(calculateLinePosition( (linePos++ > 0) ? linePos : 0)); 372 (*textIt)->setText((*it)); 373 } 374 while (textIt != this->bufferText.end()) 375 { 376 (*textIt)->setText(""); 377 textIt++; 378 } 379 380 this->repositionText(); 381 } 382 383 /** 384 * @brief clears the Shell (empties all buffers) 385 */ 386 void Shell::clear() 387 { 388 this->flush(); 389 ShellBuffer::addBufferLineStatic("orxonox - shell\n ==================== \n", NULL); 390 } 391 392 /** 393 * @brief listens for some event 394 * @param event the Event happened 395 */ 396 void Shell::process(const Event &event) 397 { 398 if (event.bPressed) 399 { 400 if (event.type == SDLK_BACKQUOTE || event.type == SDLK_F12) 401 { 402 if (this->bActive == false) 403 this->activate(); 404 else 405 this->deactivate(); 406 } 407 else if (event.type == SDLK_PAGEUP) 408 { 409 this->moveDisplayBuffer(+this->bufferDisplaySize-1); 410 } 411 else if (event.type == SDLK_PAGEDOWN) 412 { 413 this->moveDisplayBuffer(-this->bufferDisplaySize+1); 414 } 415 else if (event.type == EV_VIDEO_RESIZE) 416 { 417 this->updateResolution(event.resize.w); 418 this->repositionText(); 419 } 420 } 421 } 422 423 void Shell::tick(float dt) 424 { 425 if (this->linesProcessed < this->shellBuffer->getLineCount()) 426 { 427 unsigned int pollLines = this->shellBuffer->getLineCount() - this->linesProcessed; 428 if (this->bufferText.size() < pollLines) 429 pollLines = this->bufferText.size(); 430 if (unlikely(this->shellBuffer->getBuffer().size() < pollLines)) 431 pollLines = this->shellBuffer->getBuffer().size(); 432 433 std::list<std::string>::const_iterator line = this->shellBuffer->getBuffer().begin(); 434 unsigned int i; 435 for(i = 0; i < pollLines; i++) 436 line ++; 437 for (i = 0; i < pollLines; i++) 438 { 439 this->printToDisplayBuffer((*--line)); 440 } 441 } 442 this->linesProcessed = this->shellBuffer->getLineCount(); 443 } 444 445 446 /** 447 * displays the Shell 448 */ 449 void Shell::draw() const 93 void GLGuiNotifier::draw() const 450 94 { 451 95 // transform for alignment. 452 96 // setting the Blending effects 97 this->beginDraw(); 453 98 454 this->backgroundMaterial.select(); 455 456 glBegin(GL_TRIANGLE_STRIP); 457 458 glTexCoord2f(0, 0); 459 glVertex2f(this->getAbsCoor2D().x, this->getAbsCoor2D().y ); 460 461 glTexCoord2f(1, 0); 462 glVertex2f(GraphicsEngine::getInstance()->getResolutionX() - this->getAbsCoor2D().x, this->getAbsCoor2D().y ); 463 464 glTexCoord2f(0, 1); 465 glVertex2f(this->getAbsCoor2D().x, this->getAbsCoor2D().y + this->shellHeight); 466 467 glTexCoord2f(1, 1); 468 glVertex2f(GraphicsEngine::getInstance()->getResolutionX() - this->getAbsCoor2D().x, this->getAbsCoor2D().y + this->shellHeight); 469 470 glEnd(); 99 this->backMaterial().select(); 100 this->drawRect(this->backRect()); 101 this->endDraw(); 471 102 } 472 103 … … 480 111 * @returns the Position of the Line. 481 112 */ 482 Vector2D Shell::calculateLinePosition(unsigned int lineNumber)113 Vector2D GLGuiNotifier::calculateLinePosition(unsigned int lineNumber) 483 114 { 484 return Vector2D(5.0f, (float)(this->textSize + this->lineSpacing)*(float)((int)this->bufferDisplaySize - (int)lineNumber - (int)1)); 115 // return Vector2D(5.0f, (float)(this->textSize + this->lineSpacing)*(float)((int)this->bufferDisplaySize - (int)lineNumber - (int)1)); 116 return Vector2D(); 485 117 } 486 118 … … 488 120 489 121 /** 490 * @brief displays some nice output from the Shell122 * @brief displays some nice output from the GLGuiNotifier 491 123 */ 492 void Shell::debug() const124 void GLGuiNotifier::debug() const 493 125 { 494 126 PRINT(3)("Debugging output to console (not this shell)\n"); … … 496 128 // if (this->pressedKey != SDLK_FIRST) 497 129 // printf("%s::%f %f\n", SDLKToKeyname(this->pressedKey), this->delayed, this->repeatDelay); 498 499 500 this->shellBuffer->debug();501 130 } 502 503 /**504 * @brief a Handy Function, to Test the behaviour of the Shell.505 */506 void Shell::testShell() const507 {508 for (unsigned int i = 0; i < 100; i++)509 PRINT(0)("%d\n", i);510 }511 SHELL_COMMAND(test, Shell, testShell);512 513 131 } -
branches/gui/src/lib/gui/gl/specials/glgui_notifier.h
r8499 r8503 7 7 */ 8 8 9 #ifndef _ SHELL_H10 #define _ SHELL_H9 #ifndef _GLGUI_NOTIFIER_H 10 #define _GLGUI_NOTIFIER_H 11 11 12 12 #include "glgui_widget.h" … … 15 15 // FORWARD DECLARATION 16 16 class MultiLineText; 17 class Text; 17 18 18 //! Namespace of the Shellof ORXONOX.19 //! Namespace of the GLGuiNotifier of ORXONOX. 19 20 namespace OrxGui 20 21 { 21 class Shell: public GLGuiWidget22 class GLGuiNotifier : public GLGuiWidget 22 23 { 23 24 24 25 public: 25 Shell();26 virtual ~ Shell();26 GLGuiNotifier(); 27 virtual ~GLGuiNotifier(); 27 28 28 29 void pushNotifyMessage(const std::string& message); … … 63 64 } 64 65 65 #endif /* _ SHELL_H */66 #endif /* _GLGUI_NOTIFIER_H */
Note: See TracChangeset
for help on using the changeset viewer.