| [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 | |
|---|
| [4838] | 14 | // FORWARD DECLARATION |
|---|
| [5068] | 15 | class Text; |
|---|
| 16 | template<class T> class tList; |
|---|
| [5118] | 17 | template<class T> class tIterator; |
|---|
| [3543] | 18 | |
|---|
| [5068] | 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 | */ |
|---|
| [5069] | 31 | class Shell : public Element2D, public EventListener { |
|---|
| [3543] | 32 | |
|---|
| [5068] | 33 | public: |
|---|
| 34 | virtual ~Shell(); |
|---|
| 35 | /** @returns a Pointer to the only object of this Class */ |
|---|
| [5072] | 36 | inline static Shell* getInstance() { if (!Shell::singletonRef) Shell::singletonRef = new Shell(); return Shell::singletonRef; }; |
|---|
| [2036] | 37 | |
|---|
| [1853] | 38 | |
|---|
| [5113] | 39 | void activate(); |
|---|
| 40 | void deactivate(); |
|---|
| [1853] | 41 | |
|---|
| [5113] | 42 | void setTextSize(unsigned int textSize, unsigned int lineSpacing = 1); |
|---|
| 43 | void rebuildText(); |
|---|
| [3245] | 44 | |
|---|
| [5068] | 45 | // BUFFER // |
|---|
| [5113] | 46 | void setBufferSize(unsigned int bufferSize) { this->bufferSize = bufferSize; }; |
|---|
| 47 | void setBufferDisplaySize(unsigned int bufferDisplaySize); |
|---|
| [5068] | 48 | void flushBuffers(); |
|---|
| [5075] | 49 | static bool addBufferLineStatic(const char* line, ...); |
|---|
| 50 | void addBufferLine(const char* line, va_list arg); |
|---|
| [5118] | 51 | void printToDisplayBuffer(const char* text); |
|---|
| [5068] | 52 | void moveBuffer(int lineCount); |
|---|
| 53 | const char* getBufferLine(unsigned int lineNumber); |
|---|
| [3245] | 54 | |
|---|
| [5069] | 55 | // InputLine |
|---|
| [5068] | 56 | void flushInputLine(); |
|---|
| 57 | void addCharacter(char character); |
|---|
| 58 | void addCharacters(const char* characters); |
|---|
| 59 | void removeCharacters(unsigned int characterCount = 1); |
|---|
| [5096] | 60 | bool executeCommand(); |
|---|
| [5068] | 61 | |
|---|
| [5097] | 62 | void setRepeatDelay(float repeatDelay, float repeatRate); |
|---|
| [5068] | 63 | |
|---|
| [5069] | 64 | // EventListener |
|---|
| 65 | virtual void process(const Event &event); |
|---|
| 66 | |
|---|
| [5068] | 67 | // Element2D-functions |
|---|
| [5095] | 68 | void tick(float dt); |
|---|
| [5068] | 69 | virtual void draw() const; |
|---|
| 70 | |
|---|
| [5119] | 71 | void help() const; |
|---|
| [5068] | 72 | void debug() const; |
|---|
| 73 | |
|---|
| 74 | private: |
|---|
| 75 | bool autoComplete(); |
|---|
| [5113] | 76 | bool classComplete(const char* classBegin); |
|---|
| 77 | bool objectComplete(const char* objectBegin, long classID); |
|---|
| 78 | bool functionComplete(const char* functionBegin); |
|---|
| [5068] | 79 | |
|---|
| [5113] | 80 | bool generalComplete(const tList<const char>* stringList, const char* begin, const char* displayAs = "%s", const char* addBack = NULL, const char* addFront = NULL); |
|---|
| [5068] | 81 | |
|---|
| [5113] | 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 | |
|---|
| [5120] | 85 | // helpers // |
|---|
| 86 | Vector calculateLinePosition(unsigned int lineNumber); |
|---|
| [5113] | 87 | |
|---|
| [5120] | 88 | |
|---|
| [5068] | 89 | private: |
|---|
| 90 | Shell(); |
|---|
| [5072] | 91 | static Shell* singletonRef; //!< The singleton-reference to the only memeber of this class. |
|---|
| [5068] | 92 | |
|---|
| [5072] | 93 | unsigned int bufferSize; //!< The Size of the buffer |
|---|
| 94 | unsigned int bufferDisplaySize; //!< The Size of the Display-buffer, in lines (not in characters) |
|---|
| [5068] | 95 | |
|---|
| [5095] | 96 | Text* inputLineText; //!< The inputLine of the Shell |
|---|
| [5072] | 97 | char* inputLine; //!< the Char-Array of the Buffer |
|---|
| [5097] | 98 | float repeatRate; //!< The Repeat-Delay. |
|---|
| 99 | float repeatDelay; //!< The delay of the first Character of a given Character. |
|---|
| [5095] | 100 | float delayed; //!< how much of the delay is remaining. |
|---|
| 101 | int pressedKey; //!< the pressed key that will be repeated. |
|---|
| [5068] | 102 | |
|---|
| [5072] | 103 | tList<char>* buffer; //!< A list of stored char-arrays(strings) to store the history |
|---|
| [5118] | 104 | tIterator<char>* bufferIterator; //!< An iterator for the Shells main buffer. |
|---|
| [5068] | 105 | |
|---|
| [5080] | 106 | Text** bufferText; //!< A list of stored bufferTexts for the display of the buffer |
|---|
| 107 | unsigned int textSize; //!< The size of the text. |
|---|
| 108 | unsigned int lineSpacing; //!< The Spacing between lines. |
|---|
| [5113] | 109 | unsigned int shellHeight; //!< The hight of the Shell in Pixels |
|---|
| 110 | bool bActive; //!< if the shell is active; |
|---|
| [5075] | 111 | |
|---|
| 112 | char bufferArray[10000]; //!< a BUFFER for fast writing |
|---|
| [5113] | 113 | |
|---|
| 114 | // completion |
|---|
| 115 | tList<const char>* completionList; //!< A list of completions, that are io. |
|---|
| [1853] | 116 | }; |
|---|
| 117 | |
|---|
| [5068] | 118 | #endif /* _SHELL_H */ |
|---|