Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

CUI_Console.h

Go to the documentation of this file.
00001 
00015 #ifndef CUI_CONSOLE_H
00016 #define CUI_CONSOLE_H
00017 
00018 #include <string>
00019 #include <map>
00020 
00021 #include "UI_Lib.h"
00022 #include "UI_types.h"
00023 #include "CUI_Control.h"
00024 #include "CUI_TextField.h"
00025 #include "CUI_ScrollableTextBox.h"
00026 
00027 class CUI_ConsoleVar;
00028 class CUI_ConsoleFun;
00029 
00031 
00054 class GLGUI_ENTRY CUI_Console : public CUI_Control
00055 {
00056 public:
00058         typedef bool (cfun)( CUI_Console *con, const char *param );
00059 
00061         typedef enum cvartype_t { UI_TYPE_INT, UI_TYPE_UINT, UI_TYPE_FLOAT, UI_TYPE_STRING };
00062 
00064         CUI_Console(  CUI_UI *ui = NULL, float x = 0, float y = 0, float x2 = 1, float y2 = 1,
00065                                 CUI_Frame *parent = NULL, IUI_Shader *shader = NULL,
00066                                 IUI_Shader *cursor = NULL, CUI_CoordSys *coordsys = NULL,
00067                                 // control
00068                                 // console
00069                                 unsigned int m_historyLength = 30, const char *prompt = "%" );
00070 
00072         virtual ~CUI_Console();
00073 
00075         virtual bool SetUI( CUI_UI *ui );
00076 
00078 
00079         virtual bool ProcessKey( unsigned long key );
00080 
00081         // Catch commands from the text field
00082         virtual bool CallbackFunc( int id, int numparam, void *param );
00083 
00085         virtual bool AddCvar( const char *name, cvartype_t type, void *data );
00086 
00088         virtual bool AddCfun( const char *name, cfun *function );
00089 
00091         virtual bool DeleteCfun( const char *name );
00092 
00094 
00095         virtual bool Exec( char *name, char *param );
00096 
00098         virtual bool ExecLine( const char *line );
00099 
00101         virtual bool ExecFun( CUI_ConsoleFun *cfun, char *param );
00102 
00104         virtual bool ExecAlias( const char *param );
00105 
00107 
00110         virtual bool ExecBuffer( char *buffer );
00111 
00113 
00117         virtual bool Complete();
00118 
00120         virtual bool SetPrompt( const char *prompt );
00121 
00122 
00125 
00126         virtual bool Echo( const char *string );
00127         
00129         virtual bool PrintCvarList( );
00130 
00132         virtual bool PrintCfunList( );
00133 
00135 
00138         virtual bool Alias( const char *name, const char *string );
00140 
00142         virtual CUI_TextField * GetTextField( )
00143         { return m_textField; }
00144 
00146         virtual bool SetHistoryLength( unsigned int length )
00147         { m_historyLength = length; return false; }
00148 
00150         virtual bool SetFieldWidth( unsigned short width )
00151         { return m_textField->SetWidth(width); }
00152 
00154         virtual bool SetFont( IUI_Font *font )
00155         { m_textField->SetFont(font); return m_textBox->SetFont(font); }
00156 
00158         virtual bool SetScrollShader( IUI_Shader *shader )
00159         { return m_textBox->SetScrollShader(shader); }
00160 
00162         virtual bool SetSliderShader( IUI_Shader *shader )
00163         { return m_textBox->SetSliderShader(shader); }
00164 
00166         virtual bool SetTextBoxSize( int columns, int rows )
00167         { return m_textBox->SetTextBoxSize( columns, rows ); }
00168 
00170         virtual bool SetWordWrap( bool wordwrap )
00171         { return m_textBox->SetWordWrap( wordwrap ); }
00172 
00174         virtual bool SetFieldHeight( float height )
00175         { m_textBox->Move( 0.0, height, 1.0, 1.0 ); return m_textField->Move( 0.0, 0.0, 1.0, height ); }
00176 
00178         virtual bool CatText( const char *text )
00179         { return m_textBox->CatText( text ); }
00180 
00181 protected:
00182 
00184         CUI_TextField *m_textField;
00185 
00187         CUI_ScrollableTextBox *m_textBox;
00188         
00190 
00191         char *m_prompt;
00192 
00194         unsigned m_promptLength;
00195         
00197         unsigned int m_historyLength;
00198 
00200         typedef std::map<std::string, CUI_ConsoleVar*, std::less<std::string> > CVARMAP;
00201 
00203         CVARMAP m_cvarMap;
00204         
00206         typedef std::map<std::string, CUI_ConsoleFun*, std::less<std::string> > CFUNMAP;
00207 
00209         CFUNMAP m_cfunMap;
00210 
00212         typedef std::map<std::string, std::string, std::less<std::string> > CALIASMAP;
00213 
00215         CALIASMAP m_caliasMap;
00216 
00218         typedef std::list<std::string> HISTORYLIST;
00219 
00221         HISTORYLIST m_historyList;
00222 
00224 
00226         unsigned int m_historyPosition;
00227 
00228 };
00229 
00231 
00237 class CUI_ConsoleVar
00238 {
00239 public:
00241         CUI_ConsoleVar( const char * name, CUI_Console::cvartype_t type, void *data );
00242 
00244         ~CUI_ConsoleVar();
00245 
00247         bool SetValue( char *val );
00248 
00250         char *GetValue( );
00251 
00252 protected:
00254         std::string m_name;
00255 
00257 
00258         CUI_Console::cvartype_t m_type;
00259 
00261         void *m_data;
00262 
00263 };
00264 
00266 
00269 class CUI_ConsoleFun
00270 {
00271 public:
00272         CUI_ConsoleFun( const char * name, CUI_Console::cfun *function );
00273 
00275         ~CUI_ConsoleFun();
00276 
00278         bool Execute( CUI_Console *con, char *param );
00279 
00280 protected:
00282         std::string m_name;
00283 
00285         CUI_Console::cfun *m_function;
00286 
00287 };
00288 
00289 
00290 #endif

Generated on Mon Sep 29 23:07:02 2003 for glGUI by doxygen 1.3.4