Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: added new Subdir for shell, and some minor changes

File size: 5.3 KB
RevLine 
[4838]1/*!
[5068]2 * @file shell.h
3 * Definition of a on-screen-shell
[3245]4*/
[1853]5
[5068]6#ifndef _SHELL_H
7#define _SHELL_H
[1853]8
[5068]9#include "element_2d.h"
[5069]10#include "event_listener.h"
[1853]11
[5068]12#include <stdarg.h>
13
[5127]14#define      SHELL_BUFFER_SIZE       16384         //!< The Size of the input-buffers (should be large enough to carry any kind of input)
15
[4838]16// FORWARD DECLARATION
[5068]17class Text;
[5141]18class ShellCommandBase;
[5068]19template<class T> class tList;
[5118]20template<class T> class tIterator;
[3543]21
[5068]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 */
[5069]34class Shell : public Element2D, public EventListener {
[3543]35
[5068]36  public:
37    virtual ~Shell();
38    /** @returns a Pointer to the only object of this Class */
[5072]39    inline static Shell* getInstance() { if (!Shell::singletonRef) Shell::singletonRef = new Shell();  return Shell::singletonRef; };
[2036]40
[5145]41    void testI (int i);
42    void testS (const char* s);
[5152]43    void testB (bool b);
44    void testF (float f);
[5154]45    void testSF (const char* s, float f);
[5145]46
[5113]47    void activate();
48    void deactivate();
[1853]49
[5113]50    void setTextSize(unsigned int textSize, unsigned int lineSpacing = 1);
51    void rebuildText();
[3245]52
[5068]53    // BUFFER //
[5113]54    void setBufferSize(unsigned int bufferSize) { this->bufferSize = bufferSize; };
55    void setBufferDisplaySize(unsigned int bufferDisplaySize);
[5068]56    void flushBuffers();
[5075]57    static bool addBufferLineStatic(const char* line, ...);
58    void addBufferLine(const char* line, va_list arg);
[5118]59    void printToDisplayBuffer(const char* text);
[5159]60    void moveBuffer(unsigned int lineCount);
61    void moveBufferTo(unsigned int lineNumber);
[5068]62    const char* getBufferLine(unsigned int lineNumber);
[3245]63
[5069]64    // InputLine
[5068]65    void flushInputLine();
66    void addCharacter(char character);
67    void addCharacters(const char* characters);
68    void removeCharacters(unsigned int characterCount = 1);
[5096]69    bool executeCommand();
[5068]70
[5130]71    void clear();
72
[5097]73    void setRepeatDelay(float repeatDelay, float repeatRate);
[5068]74
[5069]75    // EventListener
76    virtual void process(const Event &event);
77
[5068]78    // Element2D-functions
[5095]79    void tick(float dt);
[5068]80    virtual void draw() const;
81
[5119]82    void help() const;
[5068]83    void debug() const;
84
85  private:
86    bool autoComplete();
[5113]87    bool classComplete(const char* classBegin);
88    bool objectComplete(const char* objectBegin, long classID);
89    bool functionComplete(const char* functionBegin);
[5068]90
[5113]91    bool generalComplete(const tList<const char>* stringList, const char* begin, const char* displayAs = "%s", const char* addBack = NULL, const char* addFront = NULL);
[5068]92
[5129]93    const tList<const char>* createCompleteList(const tList<const char>* inputList, const char* classNameBegin);
94    const tList<const char>* createCompleteList(const tList<BaseObject>* inputList, const char* classNameBegin);
[5141]95    const tList<const char>* createCompleteList(const tList<ShellCommandBase>* inputList, const char* classNameBegin);
[5113]96
[5120]97    // helpers //
98    Vector calculateLinePosition(unsigned int lineNumber);
[5113]99
[5120]100
[5068]101  private:
102    Shell();
[5129]103    static Shell*            singletonRef;           //!< The singleton-reference to the only memeber of this class.
[5068]104
[5129]105    unsigned int             bufferSize;             //!< The Size of the buffer
106    unsigned int             bufferDisplaySize;      //!< The Size of the Display-buffer, in lines (not in characters)
[5068]107
[5129]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.
[5068]114
[5129]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.
[5068]117
[5129]118    tList<char>*             inputHistory;           //!< The history of given commands.
[5075]119
[5129]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;
[5113]125
[5129]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;
129
[5113]130    // completion
[5129]131    tList<const char>*       completionList;          //!< A list of completions, that are io.
[1853]132};
133
[5068]134#endif /* _SHELL_H */
Note: See TracBrowser for help on using the repository browser.