Changeset 5106 in orxonox.OLD for trunk/src/util
- Timestamp:
- Aug 23, 2005, 8:09:58 PM (19 years ago)
- Location:
- trunk/src/util
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/util/shell.cc
r5105 r5106 25 25 #include "load_param.h" 26 26 #include "class_list.h" 27 28 #include "key_names.h" 27 29 #include "debug.h" 28 30 #include <stdarg.h> … … 40 42 this->setName("Shell"); 41 43 44 this->shellHeight = 400; 42 45 this->buffer = new tList<char>; 43 46 44 this->textSize = 10; 47 this->textSize = 15; 48 this->lineSpacing = 5; 45 49 46 50 //this->bufferSize = 0; 47 51 this->bufferText = NULL; 48 52 this->setBufferSize(100); 53 this->bufferDisplaySize = 10; 49 54 this->setBufferDisplaySize(10); 50 this->setAbsCoor2D(3, GraphicsEngine::getInstance()->getResolutionY());55 this->setAbsCoor2D(3, -400); 51 56 this->delayed = 0; 52 57 this->setRepeatDelay(.3, .05); 53 58 this->pressedKey = SDLK_FIRST; 54 59 55 this->inputLineText = TextEngine::getInstance()->createText("fonts/earth.ttf", 10, TEXT_DYNAMIC, 255, 0, 0); 56 this->inputLineText->setAlignment(TEXT_ALIGN_LEFT); 57 this->inputLineText->setText(NULL); 60 this->inputLineText = NULL; 58 61 this->inputLine = new char[1]; 59 62 this->inputLine[0] = '\0'; 60 this->inputLineText->setParent2D(this); 61 63 64 this->rebuildText(); 62 65 this->completionList = NULL; 63 66 67 // EVENT-Handler subscription of '`' to all States, and all other keyboard commands to ES_SEHLL 64 68 EventHandler* evh = EventHandler::getInstance(); 65 69 evh->subscribe(this, ES_ALL, SDLK_BACKQUOTE); … … 78 82 for (int i = 0; i < this->bufferDisplaySize; i++) 79 83 delete this->bufferText[i]; 80 delete this->bufferText;84 delete[] this->bufferText; 81 85 82 86 // delete the inputLine … … 100 104 } 101 105 106 107 void Shell::activate() 108 { 109 EventHandler::getInstance()->setState(ES_SHELL); 110 this->setRelCoorSoft2D(0, 0, 1, 5); 111 } 112 113 void Shell::deactivate() 114 { 115 EventHandler::getInstance()->setState(ES_GAME); 116 this->setRelCoorSoft2D(0, -400, 1, 5); 117 } 118 119 void Shell::setTextSize(unsigned int textSize, unsigned int lineSpacing) 120 { 121 this->textSize = textSize; 122 this->lineSpacing = lineSpacing; 123 124 this->rebuildText(); 125 } 126 127 void Shell::rebuildText() 128 { 129 if (this->inputLineText == NULL) 130 delete this->inputLineText; 131 this->inputLineText = TextEngine::getInstance()->createText("fonts/Aniron_Bold.ttf", this->textSize, TEXT_DYNAMIC, 255, 0, 0); 132 this->inputLineText->setAlignment(TEXT_ALIGN_LEFT); 133 this->inputLineText->setText(NULL); 134 this->inputLineText->setParent2D(this); 135 this->inputLineText->setRelCoor2D(5, (this->textSize + this->lineSpacing)*this->bufferDisplaySize); 136 137 this->setBufferDisplaySize(this->bufferDisplaySize); 138 } 139 140 141 102 142 /** 103 143 * sets The count of Lines to display in the buffer. … … 110 150 for (unsigned int i = 0; i < this->bufferDisplaySize; i++) 111 151 delete this->bufferText[i]; 112 delete this->bufferText;152 delete[] this->bufferText; 113 153 } 114 154 … … 116 156 for (unsigned int i = 0; i < bufferDisplaySize; i++) 117 157 { 118 this->bufferText[i] = TextEngine::getInstance()->createText("fonts/ earth.ttf", this->textSize, TEXT_DYNAMIC, 255, 0, 0);158 this->bufferText[i] = TextEngine::getInstance()->createText("fonts/Aniron_Bold.ttf", this->textSize, TEXT_DYNAMIC, 255, 0, 0); 119 159 this->bufferText[i]->setAlignment(TEXT_ALIGN_LEFT); 120 this->bufferText[i]->setRelCoor2D(5, 12+12*i);160 this->bufferText[i]->setRelCoor2D(5, (this->textSize + this->lineSpacing)*i); 121 161 this->bufferText[i]->setText(NULL); 122 162 this->bufferText[i]->setParent2D(this); 123 163 } 124 125 126 164 this->bufferDisplaySize = bufferDisplaySize; 165 166 this->shellHeight = (this->textSize + this->lineSpacing) * (bufferDisplaySize+1); 127 167 } 128 168 … … 157 197 * @param line the Line as in the first argument in printf 158 198 * @param args the arguments as a va_list 159 *160 * @todo optimize161 199 */ 162 200 bool Shell::addBufferLineStatic(const char* line, ...) … … 178 216 return true; 179 217 } 180 int curr = 0;181 218 182 219 /** … … 213 250 } 214 251 this->bufferText[0]->setText(newLine); 215 // this->bufferText->216 // this->inputLineText->setText(newLine);217 252 } 218 253 … … 250 285 } 251 286 252 253 287 /** 254 288 * deletes the InputLine … … 262 296 this->inputLine = new char[1]; 263 297 *this->inputLine = '\0'; 264 265 298 } 266 299 … … 320 353 bool Shell::executeCommand() 321 354 { 322 323 355 this->addBufferLineStatic("Execute Command: %s\n", this->inputLine); 324 356 delete this->inputLine; … … 341 373 } 342 374 343 344 #include "key_names.h"345 375 /** 346 376 * listens for some event … … 356 386 if (EventHandler::getInstance()->getState() == ES_GAME) 357 387 { 358 EventHandler::getInstance()->setState(ES_SHELL); 359 this->setRelCoorSoft2D(0, GraphicsEngine::getInstance()->getResolutionY()-150, 1, 5); 388 this->activate(); 360 389 } 361 390 362 391 else 363 392 { 364 EventHandler::getInstance()->setState(ES_GAME); 365 this->setRelCoorSoft2D(0, GraphicsEngine::getInstance()->getResolutionY()+10, 1, 5); 393 this->deactivate(); 366 394 } 367 395 } … … 432 460 433 461 // glTexCoord2f(this->texCoord.maxU, this->texCoord.minV); 434 glVertex2f( this->getAbsCoor2D().x + 800, this->getAbsCoor2D().y );462 glVertex2f(GraphicsEngine::getInstance()->getResolutionX() - this->getAbsCoor2D().x, this->getAbsCoor2D().y ); 435 463 436 464 // glTexCoord2f(this->texCoord.maxU, this->texCoord.maxV); 437 glVertex2f( this->getAbsCoor2D().x + 800, this->getAbsCoor2D().y + 150);465 glVertex2f(GraphicsEngine::getInstance()->getResolutionX() - this->getAbsCoor2D().x, this->getAbsCoor2D().y + this->shellHeight); 438 466 439 467 // glTexCoord2f(this->texCoord.minU, this->texCoord.maxV); 440 glVertex2f(this->getAbsCoor2D().x, this->getAbsCoor2D().y + 150);468 glVertex2f(this->getAbsCoor2D().x, this->getAbsCoor2D().y + this->shellHeight); 441 469 442 470 glEnd(); … … 655 683 } 656 684 657 658 659 685 /** 660 686 * displays some nice output from the Shell -
trunk/src/util/shell.h
r5105 r5106 36 36 37 37 38 void setBufferSize(unsigned int bufferSize) { this->bufferSize = bufferSize; }; 38 void activate(); 39 void deactivate(); 39 40 40 void setBufferDisplaySize(unsigned int bufferDisplaySize); 41 void setTextSize(unsigned int textSize, unsigned int lineSpacing = 1); 42 void rebuildText(); 41 43 42 44 // BUFFER // 45 void setBufferSize(unsigned int bufferSize) { this->bufferSize = bufferSize; }; 46 void setBufferDisplaySize(unsigned int bufferDisplaySize); 43 47 void flushBuffers(); 44 48 static bool addBufferLineStatic(const char* line, ...); … … 96 100 unsigned int textSize; //!< The size of the text. 97 101 unsigned int lineSpacing; //!< The Spacing between lines. 102 unsigned int shellHeight; //!< The hight of the Shell in Pixels 98 103 99 104 char bufferArray[10000]; //!< a BUFFER for fast writing
Note: See TracChangeset
for help on using the changeset viewer.