| [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" |
|---|
| [1853] | 11 | |
|---|
| [5068] | 12 | #include <stdarg.h> |
|---|
| 13 | |
|---|
| [5127] | 14 | #define SHELL_BUFFER_SIZE 16384 //!< The Size of the input-buffers (should be large enough to carry any kind of input) |
|---|
| 15 | |
|---|
| [4838] | 16 | // FORWARD DECLARATION |
|---|
| [5068] | 17 | class Text; |
|---|
| 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 // |
|---|
| [5113] | 47 | void setBufferSize(unsigned int bufferSize) { this->bufferSize = bufferSize; }; |
|---|
| 48 | void setBufferDisplaySize(unsigned int bufferDisplaySize); |
|---|
| [5068] | 49 | void flushBuffers(); |
|---|
| [5075] | 50 | static bool addBufferLineStatic(const char* line, ...); |
|---|
| 51 | void addBufferLine(const char* line, va_list arg); |
|---|
| [5118] | 52 | void printToDisplayBuffer(const char* text); |
|---|
| [5068] | 53 | void moveBuffer(int lineCount); |
|---|
| 54 | const char* getBufferLine(unsigned int lineNumber); |
|---|
| [3245] | 55 | |
|---|
| [5069] | 56 | // InputLine |
|---|
| [5068] | 57 | void flushInputLine(); |
|---|
| 58 | void addCharacter(char character); |
|---|
| 59 | void addCharacters(const char* characters); |
|---|
| 60 | void removeCharacters(unsigned int characterCount = 1); |
|---|
| [5096] | 61 | bool executeCommand(); |
|---|
| [5068] | 62 | |
|---|
| [5130] | 63 | void clear(); |
|---|
| 64 | |
|---|
| [5097] | 65 | void setRepeatDelay(float repeatDelay, float repeatRate); |
|---|
| [5068] | 66 | |
|---|
| [5069] | 67 | // EventListener |
|---|
| 68 | virtual void process(const Event &event); |
|---|
| 69 | |
|---|
| [5068] | 70 | // Element2D-functions |
|---|
| [5095] | 71 | void tick(float dt); |
|---|
| [5068] | 72 | virtual void draw() const; |
|---|
| 73 | |
|---|
| [5119] | 74 | void help() const; |
|---|
| [5068] | 75 | void debug() const; |
|---|
| 76 | |
|---|
| 77 | private: |
|---|
| 78 | bool autoComplete(); |
|---|
| [5113] | 79 | bool classComplete(const char* classBegin); |
|---|
| 80 | bool objectComplete(const char* objectBegin, long classID); |
|---|
| 81 | bool functionComplete(const char* functionBegin); |
|---|
| [5068] | 82 | |
|---|
| [5113] | 83 | bool generalComplete(const tList<const char>* stringList, const char* begin, const char* displayAs = "%s", const char* addBack = NULL, const char* addFront = NULL); |
|---|
| [5068] | 84 | |
|---|
| [5129] | 85 | const tList<const char>* createCompleteList(const tList<const char>* inputList, const char* classNameBegin); |
|---|
| 86 | const tList<const char>* createCompleteList(const tList<BaseObject>* inputList, const char* classNameBegin); |
|---|
| [5113] | 87 | |
|---|
| [5120] | 88 | // helpers // |
|---|
| 89 | Vector calculateLinePosition(unsigned int lineNumber); |
|---|
| [5113] | 90 | |
|---|
| [5120] | 91 | |
|---|
| [5068] | 92 | private: |
|---|
| 93 | Shell(); |
|---|
| [5129] | 94 | static Shell* singletonRef; //!< The singleton-reference to the only memeber of this class. |
|---|
| [5068] | 95 | |
|---|
| [5129] | 96 | unsigned int bufferSize; //!< The Size of the buffer |
|---|
| 97 | unsigned int bufferDisplaySize; //!< The Size of the Display-buffer, in lines (not in characters) |
|---|
| [5068] | 98 | |
|---|
| [5129] | 99 | Text* inputLineText; //!< The inputLine of the Shell |
|---|
| 100 | char* inputLine; //!< the Char-Array of the Buffer |
|---|
| 101 | float repeatRate; //!< The Repeat-Delay. |
|---|
| 102 | float repeatDelay; //!< The delay of the first Character of a given Character. |
|---|
| 103 | float delayed; //!< how much of the delay is remaining. |
|---|
| 104 | int pressedKey; //!< the pressed key that will be repeated. |
|---|
| [5068] | 105 | |
|---|
| [5129] | 106 | tList<char>* buffer; //!< A list of stored char-arrays(strings) to store the history |
|---|
| 107 | tIterator<char>* bufferIterator; //!< An iterator for the Shells main buffer. |
|---|
| [5068] | 108 | |
|---|
| [5129] | 109 | tList<char>* inputHistory; //!< The history of given commands. |
|---|
| [5075] | 110 | |
|---|
| [5129] | 111 | Text** bufferText; //!< A list of stored bufferTexts for the display of the buffer |
|---|
| 112 | unsigned int textSize; //!< The size of the text. |
|---|
| 113 | unsigned int lineSpacing; //!< The Spacing between lines. |
|---|
| 114 | unsigned int shellHeight; //!< The hight of the Shell in Pixels |
|---|
| 115 | bool bActive; //!< if the shell is active; |
|---|
| [5113] | 116 | |
|---|
| [5129] | 117 | char bufferArray[SHELL_BUFFER_SIZE]; //!< a BUFFER for fast writing |
|---|
| 118 | char keepBufferArray[SHELL_BUFFER_SIZE]; //!< a BUFFER to have multi-non-newLine commands be copied into the shell. |
|---|
| 119 | bool keepBuffer; |
|---|
| 120 | |
|---|
| [5113] | 121 | // completion |
|---|
| [5129] | 122 | tList<const char>* completionList; //!< A list of completions, that are io. |
|---|
| [1853] | 123 | }; |
|---|
| 124 | |
|---|
| [5068] | 125 | #endif /* _SHELL_H */ |
|---|