FIFE  2008.0
console.h
00001 /***************************************************************************
00002  *   Copyright (C) 2005-2008 by the FIFE team                              *
00003  *   http://www.fifengine.de                                               *
00004  *   This file is part of FIFE.                                            *
00005  *                                                                         *
00006  *   FIFE is free software; you can redistribute it and/or                 *
00007  *   modify it under the terms of the GNU Lesser General Public            *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2.1 of the License, or (at your option) any later version.    *
00010  *                                                                         *
00011  *   This library is distributed in the hope that it will be useful,       *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00014  *   Lesser General Public License for more details.                       *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Lesser General Public      *
00017  *   License along with this library; if not, write to the                 *
00018  *   Free Software Foundation, Inc.,                                       *
00019  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
00020  ***************************************************************************/
00021 
00022 #ifndef FIFE_GUICHAN_ADDON_CONSOLE_H
00023 #define FIFE_GUICHAN_ADDON_CONSOLE_H
00024 
00025 // Standard C++ library includes
00026 #include <string>
00027 
00028 // 3rd party library includes
00029 #include <guichan.hpp>
00030 
00031 // FIFE includes
00032 // These includes are split up in two parts, separated by one empty line
00033 // First block: files included from the FIFE root src directory
00034 // Second block: files included from the same folder
00035 #include "util/time/timer.h"
00036 
00037 namespace FIFE {
00038 
00039     class CommandLine;
00040     class GuiFont;
00041 
00045     class ConsoleExecuter {
00046         public:
00049             virtual ~ConsoleExecuter() {}
00050 
00053             virtual void onToolsClick() = 0;
00054 
00058             virtual std::string onConsoleCommand(const std::string& command) = 0;
00059     };
00060 
00061 
00064     class Console : public gcn::Container, public gcn::ActionListener, public gcn::FocusListener {
00065         public:
00068             Console();
00069 
00072             virtual ~Console();
00073 
00076             void println(const std::string & s);
00077 
00083             void show();
00084 
00089             void hide();
00090 
00093             void clear();
00094 
00099             void toggleShowHide();
00100 
00109             void execute(std::string cmd);
00110 
00114             void updateCaption();
00115 
00119             void updateAnimation();
00120 
00123             void action(const gcn::ActionEvent & event);
00124 
00127             void setConsoleExecuter(ConsoleExecuter* const consoleexec);
00128 
00131             void removeConsoleExecuter();
00132 
00135             void reLayout();
00136 
00139             void setIOFont(GuiFont* font);
00140 
00143             void focusLost(const gcn::Event& event);
00144         private:
00145 
00146             bool m_isAttached;
00147             ConsoleExecuter* m_consoleexec;
00148             
00149             CommandLine*      m_input;
00150             gcn::TextBox*     m_output;
00151             gcn::ScrollArea*  m_outputscrollarea;
00152             gcn::Label*       m_status;
00153             gcn::Button*      m_toolsbutton;
00154             static const unsigned m_maxOutputRows;
00155 
00156             std::string m_prompt;
00157 
00158             int m_hiddenPos;
00159             int m_animationDelta;
00160 
00161             bool m_hiding;
00162 
00163             Timer m_fpsTimer;
00164             Timer m_animationTimer;
00165 
00166             void doShow();
00167             void doHide();
00168     };
00169 }
00170 #endif
00171 /* vim: set noexpandtab: set shiftwidth=2: set tabstop=2: */