X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fconsole.hpp;h=59d393486816cde1605e21d5c573e8c1bc995a6a;hb=665b4a4a6b0edae82fb830528f16d2176da44aa4;hp=e458926ce7957010dab14a6d0124268eafd50ddb;hpb=07ddaed2a657e4d2a3d038fed223fc5827159caf;p=supertux.git diff --git a/src/console.hpp b/src/console.hpp index e458926ce..59d393486 100644 --- a/src/console.hpp +++ b/src/console.hpp @@ -26,6 +26,7 @@ #include #include #include +#include class Console; class ConsoleStreamBuffer; @@ -34,7 +35,7 @@ class DrawingContext; class Surface; class Font; -class Console +class Console { public: Console(); @@ -42,24 +43,27 @@ public: static Console* instance; - static std::ostream input; /**< stream of keyboard input to send to the console. Do not forget to send std::endl or to flush the stream. */ 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 backspace(); /**< delete last character sent to the input 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 enter(); /**< process and clear input stream */ void scroll(int offset); /**< scroll console text up or down by @c offset lines */ void autocomplete(); /**< autocomplete current command */ + void show_history(int offset); /**< move @c offset lines forward through history; Negative offset moves backward */ + void move_cursor(int offset); /**< move the cursor @c offset chars to the right; Negative offset moves backward; 0xFFFF moves to the end */ void draw(DrawingContext& context); /**< draw the console in a DrawingContext */ void update(float elapsed_time); - + void show(); /**< display the console */ 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 */ - void registerCommand(std::string command, ConsoleCommandReceiver* ccr); /**< associate command with the given CCR */ - void unregisterCommand(std::string command, ConsoleCommandReceiver* ccr); /**< dissociate command and CCR */ - void unregisterCommands(ConsoleCommandReceiver* ccr); /**< dissociate all commands of given CCR */ template static bool string_is(std::string s) { std::istringstream iss(s); @@ -82,40 +86,50 @@ public: } private: - std::list lines; /**< backbuffer of lines sent to the console */ - std::map > commands; /**< map of console commands and a list of associated ConsoleCommandReceivers */ - + 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. */ + std::auto_ptr background; /**< console background image */ std::auto_ptr background2; /**< second, moving console background image */ - + + HSQUIRRELVM vm; /**< squirrel thread for the console (with custom roottable) */ + HSQOBJECT 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; + 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 */ float stayOpen; - static ConsoleStreamBuffer inputBuffer; /**< stream buffer used by input stream */ + 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 */ + 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 */ + void ready_vm(); + /** execute squirrel script and output result */ void execute_script(const std::string& s); - + 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 */ }; -class ConsoleStreamBuffer : public std::stringbuf +class ConsoleStreamBuffer : public std::stringbuf { public: - int sync() + int sync() { int result = std::stringbuf::sync(); if(Console::instance != NULL) @@ -124,19 +138,4 @@ class ConsoleStreamBuffer : public std::stringbuf } }; -class ConsoleCommandReceiver -{ -public: - virtual ~ConsoleCommandReceiver() - { - Console::instance->unregisterCommands(this); - } - - /** - * callback from Console; return false if command was unknown, - * true otherwise - */ - virtual bool consoleCommand(std::string command, std::vector arguments) = 0; -}; - #endif