console.h

00001 /*--License:
00002         Kyra Sprite Engine
00003         Copyright Lee Thomason (Grinning Lizard Software) 2001-2005
00004         www.grinninglizard.com/kyra
00005         www.sourceforge.net/projects/kyra
00006 
00007         Kyra is provided under the LGPL. 
00008         
00009         I kindly request you display a splash screen (provided in the HTML documentation)
00010         to promote Kyra and acknowledge the software and everyone who has contributed to it, 
00011         but it is not required by the license.
00012 
00013 --- LGPL License --
00014 
00015     This library is free software; you can redistribute it and/or
00016     modify it under the terms of the GNU Lesser General Public
00017     License as published by the Free Software Foundation; either
00018     version 2.1 of the License, or (at your option) any later version.
00019 
00020     This library is distributed in the hope that it will be useful,
00021     but WITHOUT ANY WARRANTY; without even the implied warranty of
00022     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00023     Lesser General Public License for more details.
00024 
00025     You should have received a copy of the GNU Lesser General Public
00026     License along with this library; if not, write to the Free Software
00027     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00028 
00029         The full text of the license can be found in lgpl.txt
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         // Not a mouse listener.
00100 
00101         // Not a key listener. Odd, but its child textwidget is what gets the keys.
00102         // Does get keys if children don't handle.
00103         virtual bool KeyEvent( const SDL_Event& key );
00104 
00105         // Not groupable.
00106         // Doesn't accelerate.
00107         // Doesn't handle events.
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         // Used to initialize the console.
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 //      struct Command
00151 //      {
00152 //              std::string                     command;
00153 //              IKrWidgetListener*      handler;
00154 //      };
00155 
00156         GlCircleList<std::string>       commandBuf;                     // Command history
00157         int                                                     commandBufSize;
00158         GlCircleNode<std::string>*      commandBufNode;         
00159         GlSList<std::string>            commandList;            // List of recognized commands.
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

Generated on Thu Jul 20 20:45:31 2006 for Kyra by  doxygen 1.4.7