| 1 | /*! | 
|---|
| 2 |  * @file shell.h | 
|---|
| 3 |  * Definition of a on-screen-shell | 
|---|
| 4 | */ | 
|---|
| 5 |  | 
|---|
| 6 | #ifndef _SHELL_H | 
|---|
| 7 | #define _SHELL_H | 
|---|
| 8 |  | 
|---|
| 9 | #include "element_2d.h" | 
|---|
| 10 | #include "event_listener.h" | 
|---|
| 11 |  | 
|---|
| 12 | #include <stdarg.h> | 
|---|
| 13 |  | 
|---|
| 14 | // FORWARD DECLARATION | 
|---|
| 15 | class Text; | 
|---|
| 16 | template<class T> class tList; | 
|---|
| 17 | template<class T> class tIterator; | 
|---|
| 18 |  | 
|---|
| 19 | //! A class that is able to redirect all output to a openGL-Shell, and that one can use to input some commands | 
|---|
| 20 | /** | 
|---|
| 21 |  * the major idea is, that all the Output can be redirected to the Shell, | 
|---|
| 22 |  * and does not have to be displayed to the opening Shell, this is good, | 
|---|
| 23 |  * for developers using Windows, where all output is otherwise redirected | 
|---|
| 24 |  * to stdout.txt | 
|---|
| 25 |  * | 
|---|
| 26 |  * Furthermore the Shell should enable us, to input some simple commands | 
|---|
| 27 |  * Each Class can tell check itself in to the Shell, and listen for commands. | 
|---|
| 28 |  * | 
|---|
| 29 |  * @todo implement what is written above :/ | 
|---|
| 30 |  */ | 
|---|
| 31 | class Shell : public Element2D, public EventListener { | 
|---|
| 32 |  | 
|---|
| 33 |   public: | 
|---|
| 34 |     virtual ~Shell(); | 
|---|
| 35 |     /** @returns a Pointer to the only object of this Class */ | 
|---|
| 36 |     inline static Shell* getInstance() { if (!Shell::singletonRef) Shell::singletonRef = new Shell();  return Shell::singletonRef; }; | 
|---|
| 37 |  | 
|---|
| 38 |  | 
|---|
| 39 |     void activate(); | 
|---|
| 40 |     void deactivate(); | 
|---|
| 41 |  | 
|---|
| 42 |     void setTextSize(unsigned int textSize, unsigned int lineSpacing = 1); | 
|---|
| 43 |     void rebuildText(); | 
|---|
| 44 |  | 
|---|
| 45 |     // BUFFER // | 
|---|
| 46 |     void setBufferSize(unsigned int bufferSize) { this->bufferSize = bufferSize; }; | 
|---|
| 47 |     void setBufferDisplaySize(unsigned int bufferDisplaySize); | 
|---|
| 48 |     void flushBuffers(); | 
|---|
| 49 |     static bool addBufferLineStatic(const char* line, ...); | 
|---|
| 50 |     void addBufferLine(const char* line, va_list arg); | 
|---|
| 51 |     void printToDisplayBuffer(const char* text); | 
|---|
| 52 |     void moveBuffer(int lineCount); | 
|---|
| 53 |     const char* getBufferLine(unsigned int lineNumber); | 
|---|
| 54 |  | 
|---|
| 55 |     // InputLine | 
|---|
| 56 |     void flushInputLine(); | 
|---|
| 57 |     void addCharacter(char character); | 
|---|
| 58 |     void addCharacters(const char* characters); | 
|---|
| 59 |     void removeCharacters(unsigned int characterCount = 1); | 
|---|
| 60 |     bool executeCommand(); | 
|---|
| 61 |  | 
|---|
| 62 |     void setRepeatDelay(float repeatDelay, float repeatRate); | 
|---|
| 63 |  | 
|---|
| 64 |     // EventListener | 
|---|
| 65 |     virtual void process(const Event &event); | 
|---|
| 66 |  | 
|---|
| 67 |     // Element2D-functions | 
|---|
| 68 |     void tick(float dt); | 
|---|
| 69 |     virtual void draw() const; | 
|---|
| 70 |  | 
|---|
| 71 |     void help() const; | 
|---|
| 72 |     void debug() const; | 
|---|
| 73 |  | 
|---|
| 74 |   private: | 
|---|
| 75 |     bool autoComplete(); | 
|---|
| 76 |     bool classComplete(const char* classBegin); | 
|---|
| 77 |     bool objectComplete(const char* objectBegin, long classID); | 
|---|
| 78 |     bool functionComplete(const char* functionBegin); | 
|---|
| 79 |  | 
|---|
| 80 |     bool generalComplete(const tList<const char>* stringList, const char* begin, const char* displayAs = "%s", const char* addBack = NULL, const char* addFront = NULL); | 
|---|
| 81 |  | 
|---|
| 82 |     const tList<const char>* Shell::createCompleteList(const tList<const char>* inputList, const char* classNameBegin); | 
|---|
| 83 |     const tList<const char>* Shell::createCompleteList(const tList<BaseObject>* inputList, const char* classNameBegin); | 
|---|
| 84 |  | 
|---|
| 85 |  | 
|---|
| 86 |   private: | 
|---|
| 87 |     Shell(); | 
|---|
| 88 |     static Shell*          singletonRef;           //!< The singleton-reference to the only memeber of this class. | 
|---|
| 89 |  | 
|---|
| 90 |     unsigned int           bufferSize;             //!< The Size of the buffer | 
|---|
| 91 |     unsigned int           bufferDisplaySize;      //!< The Size of the Display-buffer, in lines (not in characters) | 
|---|
| 92 |  | 
|---|
| 93 |     Text*                  inputLineText;          //!< The inputLine of the Shell | 
|---|
| 94 |     char*                  inputLine;              //!< the Char-Array of the Buffer | 
|---|
| 95 |     float                  repeatRate;             //!< The Repeat-Delay. | 
|---|
| 96 |     float                  repeatDelay;            //!< The delay of the first Character of a given Character. | 
|---|
| 97 |     float                  delayed;                //!< how much of the delay is remaining. | 
|---|
| 98 |     int                    pressedKey;             //!< the pressed key that will be repeated. | 
|---|
| 99 |  | 
|---|
| 100 |     tList<char>*           buffer;                 //!< A list of stored char-arrays(strings) to store the history | 
|---|
| 101 |     tIterator<char>*       bufferIterator;         //!< An iterator for the Shells main buffer. | 
|---|
| 102 |  | 
|---|
| 103 |     Text**                 bufferText;             //!< A list of stored bufferTexts for the display of the buffer | 
|---|
| 104 |     unsigned int           textSize;               //!< The size of the text. | 
|---|
| 105 |     unsigned int           lineSpacing;            //!< The Spacing between lines. | 
|---|
| 106 |     unsigned int           shellHeight;            //!< The hight of the Shell in Pixels | 
|---|
| 107 |     bool                   bActive;                //!< if the shell is active; | 
|---|
| 108 |  | 
|---|
| 109 |     char                   bufferArray[10000];     //!< a BUFFER for fast writing | 
|---|
| 110 |  | 
|---|
| 111 |     // completion | 
|---|
| 112 |     tList<const char>*    completionList;          //!< A list of completions, that are io. | 
|---|
| 113 | }; | 
|---|
| 114 |  | 
|---|
| 115 | #endif /* _SHELL_H */ | 
|---|