[4744] | 1 | /* |
---|
[1853] | 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. |
---|
[1855] | 10 | |
---|
| 11 | ### File Specific: |
---|
[5068] | 12 | main-programmer: Benjamin Grauer |
---|
[1855] | 13 | co-programmer: ... |
---|
[1853] | 14 | */ |
---|
| 15 | |
---|
[3955] | 16 | //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_ |
---|
[1853] | 17 | |
---|
[5068] | 18 | #include "shell.h" |
---|
[1853] | 19 | |
---|
[5072] | 20 | #include "text_engine.h" |
---|
| 21 | #include "list.h" |
---|
| 22 | |
---|
[1856] | 23 | using namespace std; |
---|
[1853] | 24 | |
---|
[1856] | 25 | |
---|
[3245] | 26 | /** |
---|
[4838] | 27 | * standard constructor |
---|
[5068] | 28 | */ |
---|
| 29 | Shell::Shell () |
---|
[3365] | 30 | { |
---|
[5072] | 31 | this->setClassID(CL_SHELL, "Shell"); |
---|
| 32 | this->setName("Shell"); |
---|
| 33 | |
---|
| 34 | this->bufferText = new tList<Text>; |
---|
| 35 | this->buffer = new tList<char>; |
---|
| 36 | |
---|
| 37 | this->setBufferSize(100); |
---|
| 38 | this->setBufferDisplaySize(5); |
---|
[5068] | 39 | } |
---|
[4320] | 40 | |
---|
| 41 | |
---|
[5068] | 42 | Shell* Shell::singletonRef = NULL; |
---|
[1853] | 43 | |
---|
[3245] | 44 | /** |
---|
[4838] | 45 | * standard deconstructor |
---|
[5068] | 46 | */ |
---|
| 47 | Shell::~Shell () |
---|
[3543] | 48 | { |
---|
| 49 | // delete what has to be deleted here |
---|
[5068] | 50 | |
---|
| 51 | Shell::singletonRef = NULL; |
---|
[3543] | 52 | } |
---|
[5068] | 53 | |
---|
[5072] | 54 | void Shell::setBufferDisplaySize(unsigned int bufferDisplaySize) |
---|
| 55 | { |
---|
| 56 | this->bufferDisplaySize = bufferDisplaySize; |
---|
[5068] | 57 | |
---|
[5072] | 58 | while (bufferDisplaySize < this->bufferText->getSize()) |
---|
| 59 | { |
---|
| 60 | delete this->bufferText->lastElement(); |
---|
| 61 | this->bufferText->removeLast(); |
---|
| 62 | } |
---|
| 63 | while(bufferDisplaySize > this->bufferText->getSize()) |
---|
| 64 | { |
---|
| 65 | Text* newText = TextEngine::getInstance()->createText("fonts/earth.ttf", 30, TEXT_DYNAMIC, 0, 255, 0); |
---|
| 66 | this->bufferText->add(newText); |
---|
| 67 | // add the Text here |
---|
| 68 | } |
---|
| 69 | } |
---|
[5068] | 70 | |
---|
| 71 | /** |
---|
| 72 | * deletes all the Buffers |
---|
| 73 | */ |
---|
| 74 | void Shell::flushBuffers() |
---|
| 75 | { |
---|
[5072] | 76 | // remove all chars from the BufferTexts. |
---|
| 77 | tIterator<Text>* textIterator = this->bufferText->getIterator(); |
---|
| 78 | Text* textElem = textIterator->nextElement(); |
---|
[5068] | 79 | |
---|
[5072] | 80 | while (textElem != NULL) |
---|
| 81 | { |
---|
| 82 | textElem->setText(NULL); |
---|
| 83 | |
---|
| 84 | textElem = textIterator->nextElement(); |
---|
| 85 | } |
---|
| 86 | delete textIterator; |
---|
| 87 | |
---|
| 88 | |
---|
| 89 | // delete all the Chars in the Buffers |
---|
| 90 | tIterator<char>* charIterator = this->buffer->getIterator(); |
---|
| 91 | char* charElem = charIterator->nextElement(); |
---|
| 92 | |
---|
| 93 | while (charElem != NULL) |
---|
| 94 | { |
---|
| 95 | delete charElem; |
---|
| 96 | |
---|
| 97 | charElem = charIterator->nextElement(); |
---|
| 98 | } |
---|
| 99 | delete charIterator; |
---|
[5068] | 100 | } |
---|
| 101 | |
---|
| 102 | /** |
---|
| 103 | * adds a new Line to the List of Buffers |
---|
| 104 | * @param line the Line as in the first argument in printf |
---|
| 105 | * @param args the arguments as a va_list |
---|
[5072] | 106 | * |
---|
| 107 | * @todo optimize |
---|
[5068] | 108 | */ |
---|
| 109 | void Shell::addBufferLine(const char* line, va_list args) |
---|
| 110 | { |
---|
[5072] | 111 | char tmp[1024];// = new char* |
---|
| 112 | vsprintf(tmp, line, args); |
---|
| 113 | |
---|
| 114 | char* newLine = new char[strlen(tmp)+1]; |
---|
| 115 | strcpy(newLine, tmp); |
---|
| 116 | |
---|
| 117 | this->buffer->add(newLine); |
---|
| 118 | |
---|
| 119 | if (this->buffer->getSize() > this->bufferSize) |
---|
| 120 | { |
---|
| 121 | delete this->buffer->firstElement(); |
---|
| 122 | this->buffer->remove(this->buffer->firstElement()); |
---|
| 123 | } |
---|
[5073] | 124 | |
---|
| 125 | |
---|
[5068] | 126 | } |
---|
| 127 | |
---|
| 128 | /** |
---|
| 129 | * moves the buffer around lineCount lines upwards (negative values move down) |
---|
| 130 | * @param lineCount the Count of lines to move upwards |
---|
[5072] | 131 | * |
---|
| 132 | * @todo |
---|
[5068] | 133 | */ |
---|
| 134 | void Shell::moveBuffer(int lineCount) |
---|
| 135 | { |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | /** |
---|
| 139 | * @param lineNumber the n-th line from the bottom |
---|
| 140 | * @returns the Buffer at Line lineNumber |
---|
| 141 | */ |
---|
| 142 | const char* Shell::getBufferLine(unsigned int lineNumber) |
---|
| 143 | { |
---|
[5072] | 144 | tIterator<char>* charIterator = this->buffer->getIterator(); |
---|
| 145 | char* charElem = charIterator->nextElement(); |
---|
| 146 | |
---|
| 147 | int i = 1; |
---|
| 148 | while (charElem != NULL) |
---|
| 149 | { |
---|
| 150 | if (i++ < lineNumber) |
---|
| 151 | { |
---|
| 152 | delete charIterator; |
---|
| 153 | return charElem; |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | charElem = charIterator->nextElement(); |
---|
| 157 | } |
---|
| 158 | delete charIterator; |
---|
[5068] | 159 | } |
---|
| 160 | |
---|
| 161 | |
---|
| 162 | /** |
---|
| 163 | * deletes the InputLine |
---|
| 164 | */ |
---|
| 165 | void Shell::flushInputLine() |
---|
| 166 | { |
---|
[5072] | 167 | if (likely(this->inputLine != NULL)) |
---|
| 168 | { |
---|
| 169 | delete [] this->inputLine; |
---|
| 170 | } |
---|
| 171 | this->inputLine = new char[1]; |
---|
| 172 | *this->inputLine = '\0'; |
---|
| 173 | |
---|
[5068] | 174 | } |
---|
| 175 | |
---|
| 176 | /** |
---|
| 177 | * adds one character to the inputLine |
---|
| 178 | * @param character the character to add to the inputLine |
---|
| 179 | */ |
---|
| 180 | void Shell::addCharacter(char character) |
---|
| 181 | { |
---|
[5072] | 182 | char* addCharLine = new char[strlen(inputLine)+2]; |
---|
| 183 | |
---|
| 184 | sprintf(addCharLine, "%s%c", this->inputLine, character); |
---|
| 185 | delete this->inputLine; |
---|
| 186 | this->inputLine = addCharLine; |
---|
[5068] | 187 | } |
---|
| 188 | |
---|
| 189 | /** |
---|
| 190 | * adds multiple Characters to thr inputLine |
---|
| 191 | * @param characters a '\0' terminated char-array to add to the InputLine |
---|
| 192 | */ |
---|
| 193 | void Shell::addCharacters(const char* characters) |
---|
| 194 | { |
---|
[5072] | 195 | char* addCharLine = new char[strlen(inputLine)+strlen(characters)+1]; |
---|
| 196 | |
---|
| 197 | sprintf(addCharLine, "%s%s", this->inputLine, characters); |
---|
| 198 | delete this->inputLine; |
---|
| 199 | this->inputLine = addCharLine; |
---|
[5068] | 200 | } |
---|
| 201 | |
---|
| 202 | /** |
---|
| 203 | * removes characterCount characters from the InputLine |
---|
| 204 | * @param characterCount the count of Characters to remove from the input Line |
---|
| 205 | */ |
---|
| 206 | void Shell::removeCharacters(unsigned int characterCount) |
---|
| 207 | { |
---|
[5072] | 208 | if (characterCount > strlen(this->inputLine)) |
---|
| 209 | characterCount = strlen(this->inputLine); |
---|
| 210 | |
---|
| 211 | char* removeCharLine = new char[strlen(inputLine)-characterCount+1]; |
---|
| 212 | |
---|
| 213 | strncpy(removeCharLine, this->inputLine, strlen(inputLine)-characterCount); |
---|
| 214 | delete this->inputLine; |
---|
| 215 | this->inputLine = removeCharLine; |
---|
[5068] | 216 | } |
---|
| 217 | |
---|
[5069] | 218 | /** |
---|
| 219 | * listens for some event |
---|
| 220 | * @param event the Event happened |
---|
| 221 | */ |
---|
| 222 | void Shell::process(const Event &event) |
---|
| 223 | { |
---|
| 224 | // if (event.type) |
---|
[5068] | 225 | |
---|
[5069] | 226 | } |
---|
| 227 | |
---|
[5068] | 228 | /** |
---|
| 229 | * ticks the Shell for dt Seconds |
---|
| 230 | * @param dt the elapsed time since the last tick(); |
---|
| 231 | */ |
---|
| 232 | void Shell::tick(float dt) |
---|
| 233 | { |
---|
| 234 | } |
---|
| 235 | |
---|
| 236 | /** |
---|
| 237 | * displays the Shell |
---|
| 238 | */ |
---|
| 239 | void Shell::draw() const |
---|
| 240 | { |
---|
| 241 | } |
---|
| 242 | |
---|
| 243 | |
---|
| 244 | /** |
---|
| 245 | * autocompletes the Shell's inputLine |
---|
| 246 | * @returns true, if a result was found, false otherwise |
---|
| 247 | */ |
---|
| 248 | bool Shell::autoComplete() |
---|
| 249 | { |
---|
| 250 | |
---|
| 251 | } |
---|
| 252 | |
---|
| 253 | /** |
---|
| 254 | * displays some nice output from the Shell |
---|
| 255 | */ |
---|
| 256 | void Shell::debug() const |
---|
| 257 | { |
---|
| 258 | |
---|
| 259 | } |
---|