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