[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. |
---|
[5372] | 6 | * @todo choose color of the Font and the background. |
---|
[5204] | 7 | */ |
---|
[1853] | 8 | |
---|
[5068] | 9 | #ifndef _SHELL_H |
---|
| 10 | #define _SHELL_H |
---|
[1853] | 11 | |
---|
[5068] | 12 | #include "element_2d.h" |
---|
[5069] | 13 | #include "event_listener.h" |
---|
[1853] | 14 | |
---|
[7341] | 15 | #include "shell_input.h" |
---|
[5068] | 16 | |
---|
[5372] | 17 | #define SHELL_DEFAULT_FONT "fonts/dpquake_.ttf" |
---|
[5374] | 18 | #define SHELL_DEFAULT_TEXT_COLOR 1.0f, 0.0f, 0.0f, 1.0f |
---|
[5513] | 19 | #define SHELL_DEFAULT_BACKGROUND_COLOR 0.0f, 0.0f, 0.0f, 1.0f |
---|
[5253] | 20 | |
---|
[4838] | 21 | // FORWARD DECLARATION |
---|
[5068] | 22 | class Text; |
---|
[5179] | 23 | class ShellInput; |
---|
[5372] | 24 | class Material; |
---|
[3543] | 25 | |
---|
[5068] | 26 | //! A class that is able to redirect all output to a openGL-Shell, and that one can use to input some commands |
---|
| 27 | /** |
---|
| 28 | * the major idea is, that all the Output can be redirected to the Shell, |
---|
| 29 | * and does not have to be displayed to the opening Shell, this is good, |
---|
| 30 | * for developers using Windows, where all output is otherwise redirected |
---|
| 31 | * to stdout.txt |
---|
| 32 | * |
---|
| 33 | * Furthermore the Shell should enable us, to input some simple commands |
---|
[5246] | 34 | * Each Class can check itself in to the Shell, and listen for commands. |
---|
[5068] | 35 | * |
---|
[5246] | 36 | * more info: @see ShellCommand |
---|
| 37 | * @see shell_command.h |
---|
| 38 | * @see shell_buffer.h |
---|
| 39 | * @see shell_input.h |
---|
| 40 | * |
---|
| 41 | * !! note in order to keep shellbuffer to a minimal (it is included with |
---|
| 42 | * !! debug.h) Display of it inside the Shell is located here !! |
---|
[5068] | 43 | */ |
---|
[5069] | 44 | class Shell : public Element2D, public EventListener { |
---|
[3543] | 45 | |
---|
[5068] | 46 | public: |
---|
[5206] | 47 | Shell(); |
---|
[5068] | 48 | virtual ~Shell(); |
---|
[2036] | 49 | |
---|
[5113] | 50 | void activate(); |
---|
| 51 | void deactivate(); |
---|
[5197] | 52 | /** @returns true if the Shell is active, false otherwise. */ |
---|
[5176] | 53 | inline bool isActive() const { return this->bActive; }; |
---|
[1853] | 54 | |
---|
[7221] | 55 | void setFont(const std::string& fontFile); |
---|
[5113] | 56 | void setTextSize(unsigned int textSize, unsigned int lineSpacing = 1); |
---|
[5372] | 57 | void setTextColor(float r, float g, float b, float a); |
---|
| 58 | void setBackgroundColor(float r, float g, float b, float a); |
---|
[7221] | 59 | void setBackgroundImage(const std::string& fileName); |
---|
[5372] | 60 | |
---|
| 61 | void resetValues(); |
---|
[3245] | 62 | |
---|
[5175] | 63 | // BUFFERS |
---|
[5113] | 64 | void setBufferDisplaySize(unsigned int bufferDisplaySize); |
---|
[7221] | 65 | void printToDisplayBuffer(const std::string& text); |
---|
[5246] | 66 | void moveDisplayBuffer(int lineCount); |
---|
| 67 | |
---|
[5183] | 68 | void flush(); |
---|
[3245] | 69 | |
---|
[5130] | 70 | void clear(); |
---|
| 71 | |
---|
[5069] | 72 | // EventListener |
---|
| 73 | virtual void process(const Event &event); |
---|
[5068] | 74 | // Element2D-functions |
---|
| 75 | virtual void draw() const; |
---|
| 76 | |
---|
| 77 | void debug() const; |
---|
| 78 | |
---|
| 79 | private: |
---|
[5120] | 80 | // helpers // |
---|
[7316] | 81 | Vector2D calculateLinePosition(unsigned int lineNumber); |
---|
[5113] | 82 | |
---|
[5183] | 83 | // void testI (int i); |
---|
[7221] | 84 | // void testS (const std::string& s); |
---|
[5183] | 85 | // void testB (bool b); |
---|
| 86 | // void testF (float f); |
---|
[7221] | 87 | // void testSF (const std::string& s, float f); |
---|
[5183] | 88 | |
---|
[5068] | 89 | private: |
---|
[5180] | 90 | // GENERAL |
---|
[5781] | 91 | bool bActive; //!< If the shell is active. |
---|
| 92 | unsigned int shellHeight; //!< The hight of the Shell in Pixels. |
---|
| 93 | unsigned int lineSpacing; //!< The Spacing between lines. |
---|
| 94 | unsigned int textSize; //!< The size of the text. |
---|
| 95 | float textColor[4]; //!< The text's color [r,g,b,a]. |
---|
[7221] | 96 | std::string fontFile; //!< The file containing the font. |
---|
[5781] | 97 | Material* backgroundMaterial; //!< A material for the background. |
---|
[5068] | 98 | |
---|
[5175] | 99 | // HANDLING TEXT INPUT |
---|
[7341] | 100 | ShellInput shellInput; //!< The inputLine of the Shell. |
---|
[5180] | 101 | // BUFFER |
---|
[5781] | 102 | unsigned int bufferDisplaySize; //!< The Size of the Display-buffer, in lines (not in characters). |
---|
[7341] | 103 | std::list<Text*> bufferText; //!< A list of stored bufferTexts for the display of the buffer. |
---|
[5781] | 104 | int bufferOffset; //!< how many lines from the bottom up we display the Buffer. |
---|
[7315] | 105 | std::list<std::string>::const_iterator bufferIterator; //!< used to move through and print the Buffer |
---|
[1853] | 106 | }; |
---|
| 107 | |
---|
[5068] | 108 | #endif /* _SHELL_H */ |
---|