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