view engine/core/gui/console/console.h @ 378:64738befdf3b

bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
author vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
date Mon, 11 Jan 2010 23:34:52 +0000
parents bb9902910067
children
line wrap: on
line source

/***************************************************************************
 *   Copyright (C) 2005-2008 by the FIFE team                              *
 *   http://www.fifengine.de                                               *
 *   This file is part of FIFE.                                            *
 *                                                                         *
 *   FIFE is free software; you can redistribute it and/or                 *
 *   modify it under the terms of the GNU Lesser General Public            *
 *   License as published by the Free Software Foundation; either          *
 *   version 2.1 of the License, or (at your option) any later version.    *
 *                                                                         *
 *   This library is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
 *   Lesser General Public License for more details.                       *
 *                                                                         *
 *   You should have received a copy of the GNU Lesser General Public      *
 *   License along with this library; if not, write to the                 *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
 ***************************************************************************/

#ifndef FIFE_GUICHAN_ADDON_CONSOLE_H
#define FIFE_GUICHAN_ADDON_CONSOLE_H

// Standard C++ library includes
#include <string>

// 3rd party library includes
#include <guichan.hpp>

// FIFE includes
// These includes are split up in two parts, separated by one empty line
// First block: files included from the FIFE root src directory
// Second block: files included from the same folder
#include "util/time/timer.h"

namespace FIFE {

	class CommandLine;
	class GuiFont;

	/**
	* Console executer is listener interface for console activity
	*/
	class ConsoleExecuter {
		public:
			/** Destructor
			 */
			virtual ~ConsoleExecuter() {}

			/** Called when console tools button is clicked
			 */
			virtual void onToolsClick() = 0;

			/** Called when user has typed command to console and pressed enter
			 * @return response from executer
			 */
			virtual std::string onConsoleCommand(const std::string& command) = 0;
	};


	/** Ingame Console
	 */
	class Console : public gcn::Container, public gcn::ActionListener, public gcn::FocusListener {
		public:
			/** Constructor
			 */
			Console();

			/** Destructor
			 */
			virtual ~Console();

			/** Print one or more lines to the console output
			 */
			void println(const std::string & s);

			/** Show the console
			 * Adds the Console to the guichan toplevel container
			 * and pushes an input Context so that keys are not send to the
			 * rest of the game.
			 */
			void show();

			/** Hide the console
			 * Removes itself from the toplevel container
			 * and pops it's input context
			 */
			void hide();

			/** Clear the console output
			 */
			void clear();

			/** Toggle the console
			 * Toggles whether the Console is shown or not.
			 * Calls show() or hide() respectively.
			 */
			void toggleShowHide();

			/** Execute a command
			 * Normally just sends the command to runString()
			 * Checks whether the cmd is just one token
			 * and print it's value rather than throw an
			 * useless error.
			 *
			 * @todo generalize the generated command and the regexp used.
			 */
			void execute(std::string cmd);

			/** Update the FPS caption
			 *  @note Is a timer callback.
			 */
			void updateCaption();

			/** Update the scroll in/out animation.
			 *  @note Is a timer callback.
			 */
			void updateAnimation();

			/** Callback from guichan to respond to button press
			 */
			void action(const gcn::ActionEvent & event);

			/** Sets executer for the console
			 */
			void setConsoleExecuter(ConsoleExecuter* const consoleexec);

			/** Removes executer for the console
			 */
			void removeConsoleExecuter();

			/** Layouts the console to match e.g. font changes
			 */
			void reLayout();

			/** Sets the font used for the input and output areas
			 */
			void setIOFont(GuiFont* font);

			/** Hide if we loose focus
			*/
			void focusLost(const gcn::Event& event);
		private:

			bool m_isAttached;
			ConsoleExecuter* m_consoleexec;
			
			CommandLine*      m_input;
			gcn::TextBox*     m_output;
			gcn::ScrollArea*  m_outputscrollarea;
			gcn::Label*       m_status;
			gcn::Button*      m_toolsbutton;
			static const unsigned m_maxOutputRows;

			std::string m_prompt;

			int m_hiddenPos;
			int m_animationDelta;

			bool m_hiding;

			Timer m_fpsTimer;
			Timer m_animationTimer;

			void doShow();
			void doHide();
	};
}
#endif
/* vim: set noexpandtab: set shiftwidth=2: set tabstop=2: */