Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/util/shell.h @ 5141

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

orxonox/trunk: moved helper-functions to helper-functions.cc

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