00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef KYRA_CONSOLE_INCLUDED
00033 #define KYRA_CONSOLE_INCLUDED
00034
00035 #ifdef _MSC_VER
00036 #pragma warning( disable : 4530 )
00037 #pragma warning( disable : 4786 )
00038 #endif
00039 #include <string>
00040 #include <ctype.h>
00041
00042 #include "SDL.h"
00043 #include "widget.h"
00044 #include "../../grinliz/gltypes.h"
00045 #include "../util/glcirclelist.h"
00046 #include "../util/gllist.h"
00047
00048
00049 class KrTextBox;
00050 class KrImageTree;
00051 class KrCanvasResource;
00052 class KrCanvas;
00053 class KrFontResource;
00054 class KrImNode;
00055 union KrRGBA;
00056 class KrBoxResource;
00057 class KrBox;
00058 class KrTextWidget;
00059
00060
00077 class KrConsole : public KrWidget
00078 {
00079 public:
00086 KrConsole( int width, int height,
00087 int lineSpacing,
00088 const KrScheme& scheme );
00089
00090 ~KrConsole();
00091
00092 virtual const char* WidgetType() { return "Console"; }
00093
00097 void SetBackgroundColor( const KrRGBA& color );
00098
00099
00100
00101
00102
00103 virtual bool KeyEvent( const SDL_Event& key );
00104
00105
00106
00107
00108
00110 void PushText( const char* text );
00112 void Print( const char* format, ... );
00113
00115 void GetEntryTextChar( std::string* buffer );
00116
00119 void AddCommand( const std::string& );
00120
00121 const KrTextBox* TextBox() { return textBox; }
00122
00123 KrImNode* ToExtended( const std::string& name ) { if ( name == "console" ) return this;
00124 return 0;
00125 }
00126
00127 virtual bool HandleWidgetEvent( KrWidget* source, const KrWidgetEvent& event );
00128
00129
00130 virtual void AddedtoTree();
00131
00132 private:
00133 void PositionCursor();
00134 void ProcessEnterKey();
00135 void TabCompletion();
00136
00137 enum
00138 {
00139 CURSOR_WIDTH = 2,
00140 COMMAND_BUF_SIZE = 32,
00141 LINE_BUF_SIZE = 256
00142 };
00143
00144 enum
00145 {
00146 DEPTH_BACKGROUND = -10,
00147 DEPTH_TEXT
00148 };
00149
00150
00151
00152
00153
00154
00155
00156 GlCircleList<std::string> commandBuf;
00157 int commandBufSize;
00158 GlCircleNode<std::string>* commandBufNode;
00159 GlSList<std::string> commandList;
00160
00161 KrTextBox* textBox;
00162 int width, height, lineSpacing;
00163
00164 KrFontResource* font;
00165 KrBoxResource* backgroundRes;
00166 KrBox* background;
00167 KrTextWidget* commandLine;
00168 };
00169
00170
00171 #endif