#include <sstream>
#include <vector>
+#include "util/currenton.hpp"
+#include "video/font_ptr.hpp"
#include "video/surface_ptr.hpp"
class Console;
class ConsoleStreamBuffer;
class ConsoleCommandReceiver;
class DrawingContext;
-class Font;
-class Console
+class Console : public Currenton<Console>
{
public:
Console();
~Console();
- static Console* instance;
-
static std::ostream output; /**< stream of characters to output to the console. Do not forget to send std::endl or to flush the stream. */
- void init_graphics();
-
void input(char c); /**< add character to inputBuffer */
void backspace(); /**< delete character left of inputBufferPosition */
void eraseChar(); /**< delete character at inputBufferPosition */
void update(float elapsed_time);
void show(); /**< display the console */
+ void open(); /**< open the console for viewing for 6 seconds */
void hide(); /**< hide the console */
void toggle(); /**< display the console if hidden, hide otherwise */
bool hasFocus(); /**< true if characters should be sent to the console instead of their normal target */
- template<typename T> static bool string_is(std::string s) {
- std::istringstream iss(s);
- T i;
- if ((iss >> i) && iss.eof()) {
- return true;
- } else {
- return false;
- }
- }
-
- template<typename T> static T string_to(std::string s) {
- std::istringstream iss(s);
- T i;
- if ((iss >> i) && iss.eof()) {
- return i;
- } else {
- return T();
- }
- }
-
private:
- std::list<std::string> history; /**< command history. New lines get added to back. */
- std::list<std::string>::iterator history_position; /**< item of command history that is currently displayed */
- std::list<std::string> lines; /**< backbuffer of lines sent to the console. New lines get added to front. */
+ std::list<std::string> m_history; /**< command history. New lines get added to back. */
+ std::list<std::string>::iterator m_history_position; /**< item of command history that is currently displayed */
+ std::list<std::string> m_lines; /**< backbuffer of lines sent to the console. New lines get added to front. */
- SurfacePtr background; /**< console background image */
- SurfacePtr background2; /**< second, moving console background image */
+ SurfacePtr m_background; /**< console background image */
+ SurfacePtr m_background2; /**< second, moving console background image */
- HSQUIRRELVM vm; /**< squirrel thread for the console (with custom roottable) */
- HSQOBJECT vm_object;
+ HSQUIRRELVM m_vm; /**< squirrel thread for the console (with custom roottable) */
+ HSQOBJECT m_vm_object;
- int backgroundOffset; /**< current offset of scrolling background image */
- float height; /**< height of the console in px */
- float alpha;
- int offset; /**< decrease to scroll text up */
- bool focused; /**< true if console has input focus */
- std::auto_ptr<Font> font;
- float fontheight; /**< height of the font (this is a separate var, because the font could not be initialized yet but is needed in the addLine message */
+ int m_backgroundOffset; /**< current offset of scrolling background image */
+ float m_height; /**< height of the console in px */
+ float m_alpha;
+ int m_offset; /**< decrease to scroll text up */
+ bool m_focused; /**< true if console has input focus */
+ FontPtr m_font;
- float stayOpen;
+ float m_stayOpen;
static int inputBufferPosition; /**< position in inputBuffer before which to append new characters */
static std::string inputBuffer; /**< string used for keyboard input */
int sync()
{
int result = std::stringbuf::sync();
- if(Console::instance != NULL)
- Console::instance->flush(this);
+ if(Console::current())
+ Console::current()->flush(this);
return result;
}
};