Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/shell/shell.h @ 5173

Last change on this file since 5173 was 5173, checked in by bensch, 19 years ago

orxonox/trunk: added new Class ShellBuffer, that only handles the main shell's buffer

File size: 5.3 KB
Line 
1/*!
2 * @file shell.h
3 * Definition of a on-screen-shell
4*/
5
6#ifndef _SHELL_H
7#define _SHELL_H
8
9#include "element_2d.h"
10#include "event_listener.h"
11#include "shell_buffer.h"
12
13#include <stdarg.h>
14
15// FORWARD DECLARATION
16class Text;
17class ShellCommandBase;
18template<class T> class tList;
19template<class T> class tIterator;
20
21//! A class that is able to redirect all output to a openGL-Shell, and that one can use to input some commands
22/**
23 * the major idea is, that all the Output can be redirected to the Shell,
24 * and does not have to be displayed to the opening Shell, this is good,
25 * for developers using Windows, where all output is otherwise redirected
26 * to stdout.txt
27 *
28 * Furthermore the Shell should enable us, to input some simple commands
29 * Each Class can tell check itself in to the Shell, and listen for commands.
30 *
31 * @todo implement what is written above :/
32 */
33class Shell : public Element2D, public EventListener {
34
35  public:
36    virtual ~Shell();
37    /** @returns a Pointer to the only object of this Class */
38    inline static Shell* getInstance() { if (!Shell::singletonRef) Shell::singletonRef = new Shell();  return Shell::singletonRef; };
39
40    void activate();
41    void deactivate();
42
43    void setTextSize(unsigned int textSize, unsigned int lineSpacing = 1);
44    void rebuildText();
45
46    // BUFFER //
47    /** @param bufferSize the new Buffer-Size */
48    void setBufferSize(unsigned int bufferSize) { this->bufferSize = bufferSize; };
49    void setBufferDisplaySize(unsigned int bufferDisplaySize);
50    void flushBuffers();
51    static bool addBufferLineStatic(const char* line, ...);
52    void addBufferLine(const char* line, va_list arg);
53    void printToDisplayBuffer(const char* text);
54    void moveBuffer(unsigned int lineCount);
55//    void moveBufferTo(unsigned int lineNumber);
56    const char* getBufferLine(unsigned int lineNumber);
57
58    // InputLine
59    void flushInputLine();
60    void addCharacter(char character);
61    void addCharacters(const char* characters);
62    void removeCharacters(unsigned int characterCount = 1);
63    bool executeCommand();
64
65    void clear();
66
67    void setRepeatDelay(float repeatDelay, float repeatRate);
68
69    // EventListener
70    virtual void process(const Event &event);
71
72    // Element2D-functions
73    void tick(float dt);
74    virtual void draw() const;
75
76    void help() const;
77    void debug() const;
78
79  private:
80    bool autoComplete();
81    bool classComplete(const char* classBegin);
82    bool objectComplete(const char* objectBegin, long classID);
83    bool functionComplete(const char* functionBegin);
84
85    bool generalComplete(const tList<const char>* stringList, const char* begin, const char* displayAs = "%s", const char* addBack = NULL, const char* addFront = NULL);
86
87    const tList<const char>* createCompleteList(const tList<const char>* inputList, const char* classNameBegin);
88    const tList<const char>* createCompleteList(const tList<BaseObject>* inputList, const char* classNameBegin);
89//    const tList<const char>* createCompleteList(const tList<ShellCommandBase>* inputList, const char* classNameBegin);
90
91    // helpers //
92    Vector calculateLinePosition(unsigned int lineNumber);
93//     void testI (int i);
94//     void testS (const char* s);
95//     void testB (bool b);
96//     void testF (float f);
97//     void testSF (const char* s, float f);
98
99  private:
100    Shell();
101    static Shell*            singletonRef;           //!< The singleton-reference to the only memeber of this class.
102
103    unsigned int             bufferSize;             //!< The Size of the buffer
104    unsigned int             bufferDisplaySize;      //!< The Size of the Display-buffer, in lines (not in characters)
105
106    Text*                    inputLineText;          //!< The inputLine of the Shell
107    char*                    inputLine;              //!< the Char-Array of the Buffer
108    float                    repeatRate;             //!< The Repeat-Delay.
109    float                    repeatDelay;            //!< The delay of the first Character of a given Character.
110    float                    delayed;                //!< how much of the delay is remaining.
111    int                      pressedKey;             //!< the pressed key that will be repeated.
112
113    tList<char>*             buffer;                 //!< A list of stored char-arrays(strings) to store the history
114    tIterator<char>*         bufferIterator;         //!< An iterator for the Shells main buffer.
115
116    tList<char>*             inputHistory;           //!< The history of given commands.
117
118    Text**                   bufferText;             //!< A list of stored bufferTexts for the display of the buffer
119    unsigned int             textSize;               //!< The size of the text.
120    unsigned int             lineSpacing;            //!< The Spacing between lines.
121    unsigned int             shellHeight;            //!< The hight of the Shell in Pixels
122    bool                     bActive;                //!< if the shell is active;
123
124    char                     bufferArray[SHELL_BUFFER_SIZE];     //!< a BUFFER for fast writing
125    char                     keepBufferArray[SHELL_BUFFER_SIZE]; //!< a BUFFER to have multi-non-newLine commands be copied into the shell.
126    bool                     keepBuffer;             //!< if the keepbuffer contains unfinished lines.
127
128    // completion
129    tList<const char>*       completionList;          //!< A list of completions, that are io.
130};
131
132#endif /* _SHELL_H */
Note: See TracBrowser for help on using the repository browser.