[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" |
---|
[5174] | 11 | //#include "shell_buffer.h" |
---|
[1853] | 12 | |
---|
[5068] | 13 | #include <stdarg.h> |
---|
| 14 | |
---|
[5174] | 15 | #define SHELL_BUFFER_SIZE 16384 |
---|
| 16 | |
---|
[4838] | 17 | // FORWARD DECLARATION |
---|
[5068] | 18 | class Text; |
---|
[5141] | 19 | class ShellCommandBase; |
---|
[5068] | 20 | template<class T> class tList; |
---|
[5118] | 21 | template<class T> class tIterator; |
---|
[3543] | 22 | |
---|
[5068] | 23 | //! A class that is able to redirect all output to a openGL-Shell, and that one can use to input some commands |
---|
| 24 | /** |
---|
| 25 | * the major idea is, that all the Output can be redirected to the Shell, |
---|
| 26 | * and does not have to be displayed to the opening Shell, this is good, |
---|
| 27 | * for developers using Windows, where all output is otherwise redirected |
---|
| 28 | * to stdout.txt |
---|
| 29 | * |
---|
| 30 | * Furthermore the Shell should enable us, to input some simple commands |
---|
| 31 | * Each Class can tell check itself in to the Shell, and listen for commands. |
---|
| 32 | * |
---|
| 33 | * @todo implement what is written above :/ |
---|
| 34 | */ |
---|
[5069] | 35 | class Shell : public Element2D, public EventListener { |
---|
[3543] | 36 | |
---|
[5068] | 37 | public: |
---|
| 38 | virtual ~Shell(); |
---|
| 39 | /** @returns a Pointer to the only object of this Class */ |
---|
[5072] | 40 | inline static Shell* getInstance() { if (!Shell::singletonRef) Shell::singletonRef = new Shell(); return Shell::singletonRef; }; |
---|
[5175] | 41 | /** @returns true if this class is instanciated, false otherwise */ |
---|
| 42 | inline static bool isInstanciated() { return (Shell::singletonRef == NULL)?true:false; }; |
---|
[2036] | 43 | |
---|
[5113] | 44 | void activate(); |
---|
| 45 | void deactivate(); |
---|
[1853] | 46 | |
---|
[5113] | 47 | void setTextSize(unsigned int textSize, unsigned int lineSpacing = 1); |
---|
| 48 | void rebuildText(); |
---|
[3245] | 49 | |
---|
[5175] | 50 | // BUFFERS |
---|
[5113] | 51 | void setBufferDisplaySize(unsigned int bufferDisplaySize); |
---|
[5175] | 52 | void flush(); |
---|
[5118] | 53 | void printToDisplayBuffer(const char* text); |
---|
[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 | |
---|
[5130] | 62 | void clear(); |
---|
| 63 | |
---|
[5097] | 64 | void setRepeatDelay(float repeatDelay, float repeatRate); |
---|
[5068] | 65 | |
---|
[5069] | 66 | // EventListener |
---|
| 67 | virtual void process(const Event &event); |
---|
| 68 | |
---|
[5068] | 69 | // Element2D-functions |
---|
[5095] | 70 | void tick(float dt); |
---|
[5068] | 71 | virtual void draw() const; |
---|
| 72 | |
---|
[5119] | 73 | void help() const; |
---|
[5068] | 74 | void debug() const; |
---|
| 75 | |
---|
| 76 | private: |
---|
| 77 | bool autoComplete(); |
---|
[5113] | 78 | bool classComplete(const char* classBegin); |
---|
| 79 | bool objectComplete(const char* objectBegin, long classID); |
---|
| 80 | bool functionComplete(const char* functionBegin); |
---|
[5068] | 81 | |
---|
[5113] | 82 | bool generalComplete(const tList<const char>* stringList, const char* begin, const char* displayAs = "%s", const char* addBack = NULL, const char* addFront = NULL); |
---|
[5068] | 83 | |
---|
[5129] | 84 | const tList<const char>* createCompleteList(const tList<const char>* inputList, const char* classNameBegin); |
---|
| 85 | const tList<const char>* createCompleteList(const tList<BaseObject>* inputList, const char* classNameBegin); |
---|
[5166] | 86 | // const tList<const char>* createCompleteList(const tList<ShellCommandBase>* inputList, const char* classNameBegin); |
---|
[5113] | 87 | |
---|
[5120] | 88 | // helpers // |
---|
| 89 | Vector calculateLinePosition(unsigned int lineNumber); |
---|
[5166] | 90 | // void testI (int i); |
---|
| 91 | // void testS (const char* s); |
---|
| 92 | // void testB (bool b); |
---|
| 93 | // void testF (float f); |
---|
| 94 | // void testSF (const char* s, float f); |
---|
[5113] | 95 | |
---|
[5068] | 96 | private: |
---|
| 97 | Shell(); |
---|
[5129] | 98 | static Shell* singletonRef; //!< The singleton-reference to the only memeber of this class. |
---|
[5068] | 99 | |
---|
[5129] | 100 | unsigned int bufferDisplaySize; //!< The Size of the Display-buffer, in lines (not in characters) |
---|
[5068] | 101 | |
---|
[5175] | 102 | // HANDLING TEXT INPUT |
---|
[5129] | 103 | Text* inputLineText; //!< The inputLine of the Shell |
---|
| 104 | char* inputLine; //!< the Char-Array of the Buffer |
---|
| 105 | float repeatRate; //!< The Repeat-Delay. |
---|
| 106 | float repeatDelay; //!< The delay of the first Character of a given Character. |
---|
| 107 | float delayed; //!< how much of the delay is remaining. |
---|
| 108 | int pressedKey; //!< the pressed key that will be repeated. |
---|
[5068] | 109 | |
---|
[5129] | 110 | tList<char>* inputHistory; //!< The history of given commands. |
---|
[5075] | 111 | |
---|
[5129] | 112 | Text** bufferText; //!< A list of stored bufferTexts for the display of the buffer |
---|
| 113 | unsigned int textSize; //!< The size of the text. |
---|
| 114 | unsigned int lineSpacing; //!< The Spacing between lines. |
---|
| 115 | unsigned int shellHeight; //!< The hight of the Shell in Pixels |
---|
| 116 | bool bActive; //!< if the shell is active; |
---|
[5113] | 117 | |
---|
| 118 | // completion |
---|
[5129] | 119 | tList<const char>* completionList; //!< A list of completions, that are io. |
---|
[1853] | 120 | }; |
---|
| 121 | |
---|
[5068] | 122 | #endif /* _SHELL_H */ |
---|