| 1 | /*! |
|---|
| 2 | * @file shell.h |
|---|
| 3 | * Definition of a on-screen-shell |
|---|
| 4 | * |
|---|
| 5 | * @todo Buffer Display in different Colors for different debug mode. |
|---|
| 6 | * @todo choose color of the Font and the background. |
|---|
| 7 | */ |
|---|
| 8 | |
|---|
| 9 | #ifndef _SHELL_H |
|---|
| 10 | #define _SHELL_H |
|---|
| 11 | |
|---|
| 12 | #include "element_2d.h" |
|---|
| 13 | #include "event_listener.h" |
|---|
| 14 | |
|---|
| 15 | #include <stdarg.h> |
|---|
| 16 | |
|---|
| 17 | #define SHELL_DEFAULT_FONT "fonts/dpquake_.ttf" |
|---|
| 18 | #define SHELL_DEFAULT_TEXT_COLOR 1.0f, 0.0f, 0.0f, 1.0f |
|---|
| 19 | #define SHELL_DEFAULT_BACKGROUND_COLOR 0.0f, 0.0f, 0.0f, 1.0f |
|---|
| 20 | |
|---|
| 21 | // FORWARD DECLARATION |
|---|
| 22 | class Text; |
|---|
| 23 | class ShellInput; |
|---|
| 24 | class Material; |
|---|
| 25 | |
|---|
| 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 |
|---|
| 34 | * Each Class can check itself in to the Shell, and listen for commands. |
|---|
| 35 | * |
|---|
| 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 !! |
|---|
| 43 | */ |
|---|
| 44 | class Shell : public Element2D, public EventListener { |
|---|
| 45 | |
|---|
| 46 | public: |
|---|
| 47 | Shell(); |
|---|
| 48 | virtual ~Shell(); |
|---|
| 49 | |
|---|
| 50 | void activate(); |
|---|
| 51 | void deactivate(); |
|---|
| 52 | /** @returns true if the Shell is active, false otherwise. */ |
|---|
| 53 | inline bool isActive() const { return this->bActive; }; |
|---|
| 54 | |
|---|
| 55 | void setFont(const char* fontFile); |
|---|
| 56 | void setTextSize(unsigned int textSize, unsigned int lineSpacing = 1); |
|---|
| 57 | void setTextColor(float r, float g, float b, float a); |
|---|
| 58 | void setBackgroundColor(float r, float g, float b, float a); |
|---|
| 59 | void setBackgroundImage(const char* fileName); |
|---|
| 60 | |
|---|
| 61 | void resetValues(); |
|---|
| 62 | void rebuildText(); |
|---|
| 63 | |
|---|
| 64 | // BUFFERS |
|---|
| 65 | void setBufferDisplaySize(unsigned int bufferDisplaySize); |
|---|
| 66 | void printToDisplayBuffer(const char* text); |
|---|
| 67 | void moveDisplayBuffer(int lineCount); |
|---|
| 68 | |
|---|
| 69 | void flush(); |
|---|
| 70 | |
|---|
| 71 | void clear(); |
|---|
| 72 | |
|---|
| 73 | // EventListener |
|---|
| 74 | virtual void process(const Event &event); |
|---|
| 75 | // Element2D-functions |
|---|
| 76 | virtual void draw() const; |
|---|
| 77 | |
|---|
| 78 | void debug() const; |
|---|
| 79 | |
|---|
| 80 | private: |
|---|
| 81 | // helpers // |
|---|
| 82 | Vector calculateLinePosition(unsigned int lineNumber); |
|---|
| 83 | |
|---|
| 84 | // void testI (int i); |
|---|
| 85 | // void testS (const char* s); |
|---|
| 86 | // void testB (bool b); |
|---|
| 87 | // void testF (float f); |
|---|
| 88 | // void testSF (const char* s, float f); |
|---|
| 89 | |
|---|
| 90 | private: |
|---|
| 91 | // GENERAL |
|---|
| 92 | bool bActive; //!< If the shell is active. |
|---|
| 93 | unsigned int shellHeight; //!< The hight of the Shell in Pixels. |
|---|
| 94 | unsigned int lineSpacing; //!< The Spacing between lines. |
|---|
| 95 | unsigned int textSize; //!< The size of the text. |
|---|
| 96 | float textColor[4]; //!< The text's color [r,g,b,a]. |
|---|
| 97 | char* fontFile; //!< The file containing the font. |
|---|
| 98 | Material* backgroundMaterial; //!< A material for the background. |
|---|
| 99 | |
|---|
| 100 | // HANDLING TEXT INPUT |
|---|
| 101 | ShellInput* shellInput; //!< The inputLine of the Shell. |
|---|
| 102 | // BUFFER |
|---|
| 103 | unsigned int bufferDisplaySize; //!< The Size of the Display-buffer, in lines (not in characters). |
|---|
| 104 | Text** bufferText; //!< A list of stored bufferTexts for the display of the buffer. |
|---|
| 105 | int bufferOffset; //!< how many lines from the bottom up we display the Buffer. |
|---|
| 106 | std::list<char*>::const_iterator bufferIterator; //!< used to move through and print the Buffer |
|---|
| 107 | }; |
|---|
| 108 | |
|---|
| 109 | #endif /* _SHELL_H */ |
|---|