Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/shell/shell.cc @ 5174

Last change on this file since 5174 was 5174, checked in by bensch, 19 years ago

orxonox/trunk: ShellBuffer is extern to Shell now… (But NOT used in Shell yet)

File size: 23.2 KB
Line 
1/*
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.
10
11   ### File Specific:
12   main-programmer: Benjamin Grauer
13   co-programmer: ...
14*/
15
16//#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_
17
18#include "shell.h"
19#include "shell_command.h"
20
21#include "text_engine.h"
22#include "list.h"
23#include "graphics_engine.h"
24#include "event_handler.h"
25#include "debug.h"
26#include "class_list.h"
27
28#include "key_names.h"
29#include <stdarg.h>
30#include <stdio.h>
31
32using namespace std;
33
34SHELL_COMMAND(clear, Shell, clear)->describe("Clears the shell from unwanted lines (empties all buffers)");
35SHELL_COMMAND(deactivate, Shell, deactivate)->describe("Deactivates the Shell. (moves it into background)");
36
37/**
38 * standard constructor
39 */
40Shell::Shell ()
41{
42  this->setClassID(CL_SHELL, "Shell");
43  this->setName("Shell");
44
45
46  this->bActive = false;
47  this->bufferIterator = this->buffer->getIterator();
48
49  this->inputHistory = new tList<char>;
50  //this->commandList = new tList<ShellCommand>;
51
52  this->textSize = 15;
53  this->lineSpacing = 5;
54
55  //this->bufferSize = 0;
56  this->setAbsCoor2D(3, -400);
57  this->delayed = 0;
58  this->setRepeatDelay(.3, .05);
59  this->pressedKey = SDLK_FIRST;
60
61  this->inputLineText = NULL;
62  this->inputLine = new char[1];
63  this->inputLine[0] = '\0';
64
65  this->rebuildText();
66  this->completionList = NULL;
67
68  // EVENT-Handler subscription of '`' to all States, and all other keyboard commands to ES_SEHLL
69  EventHandler* evh = EventHandler::getInstance();
70  evh->subscribe(this, ES_ALL, SDLK_BACKQUOTE);
71  for (int i = 1; i < SDLK_LAST; i++)
72    evh->subscribe(this, ES_SHELL, i);
73}
74
75Shell* Shell::singletonRef = NULL;
76
77/**
78 * standard deconstructor
79 */
80Shell::~Shell ()
81{
82  // delete the displayable Buffers
83  for (int i = 0; i < this->bufferDisplaySize; i++)
84    delete this->bufferText[i];
85  delete[] this->bufferText;
86
87  // delete the inputLine
88  delete this->inputLineText;
89  delete this->inputLine;
90
91  // delete all the Strings in the Buffers
92  char* charElem = this->bufferIterator->firstElement();
93  while (charElem != NULL)
94  {
95    delete charElem;
96    charElem = this->bufferIterator->nextElement();
97  }
98  delete this->bufferIterator;
99
100//  if (this->completionList != NULL)
101    //delete this->completionList;
102
103  Shell::singletonRef = NULL;
104}
105
106/**
107 * activates the shell
108 *
109 * This also feeds the Last few lines from the main buffers into the displayBuffer
110 */
111void Shell::activate()
112{
113  if (this->bActive == true)
114    PRINTF(3)("The shell is already active\n");
115  this->bActive = true;
116
117  EventHandler::getInstance()->setState(ES_SHELL);
118  this->setRelCoorSoft2D(0, 0, 1, 5);
119
120  this->bufferIterator->lastElement();
121  for (int i = 0; i < this->bufferDisplaySize; i++)
122    this->bufferText[i]->setText(this->bufferIterator->prevElement(), true);
123}
124
125/**
126 * deactiveates the Shell.
127 */
128void Shell::deactivate()
129{
130  if (this->bActive == false)
131    PRINTF(3)("The shell is already inactive\n");
132  this->bActive = false;
133
134  EventHandler::getInstance()->setState(ES_GAME);
135  this->setRelCoorSoft2D(0, -400, 1, 5);
136
137  this->bufferIterator->lastElement();
138  for (int i = 0; i < this->bufferDisplaySize; i++)
139    this->bufferText[i]->setText(this->bufferIterator->prevElement(), false);
140}
141
142
143/**
144 * sets the size of the text and spacing
145 * @param textSize the size of the Text in Pixels
146 * @param lineSpacing the size of the Spacing between two lines in pixels
147 *
148 * this also rebuilds the entire Text, inputLine and displayBuffer,
149 * to be accurate again.
150 */
151void Shell::setTextSize(unsigned int textSize, unsigned int lineSpacing)
152{
153  this->textSize = textSize;
154  this->lineSpacing = lineSpacing;
155
156  this->rebuildText();
157}
158
159/**
160 * rebuilds the Text's
161 *
162 * use this function, if you changed the Font/Size or something else.
163 */
164void Shell::rebuildText()
165{
166  if (this->inputLineText == NULL)
167    delete this->inputLineText;
168  this->inputLineText = TextEngine::getInstance()->createText("fonts/Aniron_Bold.ttf", this->textSize, TEXT_RENDER_DYNAMIC);
169  this->inputLineText->setColor(1, 0, 0);
170  this->inputLineText->setAlignment(TEXT_ALIGN_LEFT);
171  this->inputLineText->setText(NULL);
172  this->inputLineText->setParent2D(this);
173  this->inputLineText->setRelCoor2D(5, (this->textSize + this->lineSpacing)*this->bufferDisplaySize + this->textSize);
174
175  this->setBufferDisplaySize(this->bufferDisplaySize);
176}
177
178/**
179 * sets The count of Lines to display in the buffer.
180 * @param bufferDisplaySize the count of lines to display in the Shell-Buffer.
181 */
182void Shell::setBufferDisplaySize(unsigned int bufferDisplaySize)
183{
184  if (this->bufferText != NULL)
185  {
186    for (unsigned int i = 0; i < this->bufferDisplaySize; i++)
187      delete this->bufferText[i];
188    delete[] this->bufferText;
189  }
190
191  this->bufferText = new Text*[bufferDisplaySize];
192  for (unsigned int i = 0; i < bufferDisplaySize; i++)
193  {
194    this->bufferText[i] = TextEngine::getInstance()->createText("fonts/Aniron_Bold.ttf", this->textSize, TEXT_RENDER_DYNAMIC);
195    this->bufferText[i]->setColor(1, 0, 0);
196    this->bufferText[i]->setAlignment(TEXT_ALIGN_LEFT);
197    this->bufferText[i]->setRelCoor2D(calculateLinePosition(i));
198    this->bufferText[i]->setText(NULL);
199    this->bufferText[i]->setParent2D(this);
200  }
201  this->bufferDisplaySize = bufferDisplaySize;
202
203  this->shellHeight = (this->textSize + this->lineSpacing) * (bufferDisplaySize+1);
204}
205
206/**
207 * deletes all the Buffers
208 */
209void Shell::flushBuffers()
210{
211  // remove all chars from the BufferTexts.
212  if (this->bufferText)
213    for (int i = 0; i < this->bufferDisplaySize; i++)
214    {
215      this->bufferText[i]->setText(NULL, true);
216    }
217
218  // delete all the Chars in the Buffers
219  tIterator<char>* charIterator = this->buffer->getIterator();
220  char* charElem = charIterator->firstElement();
221  while (charElem != NULL)
222  {
223    delete charElem;
224
225    charElem = charIterator->nextElement();
226  }
227  delete charIterator;
228  delete this->buffer;
229  this->buffer = new tList<char>;
230}
231
232/**
233 * adds a new Line to the List of Buffers
234 * @param line the Line as in the first argument in printf
235 */
236bool Shell::addBufferLineStatic(const char* line, ...)
237{
238  va_list arguments;
239  va_start(arguments, line);
240
241#if DEBUG < 3
242  if (Shell::singletonRef == NULL)
243#endif
244
245  vprintf(line, arguments);
246#if DEBUG < 3
247  else
248#else
249  if (Shell::singletonRef != NULL)
250#endif
251    Shell::singletonRef->addBufferLine(line, arguments);
252  return true;
253}
254
255/**
256 * add a Line to the List of Buffers
257 * @param line
258 * @param arguments
259 *
260 * This function Adds one line to the buffer.
261 * and displays the line as the First Line of the display-buffer
262 */
263void Shell::addBufferLine(const char* line, va_list arguments)
264{
265   vsprintf(this->bufferArray, line, arguments);
266
267   char* inputEnd;
268   char* newLineBegin;
269   char* newLineEnd;
270
271   // check if we have something left in the buffers
272   if (unlikely(this->keepBuffer))
273   {
274     strcat(this->keepBufferArray, this->bufferArray);
275     inputEnd = this->keepBufferArray + strlen(this->keepBufferArray);
276     newLineBegin = this->keepBufferArray;
277     this->keepBuffer = false;
278   }
279   else
280   {
281     inputEnd = this->bufferArray + strlen(this->bufferArray);
282     newLineBegin = this->bufferArray;
283   }
284
285   // adding all the new Lines
286   while (newLineBegin < inputEnd)
287   {
288     newLineEnd = strchr(newLineBegin, '\n');
289     if (newLineEnd != NULL && *newLineEnd == '\n')
290       *newLineEnd = '\0';
291     else
292     {
293//       newLineEnd = newLineBegin + strlen(newLineBegin);
294       strcpy(this->keepBufferArray, newLineBegin);
295       this->keepBuffer = true;
296       break;
297     }
298
299     char* addLine = new char[strlen(newLineBegin)+1];
300     strcpy(addLine, newLineBegin);
301
302     this->buffer->add(addLine);
303
304     if (this->buffer->getSize() > this->bufferSize)
305     {
306       delete this->buffer->firstElement();
307       this->buffer->remove(this->buffer->firstElement());
308     }
309
310     if (this->bActive)
311     {
312       this->printToDisplayBuffer(addLine);
313     }
314     newLineBegin = newLineEnd+1;
315   }
316}
317
318/**
319 * prints out some text to the input-buffers
320 * @param text the text to output.
321 */
322void Shell::printToDisplayBuffer(const char* text)
323{
324  if(likely(bufferText != NULL))
325  {
326    Text* lastText = this->bufferText[this->bufferDisplaySize-1];
327
328    Text* swapText;
329    Text* moveText = this->bufferText[0];
330    this->bufferText[0]->setRelCoorSoft2D(this->calculateLinePosition(1),10);
331    for (unsigned int i = 1; i < this->bufferDisplaySize; i++)
332    {
333      if ( i < this->bufferDisplaySize-1)
334        this->bufferText[i]->setRelCoorSoft2D(this->calculateLinePosition(i+1),5);
335      swapText = this->bufferText[i];
336      this  ->bufferText[i] = moveText;
337      moveText = swapText;
338    }
339    lastText->setRelCoor2D(this->calculateLinePosition(0));
340    this->bufferText[0] = lastText;
341
342    this->bufferText[0]->setText(text, true);
343  }
344}
345
346/**
347 * moves the buffer around lineCount lines upwards (negative values move down)
348 * @param lineCount the Count of lines to move upwards
349 *
350 * @todo
351 */
352void Shell::moveBuffer(unsigned int lineCount)
353{
354}
355
356/**
357 * @param lineNumber the n-th line from the bottom
358 * @returns the Buffer at Line lineNumber
359 */
360const char* Shell::getBufferLine(unsigned int lineNumber)
361{
362  tIterator<char>* charIterator = this->buffer->getIterator();
363  char* charElem = charIterator->firstElement();
364
365  int i = 1;
366  while (charElem != NULL)
367  {
368    if (i++ < lineNumber)
369    {
370      delete charIterator;
371      return charElem;
372    }
373
374    charElem = charIterator->nextElement();
375  }
376  delete charIterator;
377}
378
379/**
380 * deletes the InputLine
381 */
382void Shell::flushInputLine()
383{
384  if (likely(this->inputLine != NULL))
385  {
386    delete[] this->inputLine;
387  }
388  this->inputLine = new char[1];
389  *this->inputLine = '\0';
390  this->inputLineText->setText(this->inputLine, true);
391}
392
393/**
394 * adds one character to the inputLine
395 * @param character the character to add to the inputLine
396 */
397void Shell::addCharacter(char character)
398{
399  char* addCharLine = new char[strlen(inputLine)+2];
400
401  sprintf(addCharLine, "%s%c", this->inputLine, character);
402  delete this->inputLine;
403  this->inputLine = addCharLine;
404  this->inputLineText->setText(inputLine, true);
405}
406
407/**
408 * adds multiple Characters to thr inputLine
409 * @param characters a \\0 terminated char-array to add to the InputLine
410 */
411void Shell::addCharacters(const char* characters)
412{
413  char* addCharLine = new char[strlen(inputLine)+strlen(characters)+1];
414
415  sprintf(addCharLine, "%s%s", this->inputLine, characters);
416  delete this->inputLine;
417  this->inputLine = addCharLine;
418  this->inputLineText->setText(inputLine, true);
419}
420
421/**
422 * removes characterCount characters from the InputLine
423 * @param characterCount the count of Characters to remove from the input Line
424 */
425void Shell::removeCharacters(unsigned int characterCount)
426{
427  if (strlen(this->inputLine) == 0)
428    return;
429
430  if (characterCount > strlen(this->inputLine))
431    characterCount = strlen(this->inputLine);
432
433  char* removeCharLine = new char[strlen(inputLine)-characterCount+1];
434
435  strncpy(removeCharLine, this->inputLine, strlen(inputLine)-characterCount);
436  removeCharLine[strlen(inputLine)-characterCount] = '\0';
437  delete this->inputLine;
438  this->inputLine = removeCharLine;
439  this->inputLineText->setText(inputLine, true);
440}
441
442/**
443 * executes the command stored in the inputLine
444 * @return true if the command was commited successfully, false otherwise
445 */
446bool Shell::executeCommand()
447{
448  this->addBufferLineStatic("Execute Command: %s\n", this->inputLine);
449
450  char* newCommand = new char[strlen(this->inputLine)+1];
451  strcpy(newCommand, this->inputLine);
452  this->inputHistory->add(newCommand);
453
454  ShellCommandBase::execute(this->inputLine);
455
456  this->flushInputLine();
457
458  return false;
459}
460
461/**
462 * clears the Shell (empties all buffers)
463 */
464void Shell::clear()
465{
466  this->flushBuffers();
467  this->addBufferLine("orxonox - shell\n ==================== \n", NULL);
468}
469
470/**
471 * sets the Repeate-delay and rate
472 * @param repeatDelay the Delay it takes, to repeate a key
473 * @param repeatRate the rate to repeate a pressed key
474 */
475void Shell::setRepeatDelay(float repeatDelay, float repeatRate)
476{
477  this->repeatDelay = repeatDelay;
478  this->repeatRate = repeatRate;
479
480}
481
482/**
483 * listens for some event
484 * @param event the Event happened
485 */
486void Shell::process(const Event &event)
487{
488  if (event.bPressed)
489  {
490    PRINTF(5)("Shell received command %s\n", SDLKToKeyname(event.type));
491    if (event.type == SDLK_BACKQUOTE)
492    {
493      if (EventHandler::getInstance()->getState() == ES_GAME)
494        this->activate();
495      else
496        this->deactivate();
497    }
498    else if (event.type == SDLK_F1)
499      this->help();
500    else if (event.type == SDLK_F2)
501      this->debug();
502    else if (event.type == SDLK_TAB)
503      this->autoComplete();
504    else if (event.type == SDLK_BACKSPACE)
505    {
506      this->delayed = this->repeatDelay;
507      this->pressedKey = SDLK_BACKSPACE;
508      this->removeCharacters(1);
509    }
510    else if (event.type == SDLK_RETURN)
511      this->executeCommand();
512    /*
513    else if (event.type == SDLK_UP)
514    {
515//      this->flushInputLine();
516      tIterator<char>* iterator = this->commandList->getIterator();
517      char* command = iterator->lastElement();
518      while (command)
519      {
520        if (!strcmp (command, inputLine))
521        {
522          inputLine = iterator->prevElement();
523          return;
524        }
525        command = iterator->prevElement();
526      }
527      inputLine = iterator->lastElement();
528    }
529    */
530    else if (likely(event.type < 127))
531    {
532      Uint8 *keystate = SDL_GetKeyState(NULL);
533      this->delayed = this->repeatDelay;
534      if (unlikely( keystate[SDLK_LSHIFT] || keystate[SDLK_RSHIFT] ))
535      {
536        this->pressedKey = event.type-32;
537        this->addCharacter(event.type-32);
538      }
539      else
540      {
541        this->pressedKey = event.type;
542        this->addCharacter(event.type);
543      }
544    }
545  }
546  else // if(!event.bPressed)
547  {
548    if (this->pressedKey == event.type || (this->pressedKey == event.type - 32))
549    {
550      this->pressedKey = SDLK_FIRST;
551      this->delayed = 0.0;
552    }
553  }
554}
555
556/**
557 * ticks the Shell for dt Seconds
558 * @param dt the elapsed time since the last tick();
559 */
560void Shell::tick(float dt)
561{
562  if (this->delayed > 0.0)
563    this->delayed -= dt;
564  else if (this->pressedKey != SDLK_FIRST )
565  {
566    this->delayed = this->repeatRate;
567    if (this->pressedKey == SDLK_BACKSPACE)
568      this->removeCharacters(1);
569    else if (pressedKey < 127)
570      this->addCharacter(this->pressedKey);
571  }
572}
573
574/**
575 * displays the Shell
576 */
577void Shell::draw() const
578{
579  glPushMatrix();
580  // transform for alignment.
581  // setting the Blending effects
582
583  glColor4f(0.0f, 0.0f, 0.8f, .4);
584  glEnable(GL_BLEND);
585  glDisable(GL_TEXTURE_2D);
586  glBlendFunc(GL_SRC_ALPHA, GL_ONE);
587
588  glBindTexture(GL_TEXTURE_2D, 0);
589  glBegin(GL_TRIANGLE_STRIP);
590
591  glTexCoord2f(0, 0);
592  glVertex2f(this->getAbsCoor2D().x,   this->getAbsCoor2D().);
593
594  glTexCoord2f(1, 0);
595  glVertex2f(GraphicsEngine::getInstance()->getResolutionX() - this->getAbsCoor2D().x, this->getAbsCoor2D().);
596
597  glTexCoord2f(0, 1);
598  glVertex2f(this->getAbsCoor2D().x, this->getAbsCoor2D().y + this->shellHeight);
599
600  glTexCoord2f(1, 1);
601  glVertex2f(GraphicsEngine::getInstance()->getResolutionX() - this->getAbsCoor2D().x, this->getAbsCoor2D().y + this->shellHeight);
602
603  glEnd();
604}
605
606
607/**
608 * autocompletes the Shell's inputLine
609 * @returns true, if a result was found, false otherwise
610 *
611 * @todo implement it!!
612 */
613bool Shell::autoComplete()
614{
615  //PRINTF(3)("AutoCompletion not implemented yet\n");
616
617  char* completionLine = new char[strlen(inputLine)+1];
618  strcpy(completionLine, this->inputLine);
619
620  char* commandBegin = strrchr(completionLine, ' ');
621  if (commandBegin == NULL)
622    commandBegin = completionLine;
623  else
624  {
625    if(commandBegin >= completionLine + strlen(completionLine))
626      commandBegin = completionLine + strlen(completionLine);
627    else
628      commandBegin++;
629  }
630
631  char* objectStart;
632  if (objectStart = strstr(commandBegin, "::"))
633  {
634    char* classIdentity = new char[objectStart - commandBegin +1];
635    strncpy(classIdentity, commandBegin, objectStart - commandBegin);
636    classIdentity[objectStart - commandBegin] = '\0';
637    this->objectComplete(objectStart+2, ClassList::StringToID(classIdentity));
638    delete[] classIdentity;
639  }
640  else
641    this->classComplete(commandBegin);
642
643  delete[] completionLine;
644}
645
646/**
647 * autocompletes a className
648 * @param classBegin the Beginning of a String to autoComplete
649 * @return true on success, false otherwise
650 */
651bool Shell::classComplete(const char* classBegin)
652{
653  if (unlikely(classBegin == NULL))
654    return false;
655  const tList<const char>* clList = ClassList::getClassList();
656  if (clList != NULL)
657  {
658    const tList<const char>* classList = this->createCompleteList(clList, classBegin);
659    if (classList != NULL)
660      this->generalComplete(classList, classBegin, "%s::", "::");
661    else
662      return false;
663  }
664  else
665    return false;
666  return true;
667}
668
669/**
670 * autocompletes an ObjectName
671 * @param objectBegin the beginning string of a Object
672 * @param classID the ID of the Class to search for.
673 * @return true on success, false otherwise
674 */
675bool Shell::objectComplete(const char* objectBegin, long classID)
676{
677  printf("%s\n", objectBegin);
678
679  if (unlikely(objectBegin == NULL))
680    return false;
681  tList<BaseObject>* boList = ClassList::getList(classID);
682  if (boList != NULL)
683  {
684    printf("\n", boList->firstElement()->getName());
685    const tList<const char>* objectList = this->createCompleteList(boList, objectBegin);
686    if (objectList != NULL)
687      this->generalComplete(objectList, objectBegin, "%s");
688    else
689      return false;
690  }
691  else
692    return false;
693  return true;
694}
695
696/**
697 * completes a Function
698 * @param functionBegin the beginning of the function String
699 */
700bool Shell::functionComplete(const char* functionBegin)
701{
702}
703
704/**
705 * completes the inputline on grounds of an inputList
706 * @param stringList the List to parse through
707 * @param begin the String to search in the inputList, and to extend with it.
708 * @param displayAs how to display the found value to the user, printf-style, !!with only one %s!! ex.: "::%s::"
709 * @param addBack what should be added at the end of the completion
710 * @param addFront what should be added to the front of one finished completion
711 * @return true if ok, false otherwise
712 */
713bool Shell::generalComplete(const tList<const char>* stringList, const char* begin, const char* displayAs, const char* addBack, const char* addFront)
714{
715  if (stringList->getSize() == 0)
716    return false;
717
718  const char* addString = stringList->firstElement();
719  unsigned int addLength = 0;
720  unsigned int inputLenght = strlen(begin);
721
722  if (addString != NULL)
723    addLength = strlen(addString);
724  tIterator<const char>* charIterator = stringList->getIterator();
725  const char* charElem = charIterator->firstElement();
726  while (charElem != NULL)
727  {
728    PRINTF(0)(displayAs, charElem);
729    for (unsigned int i = inputLenght; i < addLength; i++)
730      if (addString[i] != charElem[i])
731    {
732      addLength = i;
733      break;
734    }
735    charElem = charIterator->nextElement();
736  }
737  delete charIterator;
738
739  if (addLength >= inputLenght)
740  {
741    char* adder = new char[addLength+1];
742    strncpy(adder, addString, addLength);
743    adder[addLength] = '\0';
744    this->removeCharacters(inputLenght);
745    this->addCharacters(adder);
746    if (addBack != NULL && stringList->getSize() == 1)
747      this->addCharacters("::");
748    delete[] adder;
749  }
750  return true;
751}
752
753/**
754 * searches for classes, which beginn with classNameBegin
755 * @param inputList the List to parse through
756 * @param classNameBegin the beginning string
757 * @return a NEW char-array with ClassNames. The LIST should be deleted afterwards,
758 * !! The strings MUST NOT be deleted !!
759 */
760const tList<const char>* Shell::createCompleteList(const tList<const char>* inputList, const char* classNameBegin)
761{
762  if (inputList == NULL || classNameBegin == NULL)
763    return NULL;
764  unsigned int searchLength = strlen(classNameBegin);
765  if (this->completionList != NULL)
766    delete this->completionList;
767  this->completionList = new tList<const char>;
768
769//  tList<const char>* classList = ClassList::getClassList();
770
771  tIterator<const char>* iterator = inputList->getIterator();
772  const char* enumString = iterator->firstElement();
773  while (enumString != NULL)
774  {
775    if (strlen(enumString)>searchLength+1 &&
776        !strncasecmp(enumString, classNameBegin, searchLength))
777    {
778      this->completionList->add(enumString);
779    }
780    enumString = iterator->nextElement();
781  }
782  delete iterator;
783
784  return this->completionList;
785}
786
787/**
788 * searches for classes, which beginn with classNameBegin
789 * @param inputList the List to parse through
790 * @param classNameBegin the beginning string
791 * @return a NEW char-array with ClassNames. The LIST should be deleted afterwards,
792 * !! The strings MUST NOT be deleted !!
793 */
794const tList<const char>* Shell::createCompleteList(const tList<BaseObject>* inputList, const char* classNameBegin)
795{
796  if (inputList == NULL || classNameBegin == NULL)
797    return NULL;
798  unsigned int searchLength = strlen(classNameBegin);
799  if (this->completionList != NULL)
800    delete this->completionList;
801  this->completionList = new tList<const char>;
802
803  tIterator<BaseObject>* iterator = inputList->getIterator();
804  BaseObject* enumBO = iterator->firstElement();
805  while (enumBO != NULL)
806  {
807    if (enumBO->getName() != NULL &&
808        strlen(enumBO->getName())>searchLength+1 &&
809        !strncasecmp(enumBO->getName(), classNameBegin, searchLength))
810    {
811      this->completionList->add(enumBO->getName());
812    }
813    enumBO = iterator->nextElement();
814  }
815  delete iterator;
816
817  return this->completionList;
818}
819
820/**
821 * prints out some nice help about the Shell
822 */
823void Shell::help() const
824{
825  PRINT(0)("Help for the most important Shell-commands\n");
826  PRINT(0)("F1 - HELP; F2 - DEBUG; ` - open/close shell\n");
827  PRINT(0)("input order:\n");
828  PRINT(0)("ClassName::objectName function [parameter1, [parameter2 ...]]  or\n");
829  PRINT(0)("Command [parameter]\n");
830}
831
832
833///////////////////////
834// HELPER FUNCTIONS  //
835///////////////////////
836
837/**
838 * calculates the position of a Buffer-Display Line
839 * @param lineNumber the lineNumber from the bottom to calculate the position from
840 * @returns the Position of the Line.
841 */
842Vector Shell::calculateLinePosition(unsigned int lineNumber)
843{
844  return Vector(5, (this->textSize + this->lineSpacing)*(this->bufferDisplaySize - lineNumber -1) + this->textSize, 0);
845}
846
847
848
849/**
850 * displays some nice output from the Shell
851 */
852void Shell::debug() const
853{
854  PRINT(3)("Debugging output to console (not this shell)\n");
855
856  if (this->pressedKey != SDLK_FIRST)
857    printf("%s::%f %f\n", SDLKToKeyname(this->pressedKey), this->delayed, this->repeatDelay);
858
859
860  char* tmpChar = this->bufferIterator->firstElement();
861  while(tmpChar != NULL)
862  {
863    printf(tmpChar);
864    tmpChar = this->bufferIterator->nextElement();
865  }
866}
867
868
869
870// void Shell::testI (int i)
871// {
872//   PRINTF(3)("This is the Test for one Int '%d'\n", i);
873// }
874//
875// void Shell::testS (const char* s)
876// {
877//   PRINTF(3)("This is the Test for one String '%s'\n", s);
878// }
879//
880// void Shell::testB (bool b)
881// {
882//   PRINTF(3)("This is the Test for one Bool: ");
883//   if (b)
884//     PRINTF(3)("true\n");
885//   else
886//     PRINTF(3)("false\n");
887// }
888//
889// void Shell::testF (float f)
890// {
891//   PRINTF(3)("This is the Test for one Float '%f'\n", f);
892// }
893//
894// void Shell::testSF (const char* s, float f)
895// {
896//   PRINTF(3)("This is the Test for one String '%s' and one Float '%f'\n",s , f);
897// }
Note: See TracBrowser for help on using the repository browser.