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 | // FORWARD DECLARATION |
---|
15 | class Text; |
---|
16 | template<class T> class tList; |
---|
17 | |
---|
18 | //! A class that is able to redirect all output to a openGL-Shell, and that one can use to input some commands |
---|
19 | /** |
---|
20 | * the major idea is, that all the Output can be redirected to the Shell, |
---|
21 | * and does not have to be displayed to the opening Shell, this is good, |
---|
22 | * for developers using Windows, where all output is otherwise redirected |
---|
23 | * to stdout.txt |
---|
24 | * |
---|
25 | * Furthermore the Shell should enable us, to input some simple commands |
---|
26 | * Each Class can tell check itself in to the Shell, and listen for commands. |
---|
27 | * |
---|
28 | * @todo implement what is written above :/ |
---|
29 | */ |
---|
30 | class Shell : public Element2D, public EventListener { |
---|
31 | |
---|
32 | public: |
---|
33 | virtual ~Shell(); |
---|
34 | /** @returns a Pointer to the only object of this Class */ |
---|
35 | inline static Shell* getInstance() { if (!Shell::singletonRef) Shell::singletonRef = new Shell(); return Shell::singletonRef; }; |
---|
36 | |
---|
37 | |
---|
38 | void setBufferSize(unsigned int bufferSize) { this->bufferSize = bufferSize; }; |
---|
39 | |
---|
40 | void setBufferDisplaySize(unsigned int bufferDisplaySize); |
---|
41 | |
---|
42 | // BUFFER // |
---|
43 | void flushBuffers(); |
---|
44 | static bool addBufferLineStatic(const char* line, ...); |
---|
45 | void addBufferLine(const char* line, va_list arg); |
---|
46 | void moveBuffer(int lineCount); |
---|
47 | const char* getBufferLine(unsigned int lineNumber); |
---|
48 | |
---|
49 | // InputLine |
---|
50 | void flushInputLine(); |
---|
51 | void addCharacter(char character); |
---|
52 | void addCharacters(const char* characters); |
---|
53 | void removeCharacters(unsigned int characterCount = 1); |
---|
54 | bool executeCommand(); |
---|
55 | |
---|
56 | void setRepeatDelay(float repeatDelay, float repeatRate); |
---|
57 | |
---|
58 | // EventListener |
---|
59 | virtual void process(const Event &event); |
---|
60 | |
---|
61 | // Element2D-functions |
---|
62 | void tick(float dt); |
---|
63 | virtual void draw() const; |
---|
64 | |
---|
65 | void debug() const; |
---|
66 | |
---|
67 | private: |
---|
68 | bool autoComplete(); |
---|
69 | bool classComplete(const char* classBegin); |
---|
70 | bool objectComplete(const char* objectBegin, ClassID classID); |
---|
71 | bool functionComplete(const char* functionBegin); |
---|
72 | |
---|
73 | |
---|
74 | private: |
---|
75 | Shell(); |
---|
76 | static Shell* singletonRef; //!< The singleton-reference to the only memeber of this class. |
---|
77 | |
---|
78 | unsigned int bufferSize; //!< The Size of the buffer |
---|
79 | unsigned int bufferDisplaySize; //!< The Size of the Display-buffer, in lines (not in characters) |
---|
80 | |
---|
81 | Text* inputLineText; //!< The inputLine of the Shell |
---|
82 | char* inputLine; //!< the Char-Array of the Buffer |
---|
83 | float repeatRate; //!< The Repeat-Delay. |
---|
84 | float repeatDelay; //!< The delay of the first Character of a given Character. |
---|
85 | float delayed; //!< how much of the delay is remaining. |
---|
86 | int pressedKey; //!< the pressed key that will be repeated. |
---|
87 | |
---|
88 | tList<char>* buffer; //!< A list of stored char-arrays(strings) to store the history |
---|
89 | |
---|
90 | Text** bufferText; //!< A list of stored bufferTexts for the display of the buffer |
---|
91 | unsigned int textSize; //!< The size of the text. |
---|
92 | unsigned int lineSpacing; //!< The Spacing between lines. |
---|
93 | |
---|
94 | char bufferArray[10000]; //!< a BUFFER for fast writing |
---|
95 | }; |
---|
96 | |
---|
97 | #endif /* _SHELL_H */ |
---|