/*
 * This source file is part of KEOS (Free 3D Engine)
 * For the latest info, see http://www.keosengine.org/
 * E-mails : thierry.vouriot@keosengine.org, yeri@keosengine.org
 * 
 * This program 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 of the License, or (at your option) any later
 * version.
 *
 * This program 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 program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place - Suite 330, Boston, MA 02111-1307, USA, or go to
 * http://www.gnu.org/copyleft/lesser.txt.
 *
 */
#ifndef KEOS_CONSOLELOOKDEFAULT_H
#define KEOS_CONSOLELOOKDEFAULT_H

#include "KeosPrerequisites.h"
#include "KeosModel.h"
#include "KeosConsoleLook.h"
#include "KeosMatrix4.h"
#include "KeosColor.h"

namespace Keos {

	namespace Console {

        //-----------------------------------------------------------------------
        /** Class defining a personalized look for the console.
        */
	    class KEOS_EXPORT CLookDefault : public ILook
	    {
	    public :

	        /** Default constructor.
            *  @param strFont Resource name for the font.
            *  @param Size Size of the console.
            *  @param strTexture File with the texture for the background.
            *  @param TextColor Color of the text seized by the user.
            *  @param TextOkColor Color of the text returned by a command.
            *  @param TextErrorColor Color of the text resulting from an error.
            */
		    CLookDefault(	const String& strFont, TVector2F Size, const String& strTexture,
						    const CColor& TextColor = CColor::White, const CColor& TextOkColor = CColor(150, 200, 150), 
						    const CColor& TextErrorColor = CColor(200, 150, 150) );

            /** Function called during the update of the console.
            *  Function to be overloaded to define an ILook.
            */
		    virtual void Update();

            /** Function called during the display of the console.
            *  Function to be overloaded to define an ILook.
            */
		    virtual void Draw() const;

            /** Function called during the activation/deactivation of the console.
            *  Function to be overloaded to define an ILook.
            *  @param bVisible Show/Hide the console (state).
            */
		    virtual void Show(bool bVisible);

            /** Function called after the call to a command.
            *  Function to be overloaded to define an ILook.
            *  @param strResult Result of the call of the command.
            */
		    virtual void CommandCalled(const String& strResult);

            /** Function called to every change of the current line.
            *  Function to be overloaded to define an ILook.
            *  @param strNewText New text.
            */
		    virtual void TextChanged(const String& strNewText);

            /** Function called in case of error.
            *  Function to be overloaded to define an ILook.
            *  @param strMessage Message describing the error.
            */
		    virtual void Error(const String& strMessage);

            /** Change the colors of the text in console.
            *  @param TextColor Color of the text seized by the user.
            *  @param TextOkColor Color of the text returned by a command.
            *  @param TextErrorColor Color of the text resulting from an error.
            */
		    void SetTextColors(const CColor& TextColor, const CColor& TextOkColor, const CColor& TextErrorColor)
		    {
			    m_TextColor			= TextColor;
			    m_TextOkColor		= TextOkColor;
			    m_TextErrorColor	= TextErrorColor;
		    }

	    private :

		    //! Console states
	        enum TState {STOPPED_VISIBLE, STOPPED_INVISIBLE, HIDDING, SHOWING};

            /** Add a line.
             *  @param strLine Text of the new line.
             *  @param Color Color of the text.
             */
		    void AddLine(const String& strLine, const CColor& Color);

            //! Backgroud of the console
		    TModelPtr                 m_Background;
            //! Last lines shown on the console
		    std::list<CGraphicString> m_Lines;  
			//! Matrix of transformation associated to the displaying of the console
            CMatrix4                  m_Transfo; 
            //! State of the animation of the console
		    TState                    m_State;
            //! Size of the console (background)
            TVector2F                 m_nSize;

            //! Resource name for the font
		    String    m_strFont;
            //! Font height (pixels)
		    size_t    m_nFontHeight;
		    //! Color of the text seized by the user
		    CColor		m_TextColor;
            //! Color of the text resulting from an error
		    CColor		m_TextErrorColor;
            //! Color of the text returned by a command
		    CColor		m_TextOkColor;
		    };

        /** Struct used to display message in the console.
        *  Ex:  CConsole::Instance().RegisterCommand("ver", Console::Bind(Console::Print("version 1.X")));
        */
	    struct Print
        {
            Print(const std::string& Text) : m_Text(Text) {}

            const std::string& operator ()() const
            {
                return m_Text;
            }

        private :

            std::string m_Text;
        };

	} // namespace Console

} // namespace Keos

#endif // KEOS_CONSOLELOOKDEFAULT_H
