00001 /*--License: 00002 Kyra Sprite Engine 00003 Copyright Lee Thomason (Grinning Lizard Software) 2001-2002 00004 www.grinninglizard.com/kyra 00005 www.sourceforge.net/projects/kyra 00006 00007 Kyra is provided under 2 licenses: 00008 00009 - The GPL, with no additional restrictions. 00010 - The LGPL, provided you display the Kyra splash screen, described below. 00011 00012 00013 --- GPL License -- 00014 This program is free software; you can redistribute it and/or 00015 modify it under the terms of the GNU General Public License 00016 as published by the Free Software Foundation; either version 2 00017 of the License, or (at your option) any later version. 00018 00019 This program is distributed in the hope that it will be useful, 00020 but WITHOUT ANY WARRANTY; without even the implied warranty of 00021 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00022 GNU General Public License for more details. 00023 00024 You should have received a copy of the GNU General Public License 00025 along with this program; if not, write to the Free Software 00026 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00027 00028 The full text of the license can be found in license.txt 00029 00030 00031 --- LGPL License -- 00032 **Provided you kindly display the Kyra splash screen (details below), 00033 you may use the LGPL license:** 00034 00035 This library is free software; you can redistribute it and/or 00036 modify it under the terms of the GNU Lesser General Public 00037 License as published by the Free Software Foundation; either 00038 version 2.1 of the License, or (at your option) any later version. 00039 00040 This library is distributed in the hope that it will be useful, 00041 but WITHOUT ANY WARRANTY; without even the implied warranty of 00042 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00043 Lesser General Public License for more details. 00044 00045 You should have received a copy of the GNU Lesser General Public 00046 License along with this library; if not, write to the Free Software 00047 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00048 00049 The full text of the license can be found in lgpl.txt 00050 00051 00052 --- Kyra Splash Screen. 00053 00054 It would be appreciate if you display the Kyra splash screen when using 00055 either license, however it is only required for the LGPL. All the 00056 resources for the splash are compiled into the library, and it can be 00057 accessed through the following API: 00058 00059 KrEngine::StartSplash 00060 KrEngine::UpdateSplash 00061 KrEngine::EndSplash 00062 00063 Full documentation is provided with the KrEngine class. The splash screen 00064 should be displayed for 2 seconds. 00065 00066 Thank you. 00067 */ 00068 00069 #ifndef KYRA_CONSOLE_INCLUDED 00070 #define KYRA_CONSOLE_INCLUDED 00071 00072 #pragma warning( disable : 4530 ) 00073 #pragma warning( disable : 4786 ) 00074 #include <string> 00075 #include <ctype.h> 00076 00077 #include "SDL.h" 00078 #include "widget.h" 00079 #include "../util/gltypes.h" 00080 #include "../util/gldynarray.h" 00081 #include "../util/glcirclelist.h" 00082 #include "../util/gllist.h" 00083 00084 00085 class KrTextBox; 00086 class KrImageTree; 00087 class KrCanvasResource; 00088 class KrCanvas; 00089 class KrFontResource; 00090 class KrImNode; 00091 union KrRGBA; 00092 class KrBoxResource; 00093 class KrBox; 00094 class KrTextWidget; 00095 00096 00113 class KrConsole : public KrWidget 00114 { 00115 public: 00122 KrConsole( int width, int height, 00123 int lineSpacing, 00124 const KrScheme& scheme ); 00125 00126 ~KrConsole(); 00127 00131 void SetBackgroundColor( const KrRGBA& color ); 00132 00133 // Not my best idea. Better solved by simply putting color or an image 00134 // behind the object. 00135 // /** Set a background box: same options and flags as KrBoxResource. 00136 // Only works after the KrConsole has been added to the Tree. 00137 // */ 00138 // void SetBackgroundBox( const KrRGBA* colorArray, 00139 // int numColors, 00140 // int flags ); 00141 00142 // Not a mouse listener. 00143 00144 // Not a key listener. Odd, but its child textwidget is what gets the keys. 00145 // Does get keys if children don't handle. 00146 virtual bool KeyEvent( const SDL_Event& key ); 00147 00148 // Not groupable. 00149 // Doesn't accelerate. 00150 // Doesn't handle events. 00151 00153 void PushText( const char* text ); 00155 void Print( const char* format, ... ); 00156 00158 void GetEntryTextChar( std::string* buffer ); 00159 00164 void AddCommand( const std::string&, IKrWidgetListener* handler ); 00165 00166 const KrTextBox* TextBox() { return textBox; } 00167 00168 KrImNode* ToExtended( const std::string& name ) { if ( name == "console" ) return this; 00169 return 0; 00170 } 00171 00172 virtual bool HandleWidgetEvent( KrWidget* source, 00173 U32 event, U32 data, const SDL_Event* sdlEvent, 00174 const char* command, const char* arg ); 00175 00176 // Used to initialize the console. 00177 virtual void AddedtoTree(); 00178 00179 private: 00180 void PositionCursor(); 00181 void ProcessEnterKey(); 00182 void TabCompletion(); 00183 00184 enum 00185 { 00186 CURSOR_WIDTH = 2, 00187 COMMAND_BUF_SIZE = 32, 00188 LINE_BUF_SIZE = 256 00189 }; 00190 00191 enum 00192 { 00193 DEPTH_BACKGROUND = -10, 00194 DEPTH_TEXT 00195 }; 00196 00197 struct Command 00198 { 00199 std::string command; 00200 IKrWidgetListener* handler; 00201 }; 00202 00203 GlCircleList<std::string> commandBuf; // Command history 00204 int commandBufSize; 00205 GlCircleNode<std::string>* commandBufNode; 00206 GlSList<Command> commandList; // List of recognized commands. 00207 00208 KrTextBox* textBox; 00209 // KrCanvasResource* cursorRes; 00210 // KrCanvas* cursor; 00211 00212 // int cursorPos; 00213 int width, height, lineSpacing; 00214 00215 KrFontResource* font; 00216 KrBoxResource* backgroundRes; 00217 KrBox* background; 00218 KrTextWidget* commandLine; 00219 }; 00220 00221 00222 #endif