[4838] | 1 | /*! |
---|
[5068] | 2 | * @file shell.h |
---|
| 3 | * Definition of a on-screen-shell |
---|
[5204] | 4 | * |
---|
[5208] | 5 | * @todo Buffer Display in different Colors for different debug mode. |
---|
[5204] | 6 | */ |
---|
[1853] | 7 | |
---|
[5068] | 8 | #ifndef _SHELL_H |
---|
| 9 | #define _SHELL_H |
---|
[1853] | 10 | |
---|
[5068] | 11 | #include "element_2d.h" |
---|
[5069] | 12 | #include "event_listener.h" |
---|
[1853] | 13 | |
---|
[5068] | 14 | #include <stdarg.h> |
---|
| 15 | |
---|
[5253] | 16 | #define SHELL_DEFAULT_FONT "fonts/dpquake_.ttf" |
---|
| 17 | |
---|
[4838] | 18 | // FORWARD DECLARATION |
---|
[5068] | 19 | class Text; |
---|
[5179] | 20 | class ShellInput; |
---|
[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 |
---|
[5246] | 31 | * Each Class can check itself in to the Shell, and listen for commands. |
---|
[5068] | 32 | * |
---|
[5246] | 33 | * more info: @see ShellCommand |
---|
| 34 | * @see shell_command.h |
---|
| 35 | * @see shell_buffer.h |
---|
| 36 | * @see shell_input.h |
---|
| 37 | * |
---|
| 38 | * !! note in order to keep shellbuffer to a minimal (it is included with |
---|
| 39 | * !! debug.h) Display of it inside the Shell is located here !! |
---|
[5068] | 40 | */ |
---|
[5069] | 41 | class Shell : public Element2D, public EventListener { |
---|
[3543] | 42 | |
---|
[5068] | 43 | public: |
---|
[5206] | 44 | Shell(); |
---|
[5068] | 45 | virtual ~Shell(); |
---|
[2036] | 46 | |
---|
[5113] | 47 | void activate(); |
---|
| 48 | void deactivate(); |
---|
[5197] | 49 | /** @returns true if the Shell is active, false otherwise. */ |
---|
[5176] | 50 | inline bool isActive() const { return this->bActive; }; |
---|
[1853] | 51 | |
---|
[5251] | 52 | void setFont(const char* fontFile); |
---|
[5113] | 53 | void setTextSize(unsigned int textSize, unsigned int lineSpacing = 1); |
---|
| 54 | void rebuildText(); |
---|
[3245] | 55 | |
---|
[5175] | 56 | // BUFFERS |
---|
[5113] | 57 | void setBufferDisplaySize(unsigned int bufferDisplaySize); |
---|
[5118] | 58 | void printToDisplayBuffer(const char* text); |
---|
[5246] | 59 | void moveDisplayBuffer(int lineCount); |
---|
| 60 | |
---|
[5183] | 61 | void flush(); |
---|
[3245] | 62 | |
---|
[5130] | 63 | void clear(); |
---|
| 64 | |
---|
[5069] | 65 | // EventListener |
---|
| 66 | virtual void process(const Event &event); |
---|
[5068] | 67 | // Element2D-functions |
---|
| 68 | virtual void draw() const; |
---|
| 69 | |
---|
| 70 | void debug() const; |
---|
| 71 | |
---|
| 72 | private: |
---|
[5120] | 73 | // helpers // |
---|
| 74 | Vector calculateLinePosition(unsigned int lineNumber); |
---|
[5113] | 75 | |
---|
[5183] | 76 | // void testI (int i); |
---|
| 77 | // void testS (const char* s); |
---|
| 78 | // void testB (bool b); |
---|
| 79 | // void testF (float f); |
---|
| 80 | // void testSF (const char* s, float f); |
---|
| 81 | |
---|
[5068] | 82 | private: |
---|
[5180] | 83 | // GENERAL |
---|
[5246] | 84 | bool bActive; //!< If the shell is active. |
---|
| 85 | unsigned int shellHeight; //!< The hight of the Shell in Pixels. |
---|
[5180] | 86 | unsigned int lineSpacing; //!< The Spacing between lines. |
---|
| 87 | unsigned int textSize; //!< The size of the text. |
---|
[5251] | 88 | char* fontFile; //!< The file containing the font. |
---|
[5068] | 89 | |
---|
[5175] | 90 | // HANDLING TEXT INPUT |
---|
[5197] | 91 | ShellInput* shellInput; //!< The inputLine of the Shell. |
---|
[5180] | 92 | // BUFFER |
---|
[5246] | 93 | unsigned int bufferDisplaySize; //!< The Size of the Display-buffer, in lines (not in characters). |
---|
| 94 | Text** bufferText; //!< A list of stored bufferTexts for the display of the buffer. |
---|
| 95 | int bufferOffset; //!< how many lines from the bottom up we display the Buffer. |
---|
[5247] | 96 | tIterator<char>* bufferIterator; //!< used to move through and print the Buffer |
---|
[1853] | 97 | }; |
---|
| 98 | |
---|
[5068] | 99 | #endif /* _SHELL_H */ |
---|