1 // $Id: worldmap.hpp 3209 2006-04-02 22:19:22Z sommer $
4 // Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #ifndef SUPERTUX_CONSOLE_H
21 #define SUPERTUX_CONSOLE_H
29 class ConsoleStreamBuffer;
30 class ConsoleCommandReceiver;
40 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. */
41 static std::ostream output; /**< stream of characters to output to the console. Do not forget to send std::endl or to flush the stream. */
43 static void flush(ConsoleStreamBuffer* buffer); /**< act upon changes in a stream, normally called by the stream itself */
45 void draw(DrawingContext& context); /**< draw the console to its */
46 static void show(); /**< display the console */
47 static void hide(); /**< hide the console */
48 static bool hasFocus(); /**< true if characters should be sent to the console instead of their normal target */
49 static void registerCommandReceiver(ConsoleCommandReceiver* ccr); /**< register instance to notify of commands entered in the console */
50 static void unregisterCommandReceiver(ConsoleCommandReceiver* ccr); /**< new commands should no longer be sent to this ccr */
53 static std::list<std::string> lines; /**< backbuffer of lines sent to the console */
54 static std::list<ConsoleCommandReceiver*> commandReceivers; /**< list of instances to notify of new console commands */
55 DrawingContext* context; /**< context to draw to */
56 Surface* background; /**< console background image */
57 static int height; /**< height of the console in px */
58 static bool focused; /**< true if console has input focus */
60 static ConsoleStreamBuffer inputBuffer; /**< stream buffer used by input stream */
61 static ConsoleStreamBuffer outputBuffer; /**< stream buffer used by output stream */
63 static void addLine(std::string s); /**< display a line in the console */
64 static void parse(std::string s); /**< react to a given command */
67 class ConsoleStreamBuffer : public std::stringbuf
73 return std::stringbuf::sync();
77 class ConsoleCommandReceiver
80 ConsoleCommandReceiver()
82 //Console::registerCommandReceiver(this);
84 virtual bool consoleCommand(std::string command) = 0; /**< callback from Console; return false if command was unknown, true otherwise */
85 virtual ~ConsoleCommandReceiver()
87 //Console::unregisterCommandReceiver(this);