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