Changeset 5180 in orxonox.OLD for trunk/src/lib/shell
- Timestamp:
- Sep 13, 2005, 11:45:51 PM (19 years ago)
- Location:
- trunk/src/lib/shell
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/shell/shell.cc
r5179 r5180 58 58 // INPUT LINE 59 59 this->shellInput = new ShellInput; 60 this->delayed = 0;61 this->shellInput->setRepeatDelay(.3, .05);62 60 //this->commandList = new tList<ShellCommand>; 63 61 … … 65 63 this->completionList = NULL; 66 64 67 // EVENT-Handler subscription of '`' to all States, and all other keyboard commands to ES_SEHLL 68 EventHandler* evh = EventHandler::getInstance(); 69 evh->subscribe(this, ES_ALL, SDLK_BACKQUOTE); 70 for (int i = 1; i < SDLK_LAST; i++) 71 evh->subscribe(this, ES_SHELL, i); 65 // EVENT-Handler subscription of '`' to all States. 66 EventHandler::getInstance()->subscribe(this, ES_ALL, SDLK_BACKQUOTE); 67 72 68 } 73 69 … … 85 81 86 82 // delete the inputLine 83 delete this->shellInput; 87 84 88 85 Shell::singletonRef = NULL; … … 250 247 if (event.bPressed) 251 248 { 252 PRINTF(5)("Shell received command %s\n", SDLKToKeyname(event.type));253 249 if (event.type == SDLK_BACKQUOTE) 254 250 { … … 258 254 this->deactivate(); 259 255 } 260 else if (event.type == SDLK_F1)261 this->help();262 else if (event.type == SDLK_F2)263 this->debug();264 else if (event.type == SDLK_TAB)265 ;//this->autoComplete();266 else if (event.type == SDLK_BACKSPACE)267 {268 this->delayed = this->repeatDelay;269 this->pressedKey = SDLK_BACKSPACE;270 this->shellInput->removeCharacters(1);271 }272 else if (event.type == SDLK_RETURN)273 this->shellInput->executeCommand();274 /*275 else if (event.type == SDLK_UP)276 {277 // this->flushInputLine();278 tIterator<char>* iterator = this->commandList->getIterator();279 char* command = iterator->lastElement();280 while (command)281 {282 if (!strcmp (command, inputLine))283 {284 inputLine = iterator->prevElement();285 return;286 }287 command = iterator->prevElement();288 }289 inputLine = iterator->lastElement();290 }291 */292 else if (likely(event.type < 127))293 {294 Uint8 *keystate = SDL_GetKeyState(NULL);295 this->delayed = this->repeatDelay;296 if (unlikely( keystate[SDLK_LSHIFT] || keystate[SDLK_RSHIFT] ))297 {298 this->pressedKey = event.type-32;299 this->shellInput->addCharacter(event.type-32);300 }301 else302 {303 this->pressedKey = event.type;304 this->shellInput->addCharacter(event.type);305 }306 }307 256 } 308 else // if(!event.bPressed) 309 { 310 if (this->pressedKey == event.type || (this->pressedKey == event.type - 32)) 311 { 312 this->pressedKey = SDLK_FIRST; 313 this->delayed = 0.0; 314 } 315 } 316 } 317 318 /** 319 * ticks the Shell for dt Seconds 320 * @param dt the elapsed time since the last tick(); 321 */ 322 void Shell::tick(float dt) 323 { 324 if (this->delayed > 0.0) 325 this->delayed -= dt; 326 else if (this->pressedKey != SDLK_FIRST ) 327 { 328 this->delayed = this->repeatRate; 329 if (this->pressedKey == SDLK_BACKSPACE) 330 this->shellInput->removeCharacters(1); 331 else if (pressedKey < 127) 332 this->shellInput->addCharacter(this->pressedKey); 333 } 334 } 257 } 258 335 259 /** 336 260 * displays the Shell … … 365 289 } 366 290 367 /**368 * prints out some nice help about the Shell369 */370 void Shell::help() const371 {372 PRINT(0)("Help for the most important Shell-commands\n");373 PRINT(0)("F1 - HELP; F2 - DEBUG; ` - open/close shell\n");374 PRINT(0)("input order:\n");375 PRINT(0)("ClassName::objectName function [parameter1, [parameter2 ...]] or\n");376 PRINT(0)("Command [parameter]\n");377 }378 379 380 291 /////////////////////// 381 292 // HELPER FUNCTIONS // … … 401 312 PRINT(3)("Debugging output to console (not this shell)\n"); 402 313 403 if (this->pressedKey != SDLK_FIRST)404 printf("%s::%f %f\n", SDLKToKeyname(this->pressedKey), this->delayed, this->repeatDelay);314 // if (this->pressedKey != SDLK_FIRST) 315 // printf("%s::%f %f\n", SDLKToKeyname(this->pressedKey), this->delayed, this->repeatDelay); 405 316 406 317 -
trunk/src/lib/shell/shell.h
r5179 r5180 54 54 void clear(); 55 55 56 57 56 // EventListener 58 57 virtual void process(const Event &event); 59 58 60 59 // Element2D-functions 61 void tick(float dt);62 60 virtual void draw() const; 63 61 64 void help() const;65 62 void debug() const; 66 63 … … 79 76 static Shell* singletonRef; //!< The singleton-reference to the only memeber of this class. 80 77 81 unsigned int bufferDisplaySize; //!< The Size of the Display-buffer, in lines (not in characters) 78 // GENERAL 79 bool bActive; //!< if the shell is active; 80 unsigned int shellHeight; //!< The hight of the Shell in Pixels 81 unsigned int lineSpacing; //!< The Spacing between lines. 82 unsigned int textSize; //!< The size of the text. 82 83 83 84 // HANDLING TEXT INPUT 84 85 ShellInput* shellInput; 85 86 float repeatRate; //!< The Repeat-Delay. 87 float repeatDelay; //!< The delay of the first Character of a given Character. 88 float delayed; //!< how much of the delay is remaining. 89 int pressedKey; //!< the pressed key that will be repeated. 90 91 tList<char>* inputHistory; //!< The history of given commands. 92 86 // BUFFER 87 unsigned int bufferDisplaySize; //!< The Size of the Display-buffer, in lines (not in characters) 93 88 Text** bufferText; //!< A list of stored bufferTexts for the display of the buffer 94 unsigned int textSize; //!< The size of the text.95 unsigned int lineSpacing; //!< The Spacing between lines.96 unsigned int shellHeight; //!< The hight of the Shell in Pixels97 bool bActive; //!< if the shell is active;98 89 99 90 // completion -
trunk/src/lib/shell/shell_input.cc
r5179 r5180 18 18 #include "shell_input.h" 19 19 20 #include " text_engine.h"20 #include "event_handler.h" 21 21 22 22 #include "shell_command.h" … … 25 25 #include "compiler.h" 26 26 #include "stdlibincl.h" 27 #include "key_names.h" 28 27 29 28 30 using namespace std; … … 40 42 this->inputLine[0] = '\0'; 41 43 this->inputHistory = new tList<char>; 44 this->delayed = 0; 45 this->setRepeatDelay(.3, .05); 46 47 // subscribe all keyboard commands to ES_SEHLL 48 EventHandler* evh = EventHandler::getInstance(); 49 for (int i = 1; i < SDLK_LAST; i++) 50 evh->subscribe(this, ES_SHELL, i); 51 42 52 } 43 53 … … 144 154 } 145 155 156 157 /** 158 * prints out some nice help about the Shell 159 */ 160 void ShellInput::help() const 161 { 162 PRINT(0)("Help for the most important Shell-commands\n"); 163 PRINT(0)("F1 - HELP; F2 - DEBUG; ` - open/close shell\n"); 164 PRINT(0)("input order:\n"); 165 PRINT(0)("ClassName::objectName function [parameter1, [parameter2 ...]] or\n"); 166 PRINT(0)("Command [parameter]\n"); 167 } 168 169 void ShellInput::tick(float dt) 170 { 171 if (this->delayed > 0.0) 172 this->delayed -= dt; 173 else if (this->pressedKey != SDLK_FIRST ) 174 { 175 this->delayed = this->repeatRate; 176 if (this->pressedKey == SDLK_BACKSPACE) 177 this->removeCharacters(1); 178 else if (pressedKey < 127) 179 this->addCharacter(this->pressedKey); 180 } 181 } 182 183 /** 184 * listens for some event 185 * @param event the Event happened 186 */ 187 void ShellInput::process(const Event &event) 188 { 189 if (event.bPressed) 190 { 191 PRINTF(5)("Shell received command %s\n", SDLKToKeyname(event.type)); 192 if (event.type == SDLK_F1) 193 this->help(); 194 else if (event.type == SDLK_F2) 195 this->debug(); 196 else if (event.type == SDLK_TAB) 197 ;//this->autoComplete(); 198 else if (event.type == SDLK_BACKSPACE) 199 { 200 this->delayed = this->repeatDelay; 201 this->pressedKey = SDLK_BACKSPACE; 202 this->removeCharacters(1); 203 } 204 else if (event.type == SDLK_RETURN) 205 this->executeCommand(); 206 /* 207 else if (event.type == SDLK_UP) 208 { 209 // this->flushInputLine(); 210 tIterator<char>* iterator = this->commandList->getIterator(); 211 char* command = iterator->lastElement(); 212 while (command) 213 { 214 if (!strcmp (command, inputLine)) 215 { 216 inputLine = iterator->prevElement(); 217 return; 218 } 219 command = iterator->prevElement(); 220 } 221 inputLine = iterator->lastElement(); 222 } 223 */ 224 else if (likely(event.type < 127)) 225 { 226 Uint8 *keystate = SDL_GetKeyState(NULL); 227 this->delayed = this->repeatDelay; 228 if (unlikely( keystate[SDLK_LSHIFT] || keystate[SDLK_RSHIFT] )) 229 { 230 this->pressedKey = event.type-32; 231 this->addCharacter(event.type-32); 232 } 233 else 234 { 235 this->pressedKey = event.type; 236 this->addCharacter(event.type); 237 } 238 } 239 } 240 else // if(!event.bPressed) 241 { 242 if (this->pressedKey == event.type || (this->pressedKey == event.type - 32)) 243 { 244 this->pressedKey = SDLK_FIRST; 245 this->delayed = 0.0; 246 } 247 } 248 } -
trunk/src/lib/shell/shell_input.h
r5179 r5180 8 8 9 9 #include "text_engine.h" 10 #include "event_listener.h" 10 11 11 12 // FORWARD DECLARATION … … 14 15 15 16 //! A class for ... 16 class ShellInput : public Text {17 class ShellInput : public Text, public EventListener { 17 18 18 19 public: … … 28 29 void setRepeatDelay(float repeatDelay, float repeatRate); 29 30 bool executeCommand(); 31 void help() const; 30 32 const char* getInputString() const { return this->inputLine; }; 31 33 34 35 virtual void tick(float dt); 36 virtual void process(const Event &event); 32 37 33 38 private:
Note: See TracChangeset
for help on using the changeset viewer.