00001 // console.h 00002 // 00003 // Copyright (C) 2003, Chris Laurel <claurel@shatters.net> 00004 // 00005 // This program is free software; you can redistribute it and/or 00006 // modify it under the terms of the GNU General Public License 00007 // as published by the Free Software Foundation; either version 2 00008 // of the License, or (at your option) any later version. 00009 00010 #ifndef _CELENGINE_CONSOLE_H_ 00011 #define _CELENGINE_CONSOLE_H_ 00012 00013 #include <string> 00014 #include <iostream> 00015 #include <celtxf/texturefont.h> 00016 00017 00018 class Console; 00019 00020 // Custom streambuf class to support C++ operator style output. The 00021 // output is completely unbuffered. 00022 class ConsoleStreamBuf : public std::streambuf 00023 { 00024 public: 00025 ConsoleStreamBuf() : console(NULL) { setbuf(0, 0); }; 00026 00027 void setConsole(Console*); 00028 00029 int overflow(int c = EOF); 00030 enum UTF8DecodeState 00031 { 00032 UTF8DecodeStart = 0, 00033 UTF8DecodeMultibyte = 1, 00034 }; 00035 00036 private: 00037 Console* console; 00038 UTF8DecodeState decodeState; 00039 wchar_t decodedChar; 00040 unsigned int decodeShift; 00041 }; 00042 00043 00044 class Console : public std::ostream 00045 { 00046 public: 00047 Console(int _nRows, int _nColumns); 00048 ~Console(); 00049 00050 void begin(); 00051 void end(); 00052 void render(int rowHeight); 00053 00054 void setScale(int, int); 00055 void setFont(TextureFont*); 00056 00057 void print(wchar_t); 00058 void print(char*); 00059 void newline(); 00060 #if 0 00061 void printf(const char*, ...); 00062 #endif 00063 00064 int getRow() const; 00065 int getColumn() const; 00066 int getWindowRow() const; 00067 void setWindowRow(int); 00068 void setWindowHeight(int); 00069 00070 int getHeight() const; 00071 int getWidth() const; 00072 00073 private: 00074 wchar_t* text; 00075 int nRows; 00076 int nColumns; 00077 int row; 00078 int column; 00079 00080 int windowRow; 00081 00082 int windowHeight; 00083 00084 int xscale; 00085 int yscale; 00086 TextureFont* font; 00087 00088 ConsoleStreamBuf sbuf; 00089 00090 bool autoScroll; 00091 }; 00092 00093 #endif // _CELENGINE_CONSOLE_H_
1.4.1