Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: ShellBuffer is extern to Shell now… (But NOT used in Shell yet)

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