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 | */ |
---|
7 | |
---|
8 | #ifndef _SHELL_H |
---|
9 | #define _SHELL_H |
---|
10 | |
---|
11 | #include "element_2d.h" |
---|
12 | #include "event_listener.h" |
---|
13 | |
---|
14 | #include <stdarg.h> |
---|
15 | |
---|
16 | #define SHELL_DEFAULT_FONT "fonts/dpquake_.ttf" |
---|
17 | |
---|
18 | // FORWARD DECLARATION |
---|
19 | class Text; |
---|
20 | class ShellInput; |
---|
21 | template<class T> class tIterator; |
---|
22 | |
---|
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 check itself in to the Shell, and listen for commands. |
---|
32 | * |
---|
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 !! |
---|
40 | */ |
---|
41 | class Shell : public Element2D, public EventListener { |
---|
42 | |
---|
43 | public: |
---|
44 | Shell(); |
---|
45 | virtual ~Shell(); |
---|
46 | |
---|
47 | void activate(); |
---|
48 | void deactivate(); |
---|
49 | /** @returns true if the Shell is active, false otherwise. */ |
---|
50 | inline bool isActive() const { return this->bActive; }; |
---|
51 | |
---|
52 | void setFont(const char* fontFile); |
---|
53 | void setTextSize(unsigned int textSize, unsigned int lineSpacing = 1); |
---|
54 | void rebuildText(); |
---|
55 | |
---|
56 | // BUFFERS |
---|
57 | void setBufferDisplaySize(unsigned int bufferDisplaySize); |
---|
58 | void printToDisplayBuffer(const char* text); |
---|
59 | void moveDisplayBuffer(int lineCount); |
---|
60 | |
---|
61 | void flush(); |
---|
62 | |
---|
63 | void clear(); |
---|
64 | |
---|
65 | // EventListener |
---|
66 | virtual void process(const Event &event); |
---|
67 | // Element2D-functions |
---|
68 | virtual void draw() const; |
---|
69 | |
---|
70 | void debug() const; |
---|
71 | |
---|
72 | private: |
---|
73 | // helpers // |
---|
74 | Vector calculateLinePosition(unsigned int lineNumber); |
---|
75 | |
---|
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 | |
---|
82 | private: |
---|
83 | // GENERAL |
---|
84 | bool bActive; //!< If the shell is active. |
---|
85 | unsigned int shellHeight; //!< The hight of the Shell in Pixels. |
---|
86 | unsigned int lineSpacing; //!< The Spacing between lines. |
---|
87 | unsigned int textSize; //!< The size of the text. |
---|
88 | char* fontFile; //!< The file containing the font. |
---|
89 | |
---|
90 | // HANDLING TEXT INPUT |
---|
91 | ShellInput* shellInput; //!< The inputLine of the Shell. |
---|
92 | // BUFFER |
---|
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. |
---|
96 | tIterator<char>* bufferIterator; //!< used to move through and print the Buffer |
---|
97 | }; |
---|
98 | |
---|
99 | #endif /* _SHELL_H */ |
---|