X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fsupertux%2Fconsole.hpp;h=d1c1da902953c0c36cc879960e04e2c2bad56c91;hb=9f40a73e89c17a2862a1213343589c19eff42199;hp=61c0d9beb4eada9f24386256fd766237fb3f2e70;hpb=08813a74da6ac1fd045a105e4e8105f1d7f716f0;p=supertux.git diff --git a/src/supertux/console.hpp b/src/supertux/console.hpp index 61c0d9beb..d1c1da902 100644 --- a/src/supertux/console.hpp +++ b/src/supertux/console.hpp @@ -23,24 +23,44 @@ #include #include +#include "util/currenton.hpp" +#include "video/font_ptr.hpp" +#include "video/surface_ptr.hpp" + class Console; class ConsoleStreamBuffer; class ConsoleCommandReceiver; class DrawingContext; -class Surface; -class Font; -class Console +class ConsoleBuffer : public Currenton { public: - Console(); - ~Console(); + static std::ostream output; /**< stream of characters to output to the console. Do not forget to send std::endl or to flush the stream. */ + static ConsoleStreamBuffer s_outputBuffer; /**< stream buffer used by output stream */ - static Console* instance; +public: + std::list m_lines; /**< backbuffer of lines sent to the console. New lines get added to front. */ - static std::ostream output; /**< stream of characters to output to the console. Do not forget to send std::endl or to flush the stream. */ +public: + ConsoleBuffer(); - void init_graphics(); + void addLines(const std::string& s); /**< display a string of (potentially) multiple lines in the console */ + void addLine(const std::string& s); /**< display a line in the console */ + + void flush(ConsoleStreamBuffer& buffer); /**< act upon changes in a ConsoleStreamBuffer */ + +private: + ConsoleBuffer(const ConsoleBuffer&) = delete; + ConsoleBuffer& operator=(const ConsoleBuffer&) = delete; +}; + +class Console : public Currenton +{ +public: + Console(ConsoleBuffer& buffer); + ~Console(); + + void on_buffer_change(int line_count); void input(char c); /**< add character to inputBuffer */ void backspace(); /**< delete character left of inputBufferPosition */ @@ -55,58 +75,36 @@ public: 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 static bool string_is(std::string s) { - std::istringstream iss(s); - T i; - if ((iss >> i) && iss.eof()) { - return true; - } else { - return false; - } - } - - template 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 history; /**< command history. New lines get added to back. */ - std::list::iterator history_position; /**< item of command history that is currently displayed */ - std::list lines; /**< backbuffer of lines sent to the console. New lines get added to front. */ + ConsoleBuffer& m_buffer; - std::auto_ptr background; /**< console background image */ - std::auto_ptr background2; /**< second, moving console background image */ + std::string m_inputBuffer; /**< string used for keyboard input */ + int m_inputBufferPosition; /**< position in inputBuffer before which to append new characters */ - HSQUIRRELVM vm; /**< squirrel thread for the console (with custom roottable) */ - HSQOBJECT vm_object; + std::list m_history; /**< command history. New lines get added to back. */ + std::list::iterator m_history_position; /**< item of command history that is currently displayed */ - 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; - 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 */ + SurfacePtr m_background; /**< console background image */ + SurfacePtr m_background2; /**< second, moving console background image */ - float stayOpen; + HSQUIRRELVM m_vm; /**< squirrel thread for the console (with custom roottable) */ + HSQOBJECT m_vm_object; - static int inputBufferPosition; /**< position in inputBuffer before which to append new characters */ - static std::string inputBuffer; /**< string used for keyboard input */ - static ConsoleStreamBuffer outputBuffer; /**< stream buffer used by output stream */ + 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 m_stayOpen; - void addLines(std::string s); /**< display a string of (potentially) multiple lines in the console */ - void addLine(std::string s); /**< display a line in the console */ void parse(std::string s); /**< react to a given command */ /** ready a virtual machine instance, creating a new thread and loading default .nut files if needed */ @@ -117,9 +115,6 @@ private: bool consoleCommand(std::string command, std::vector arguments); /**< process internal command; return false if command was unknown, true otherwise */ - friend class ConsoleStreamBuffer; - void flush(ConsoleStreamBuffer* buffer); /**< act upon changes in a ConsoleStreamBuffer */ - private: Console(const Console&); Console & operator=(const Console&); @@ -131,8 +126,8 @@ public: int sync() { int result = std::stringbuf::sync(); - if(Console::instance != NULL) - Console::instance->flush(this); + if(ConsoleBuffer::current()) + ConsoleBuffer::current()->flush(*this); return result; } };