Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: added class ShellInput for the InputLine, also worked a bit on ShellCompletion

File size: 4.5 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// FORWARD DECLARATION
15class Text;
16class ShellCommandBase;
17template<class T> class tList;
18template<class T> class tIterator;
19
20//! A class that is able to redirect all output to a openGL-Shell, and that one can use to input some commands
21/**
22 * the major idea is, that all the Output can be redirected to the Shell,
23 * and does not have to be displayed to the opening Shell, this is good,
24 * for developers using Windows, where all output is otherwise redirected
25 * to stdout.txt
26 *
27 * Furthermore the Shell should enable us, to input some simple commands
28 * Each Class can tell check itself in to the Shell, and listen for commands.
29 *
30 * @todo implement what is written above :/
31 */
32class Shell : public Element2D, public EventListener {
33
34  public:
35    virtual ~Shell();
36    /** @returns a Pointer to the only object of this Class */
37    inline static Shell* getInstance() { if (!Shell::singletonRef) Shell::singletonRef = new Shell();  return Shell::singletonRef; };
38    /** @returns true if this class is instanciated, false otherwise */
39    inline static bool isInstanciated() { return (Shell::singletonRef == NULL)?false:true; };
40
41    void activate();
42    void deactivate();
43    inline bool isActive() const { return this->bActive; };
44
45    void setTextSize(unsigned int textSize, unsigned int lineSpacing = 1);
46    void rebuildText();
47
48    // BUFFERS
49    void flush();
50    void setBufferDisplaySize(unsigned int bufferDisplaySize);
51    void printToDisplayBuffer(const char* text);
52
53    // InputLine
54    void flushInputLine();
55    void addCharacter(char character);
56    void addCharacters(const char* characters);
57    void removeCharacters(unsigned int characterCount = 1);
58    void setRepeatDelay(float repeatDelay, float repeatRate);
59    bool executeCommand();
60
61    void clear();
62
63
64    // EventListener
65    virtual void process(const Event &event);
66
67    // Element2D-functions
68    void tick(float dt);
69    virtual void draw() const;
70
71    void help() const;
72    void debug() const;
73
74  private:
75    bool autoComplete();
76    bool classComplete(const char* classBegin);
77    bool objectComplete(const char* objectBegin, long classID);
78    bool functionComplete(const char* functionBegin);
79
80    bool generalComplete(const tList<const char>* stringList, const char* begin, const char* displayAs = "%s", const char* addBack = NULL, const char* addFront = NULL);
81
82    const tList<const char>* createCompleteList(const tList<const char>* inputList, const char* classNameBegin);
83    const tList<const char>* createCompleteList(const tList<BaseObject>* inputList, const char* classNameBegin);
84//    const tList<const char>* createCompleteList(const tList<ShellCommandBase>* inputList, const char* classNameBegin);
85
86    // helpers //
87    Vector calculateLinePosition(unsigned int lineNumber);
88//     void testI (int i);
89//     void testS (const char* s);
90//     void testB (bool b);
91//     void testF (float f);
92//     void testSF (const char* s, float f);
93
94  private:
95    Shell();
96    static Shell*            singletonRef;           //!< The singleton-reference to the only memeber of this class.
97
98    unsigned int             bufferDisplaySize;      //!< The Size of the Display-buffer, in lines (not in characters)
99
100    // HANDLING TEXT INPUT
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>*             inputHistory;           //!< The history of given commands.
109
110    Text**                   bufferText;             //!< A list of stored bufferTexts for the display of the buffer
111    unsigned int             textSize;               //!< The size of the text.
112    unsigned int             lineSpacing;            //!< The Spacing between lines.
113    unsigned int             shellHeight;            //!< The hight of the Shell in Pixels
114    bool                     bActive;                //!< if the shell is active;
115
116    // completion
117    tList<const char>*       completionList;          //!< A list of completions, that are io.
118};
119
120#endif /* _SHELL_H */
Note: See TracBrowser for help on using the repository browser.