Changeset 7341 in orxonox.OLD for trunk/src/lib
- Timestamp:
- Apr 19, 2006, 3:58:03 AM (19 years ago)
- Location:
- trunk/src/lib
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/render2D/element_2d.cc
r7332 r7341 202 202 void Element2D::setLayer(E2D_LAYER layer) 203 203 { 204 if (unlikely(this->layer == layer)) return; 205 204 206 if (this->parent != NULL && this->parent->getLayer() > layer) 205 207 { -
trunk/src/lib/shell/shell.cc
r7340 r7341 36 36 37 37 SHELL_COMMAND(clear, Shell, clear) 38 39 38 ->describe("Clears the shell from unwanted lines (empties all buffers)") 39 ->setAlias("clear"); 40 40 SHELL_COMMAND(deactivate, Shell, deactivate) 41 42 41 ->describe("Deactivates the Shell. (moves it into background)") 42 ->setAlias("hide"); 43 43 SHELL_COMMAND(textsize, Shell, setTextSize) 44 45 44 ->describe("Sets the size of the Text size, linespacing") 45 ->defaultValues(15, 0); 46 46 SHELL_COMMAND(textcolor, Shell, setTextColor) 47 48 47 ->describe("Sets the Color of the Shells Text (red, green, blue, alpha)") 48 ->defaultValues(SHELL_DEFAULT_TEXT_COLOR); 49 49 SHELL_COMMAND(backgroundcolor, Shell, setBackgroundColor) 50 51 50 ->describe("Sets the Color of the Shells Background (red, green, blue, alpha)") 51 ->defaultValues(SHELL_DEFAULT_BACKGROUND_COLOR); 52 52 SHELL_COMMAND(backgroundimage, Shell, setBackgroundImage) 53 53 ->describe("sets the background image to load for the Shell"); 54 54 SHELL_COMMAND(font, Shell, setFont) 55 56 55 ->describe("Sets the font of the Shell") 56 ->defaultValues(SHELL_DEFAULT_FONT); 57 57 58 58 /** … … 71 71 72 72 // BUFFER 73 this->bufferText = NULL;74 this->bufferDisplaySize = 10;75 73 this->bufferOffset = 0; 76 74 this->bufferIterator = ShellBuffer::getInstance()->getBuffer().begin(); 77 75 78 76 // INPUT LINE 79 this->s hellInput = new ShellInput;80 this->shellInput ->setLayer(E2D_LAYER_ABOVE_ALL);77 this->setLayer(E2D_LAYER_ABOVE_ALL); 78 this->shellInput.setLayer(E2D_LAYER_ABOVE_ALL); 81 79 82 80 this->backgroundMaterial = new Material; 81 83 82 // Element2D and generals 84 83 this->setAbsCoor2D(3, -400); 85 this->setLayer(E2D_LAYER_ABOVE_ALL);86 84 this->textSize = 20; 87 85 this->lineSpacing = 0; … … 89 87 this->fontFile = SHELL_DEFAULT_FONT; 90 88 91 92 this->rebuildText(); 89 this->setBufferDisplaySize(10); 93 90 94 91 this->setTextColor(SHELL_DEFAULT_TEXT_COLOR); 95 92 this->setBackgroundColor(SHELL_DEFAULT_BACKGROUND_COLOR); 93 96 94 97 95 this->deactivate(); … … 101 99 102 100 /** 103 * standard deconstructor101 * @brief standard deconstructor 104 102 */ 105 103 Shell::~Shell () … … 108 106 109 107 // delete the displayable Buffers 110 for (unsigned int i = 0; i < this->bufferDisplaySize; i++) 111 delete this->bufferText[i]; 112 delete[] this->bufferText; 108 while (!this->bufferText.empty()) 109 { 110 delete this->bufferText.front(); 111 this->bufferText.pop_front(); 112 } 113 113 114 // delete the inputLine 114 delete this->shellInput;115 115 delete this->backgroundMaterial; 116 116 } 117 117 118 118 /** 119 * activates the shell119 * @brief activates the shell 120 120 * 121 121 * This also feeds the Last few lines from the main buffers into the displayBuffer … … 134 134 list<std::string>::const_iterator textLine = --ShellBuffer::getInstance()->getBuffer().end(); 135 135 bool top = false; 136 for ( int i = 0; i < this->bufferDisplaySize; i++)137 { 138 this->bufferText[i]->setVisibility(true);136 for (std::list<Text*>::iterator text = this->bufferText.begin(); text != this->bufferText.end(); ++text) 137 { 138 (*text)->setVisibility(true); 139 139 if (!top) 140 140 { 141 this->bufferText[i]->setText((*textLine));142 if (textLine != ShellBuffer::getInstance()->getBuffer().begin())143 top = true;141 (*text)->setText((*textLine)); 142 if (textLine != ShellBuffer::getInstance()->getBuffer().begin()) 143 top = true; 144 144 textLine--; 145 145 } … … 161 161 this->setRelCoorSoft2D(0, -(int)this->shellHeight, 5); 162 162 163 list<std::string>::const_iterator textLine = --ShellBuffer::getInstance()->getBuffer().end(); 164 for (int i = 0; i < this->bufferDisplaySize; i++) 165 { 166 this->bufferText[i]->setVisibility(false); 167 if (textLine != ShellBuffer::getInstance()->getBuffer().begin()) 168 { 169 this->bufferText[i]->setText((*textLine)); 170 textLine--; 171 } 172 } 163 for (std::list<Text*>::iterator text = this->bufferText.begin(); text != this->bufferText.end(); ++text) 164 (*text)->setVisibility(false); 173 165 this->bufferOffset = 0; 174 166 } … … 183 175 void Shell::setFont(const std::string& fontFile) 184 176 { 185 // if (!ResourceManager::isInDataDir(fontFile))186 // return false;177 // if (!ResourceManager::isInDataDir(fontFile)) 178 // return false; 187 179 188 180 this->fontFile = fontFile; 189 181 190 this->re buildText();182 this->resetValues(); 191 183 } 192 184 … … 203 195 this->textSize = textSize; 204 196 this->lineSpacing = lineSpacing; 197 205 198 this->resetValues(); 206 199 } 207 200 208 201 /** 209 * sets the color of the Font.202 * @brief sets the color of the Font. 210 203 * @param r: red 211 204 * @param g: green … … 225 218 226 219 /** 227 * sets the color of the Backgrond.220 * @brief sets the color of the Backgrond. 228 221 * @param r: red 229 222 * @param g: green … … 238 231 239 232 /** 240 * sets a nice background image to the Shell's background233 * @brief sets a nice background image to the Shell's background 241 234 * @param fileName the filename of the Image to load 242 235 */ … … 248 241 249 242 /** 250 * resets the Values of all visible shell's commandos to the Shell's stored values243 * @brief resets the Values of all visible shell's commandos to the Shell's stored values 251 244 * 252 245 * this functions synchronizes the stored Data with the visible one. … … 254 247 void Shell::resetValues() 255 248 { 256 if (this->shellInput != NULL) 257 { 258 this->shellInput->setSize(this->textSize); 259 this->shellInput->setColor(this->textColor[0], this->textColor[1], this->textColor[2]); 260 this->shellInput->setBlending(this->textColor[3]); 261 this->shellInput->setRelCoor2D(5, (this->textSize + this->lineSpacing)*(this->bufferDisplaySize)); 262 } 263 264 if (this->bufferText != NULL) 265 { 266 for (unsigned int i = 0; i < this->bufferDisplaySize; i++) 267 { 268 if (this->bufferText[i] != NULL) 269 { 270 this->bufferText[i]->setSize(this->textSize); 271 this->bufferText[i]->setColor(this->textColor[0], this->textColor[1], this->textColor[2]); 272 this->bufferText[i]->setBlending(this->textColor[3]); 273 this->bufferText[i]->setRelCoor2D(calculateLinePosition(i)); 274 } 275 } 249 this->shellInput.setFont(this->fontFile, this->textSize); 250 this->shellInput.setColor(this->textColor[0], this->textColor[1], this->textColor[2]); 251 this->shellInput.setBlending(this->textColor[3]); 252 this->shellInput.setRelCoor2D(5, (this->textSize + this->lineSpacing)*(this->bufferDisplaySize)); 253 this->shellInput.setLayer(this->getLayer()); 254 if (shellInput.getParent2D() != this) 255 this->shellInput.setParent2D(this); 256 257 unsigned int i = 0; 258 for (std::list<Text*>::iterator text = this->bufferText.begin(); text != this->bufferText.end(); ++text, ++i) 259 { 260 (*text)->setFont(this->fontFile, this->textSize); 261 (*text)->setColor(this->textColor[0], this->textColor[1], this->textColor[2]); 262 (*text)->setBlending(this->textColor[3]); 263 (*text)->setRelCoor2D( calculateLinePosition(i) ); 264 (*text)->setLayer(this->getLayer()); 265 if ((*text)->getParent2D() != this) 266 (*text)->setParent2D(this); 276 267 } 277 268 this->shellHeight = (this->textSize + this->lineSpacing) * (bufferDisplaySize+1); 278 269 } 279 270 280 /** 281 * rebuilds the Text's 282 * 283 * use this function, if you changed the Font/Size or something else. 284 */ 285 void Shell::rebuildText() 286 { 287 this->shellInput->setFont(this->fontFile, this->textSize); 288 this->shellInput->setAlignment(TEXT_ALIGN_LEFT); 289 if (shellInput->getParent2D() != this) 290 this->shellInput->setParent2D(this); 291 292 this->setBufferDisplaySize(this->bufferDisplaySize); 293 } 294 295 /** 296 * sets The count of Lines to display in the buffer. 271 272 /** 273 * @brief sets The count of Lines to display in the buffer. 297 274 * @param bufferDisplaySize the count of lines to display in the Shell-Buffer. 298 275 */ 299 276 void Shell::setBufferDisplaySize(unsigned int bufferDisplaySize) 300 277 { 301 Text** bufferText = this->bufferText; 302 this->bufferText = NULL; 303 if (bufferText != NULL) 304 { 305 for (unsigned int i = 0; i < this->bufferDisplaySize; i++) 306 delete bufferText[i]; 307 delete[] bufferText; 308 } 309 310 list<std::string>::const_iterator textLine = --ShellBuffer::getInstance()->getBuffer().end(); 311 bufferText = new Text*[bufferDisplaySize]; 312 for (unsigned int i = 0; i < bufferDisplaySize; i++) 313 { 314 bufferText[i] = new Text(this->fontFile, this->textSize); 315 bufferText[i]->setLayer(E2D_LAYER_ABOVE_ALL); 316 bufferText[i]->setAlignment(TEXT_ALIGN_LEFT); 317 bufferText[i]->setParent2D(this); 318 if(textLine != ShellBuffer::getInstance()->getBuffer().begin()) 319 { 320 bufferText[i]->setText(*textLine); 321 textLine--; 278 unsigned int oldSize = this->bufferText.size(); 279 if (oldSize > bufferDisplaySize) 280 { 281 for (unsigned int i = bufferDisplaySize; i <= oldSize; i++) 282 { 283 delete this->bufferText.back(); 284 this->bufferText.pop_back(); 285 } 286 } 287 else if (oldSize < bufferDisplaySize) 288 { 289 for (unsigned int i = oldSize; i <= bufferDisplaySize; i++) 290 { 291 this->bufferText.push_back(new Text); 322 292 } 323 293 } 324 294 this->bufferDisplaySize = bufferDisplaySize; 325 326 this->bufferText = bufferText; 327 this->shellHeight = (this->textSize + this->lineSpacing) * (bufferDisplaySize+1); 328 } 329 330 /** 331 * deletes all the Buffers 295 this->resetValues(); 296 } 297 298 /** 299 * @brief deletes all the Buffers 332 300 */ 333 301 void Shell::flush() 334 302 { 335 // remove all chars from the BufferTexts. 336 if (this->bufferText != NULL) 337 for (int i = 0; i < this->bufferDisplaySize; i++) 338 { 339 this->bufferText[i]->setText(""); 340 } 341 342 ShellBuffer::getInstance()->flush(); 343 // BUFFER FLUSHING 344 } 345 346 /** 347 * prints out some text to the input-buffers 303 for (std::list<Text*>::iterator text = this->bufferText.begin(); text != this->bufferText.end(); ++text) 304 { 305 (*text)->setText(""); // remove all chars from the BufferTexts. 306 } 307 ShellBuffer::getInstance()->flush(); 308 // BUFFER FLUSHING 309 } 310 311 /** 312 * @brief prints out some text to the input-buffers 348 313 * @param text the text to output. 349 314 */ 350 315 void Shell::printToDisplayBuffer(const std::string& text) 351 316 { 352 if(likely(bufferText != NULL)) 353 { 354 Text* lastText = this->bufferText[this->bufferDisplaySize-1]; 355 356 Text* swapText; 357 Text* moveText = this->bufferText[0]; 358 for (unsigned int i = 0; i < this->bufferDisplaySize; i++) 359 { 360 if ( i < this->bufferDisplaySize-1) 361 this->bufferText[i]->setRelCoorSoft2D(this->calculateLinePosition(i+1), 5); 362 swapText = this->bufferText[i]; 363 this->bufferText[i] = moveText; 364 moveText = swapText; 365 } 317 this->bufferText.push_front(this->bufferText.back()); 318 this->bufferText.pop_back(); 319 320 321 unsigned int i = 0; 322 for (std::list<Text*>::iterator textIt = ++this->bufferText.begin(); textIt != this->bufferText.end(); ++textIt, i++) 323 { 324 (*textIt)->setRelCoorSoft2D(this->calculateLinePosition(i+1), 5); 325 } 326 327 this->bufferText.front()->setRelCoor2D(this->calculateLinePosition(0)- Vector2D(-1000,0)); 328 this->bufferText.front()->setRelCoorSoft2D(this->calculateLinePosition(0),10); 366 329 367 330 /* FANCY EFFECTS :) … … 370 333 lastText->setRelCoorSoft2D(this->calculateLinePosition(0),10); 371 334 2: 372 */373 335 lastText->setRelDir2D(-90); 374 336 lastText->setRelDirSoft2D(0, 20); 375 lastText->setRelCoor2D(this->calculateLinePosition(0)- Vector2D(-1000,0)); 376 lastText->setRelCoorSoft2D(this->calculateLinePosition(0),10); 377 378 // lastText->setRelCoor2D(this->calculateLinePosition(0)); 379 this->bufferText[0] = lastText; 380 381 this->bufferText[0]->setText(text); 382 } 337 */ 338 339 // lastText->setRelCoor2D(this->calculateLinePosition(0)); 340 341 this->bufferText.front()->setText(text); 383 342 } 384 343 … … 392 351 { 393 352 if (this->bufferOffset == 0) 394 395 396 // for (unsigned int i = 0; i < this->bufferDisplaySize; i++)397 // this->bufferIterator->prevStep();398 353 { 354 this->bufferIterator = ShellBuffer::getInstance()->getBuffer().end(); 355 // for (unsigned int i = 0; i < this->bufferDisplaySize; i++) 356 // this->bufferIterator->prevStep(); 357 } 399 358 400 359 // boundraries … … 422 381 // redisplay the buffers 423 382 list<std::string>::const_iterator it = this->bufferIterator; 424 for ( unsigned int i = 0; i < this->bufferDisplaySize; i++)425 { 426 this->bufferText[i]->setText((*it));383 for (std::list<Text*>::iterator textIt = this->bufferText.begin(); textIt != this->bufferText.end(); ++textIt) 384 { 385 (*textIt)->setText((*it)); 427 386 it--; 428 387 } … … 514 473 PRINT(3)("Debugging output to console (not this shell)\n"); 515 474 516 // if (this->pressedKey != SDLK_FIRST)517 // printf("%s::%f %f\n", SDLKToKeyname(this->pressedKey), this->delayed, this->repeatDelay);475 // if (this->pressedKey != SDLK_FIRST) 476 // printf("%s::%f %f\n", SDLKToKeyname(this->pressedKey), this->delayed, this->repeatDelay); 518 477 519 478 -
trunk/src/lib/shell/shell.h
r7316 r7341 13 13 #include "event_listener.h" 14 14 15 #include <stdarg.h>15 #include "shell_input.h" 16 16 17 17 #define SHELL_DEFAULT_FONT "fonts/dpquake_.ttf" … … 60 60 61 61 void resetValues(); 62 void rebuildText();63 62 64 63 // BUFFERS … … 99 98 100 99 // HANDLING TEXT INPUT 101 ShellInput *shellInput; //!< The inputLine of the Shell.100 ShellInput shellInput; //!< The inputLine of the Shell. 102 101 // BUFFER 103 102 unsigned int bufferDisplaySize; //!< The Size of the Display-buffer, in lines (not in characters). 104 Text**bufferText; //!< A list of stored bufferTexts for the display of the buffer.103 std::list<Text*> bufferText; //!< A list of stored bufferTexts for the display of the buffer. 105 104 int bufferOffset; //!< how many lines from the bottom up we display the Buffer. 106 105 std::list<std::string>::const_iterator bufferIterator; //!< used to move through and print the Buffer -
trunk/src/lib/shell/shell_input.cc
r7221 r7341 60 60 evh->subscribe(this, ES_SHELL, i); 61 61 } 62 // unsubscribe unused TODO improve. 63 evh->unsubscribe(ES_SHELL, SDLK_BACKQUOTE); 64 evh->unsubscribe(ES_SHELL, SDLK_F12); 65 evh->unsubscribe(ES_SHELL, SDLK_PAGEUP); 66 evh->unsubscribe(ES_SHELL, SDLK_PAGEDOWN); 67 62 68 this->completion = new ShellCompletion(this); 63 69 }
Note: See TracChangeset
for help on using the changeset viewer.