PixelLightAPI  .
SNConsoleBase.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: SNConsoleBase.h                                *
00003  *
00004  *  Copyright (C) 2002-2012 The PixelLight Team (http://www.pixellight.org/)
00005  *
00006  *  This file is part of PixelLight.
00007  *
00008  *  PixelLight is free software: you can redistribute it and/or modify
00009  *  it under the terms of the GNU Lesser General Public License as published by
00010  *  the Free Software Foundation, either version 3 of the License, or
00011  *  (at your option) any later version.
00012  *
00013  *  PixelLight is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  *  GNU Lesser General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU Lesser General Public License
00019  *  along with PixelLight. If not, see <http://www.gnu.org/licenses/>.
00020 \*********************************************************/
00021 
00022 
00023 #ifndef __PLENGINE_COMPOSITING_CONSOLEBASE_H__
00024 #define __PLENGINE_COMPOSITING_CONSOLEBASE_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include <PLScene/Scene/SceneNode.h>
00032 #include "PLEngine/PLEngine.h"
00033 
00034 
00035 //[-------------------------------------------------------]
00036 //[ Namespace                                             ]
00037 //[-------------------------------------------------------]
00038 namespace PLEngine {
00039 
00040 
00041 //[-------------------------------------------------------]
00042 //[ Forward declarations                                  ]
00043 //[-------------------------------------------------------]
00044 class ConsoleCommand;
00045 
00046 
00047 //[-------------------------------------------------------]
00048 //[ Classes                                               ]
00049 //[-------------------------------------------------------]
00050 /**
00051 *  @brief
00052 *    Abstract console base class
00053 */
00054 class SNConsoleBase : public PLScene::SceneNode {
00055 
00056 
00057     //[-------------------------------------------------------]
00058     //[ Public definitions                                    ]
00059     //[-------------------------------------------------------]
00060     public:
00061         /**
00062         *  @brief
00063         *    Console state
00064         */
00065         enum EState {
00066             Active       = 0,   /**< Console is active */
00067             Inactive     = 1,   /**< Console is inactive */
00068             Activating   = 2,   /**< Console is going active */
00069             Deactivating = 3    /**< Console is going inactive */
00070         };
00071 
00072         /**
00073         *  @brief
00074         *    Scene node flags (SceneNode flags extension)
00075         */
00076         enum EFlags {
00077             NoDebugCommands = 1<<10 /**< Do not allow debug commands */
00078         };
00079         pl_enum(EFlags)
00080             pl_enum_base(SceneNode::EFlags)
00081             pl_enum_value(NoDebugCommands, "Do not allow debug commands")
00082         pl_enum_end
00083 
00084 
00085     //[-------------------------------------------------------]
00086     //[ RTTI interface                                        ]
00087     //[-------------------------------------------------------]
00088     pl_class(PL_RTTI_EXPORT, SNConsoleBase, "PLEngine", PLScene::SceneNode, "Abstract console base class")
00089         // Attributes
00090             // Overwritten SceneNode attributes
00091         pl_attribute(Flags, pl_flag_type(EFlags),   NoCulling,  ReadWrite,  GetSet, "Flags",    "")
00092     pl_class_end
00093 
00094 
00095     //[-------------------------------------------------------]
00096     //[ Public functions                                      ]
00097     //[-------------------------------------------------------]
00098     public:
00099         /**
00100         *  @brief
00101         *    Returns whether the console is active or not
00102         *
00103         *  @return
00104         *    'true' if the console is active, else 'false'
00105         */
00106         PL_API bool IsActive() const;
00107 
00108         /**
00109         *  @brief
00110         *    Activates the console
00111         */
00112         PL_API void Activate();
00113 
00114         /**
00115         *  @brief
00116         *    Deactivates the console
00117         */
00118         PL_API void Deactivate();
00119 
00120         /**
00121         *  @brief
00122         *    Returns the current console state
00123         *
00124         *  @return
00125         *    Console state
00126         */
00127         PL_API EState GetState() const;
00128 
00129         /**
00130         *  @brief
00131         *    Clear the command history
00132         */
00133         PL_API void ClearCommandHistory();
00134 
00135         /**
00136         *  @brief
00137         *    Returns the console description
00138         *
00139         *  @return
00140         *    Console description
00141         */
00142         PL_API virtual PLCore::String GetDescription() const;
00143 
00144         /**
00145         *  @brief
00146         *    Registers a new command
00147         *
00148         *  @param[in] bDebug
00149         *    Debug command?
00150         *  @param[in] sCommand
00151         *    Command string
00152         *  @param[in] sParameters
00153         *    Parameter string
00154         *  @param[in] sHelp
00155         *    Help string
00156         *  @param[in] cFunctor
00157         *    Execution functor
00158         *
00159         *  @remarks
00160         *    Example:\n
00161         *    RegisterCommand(0, "/fogcolor", "III", "<r> <g> <b>", Functor<void, ConsoleCommand &>(MyCommandFuncton));
00162         *
00163         *  @return
00164         *    'true' if all went fine, else 'false'
00165         *
00166         *  @see
00167         *    - Have a look at the definition of ConsoleCommand::EMsgParamID for more information
00168         *      about the command parameters
00169         */
00170         PL_API bool RegisterCommand(bool bDebug, const PLCore::String &sCommand, const PLCore::String &sParameters,
00171                                     const PLCore::String &sHelp, const PLCore::Functor<void, ConsoleCommand &> &cFunctor);
00172 
00173         /**
00174         *  @brief
00175         *    Register a new command
00176         *
00177         *  @param[in] cCommand
00178         *    Command which should be registered
00179         *
00180         *  @return
00181         *    'true' if all went fine, else 'false'
00182         *
00183         *  @see
00184         *    - RegisterCommand() above
00185         */
00186         PL_API bool RegisterCommand(const ConsoleCommand &cCommand);
00187 
00188         /**
00189         *  @brief
00190         *    Unregisters a command
00191         *
00192         *  @param[in] sCommand
00193         *    Command to remove
00194         *
00195         *  @return
00196         *    'true' if all went fine, else 'false'
00197         *
00198         *  @note
00199         *    - eg: "/fogcolor"... this will remove the /fogcolor command
00200         */
00201         PL_API bool UnRegisterCommand(const PLCore::String &sCommand);
00202 
00203         /**
00204         *  @brief
00205         *    Unregisters all commands
00206         */
00207         PL_API void UnRegisterAllCommands();
00208 
00209         /**
00210         *  @brief
00211         *    Returns the number of registered commands
00212         *
00213         *  @return
00214         *    The number of registered commands
00215         */
00216         PL_API PLCore::uint32 GetNumOfCommands() const;
00217 
00218         /**
00219         *  @brief
00220         *    Returns the number of parameters in a given string
00221         *
00222         *  @param[in] sString
00223         *    The string which should be checked
00224         *
00225         *  @return
00226         *    Number of parameters in the given string
00227         *
00228         *  @remarks
00229         *    Example: "/fogcolor 100 20 240" will return the value 3
00230         */
00231         PL_API PLCore::uint32 GetNumOfParamsInString(const PLCore::String &sString) const;
00232 
00233         /**
00234         *  @brief
00235         *    Process a keyboard message
00236         */
00237         PL_API void ProcessKeyMessage();
00238 
00239         /**
00240         *  @brief
00241         *    Process a command
00242         *
00243         *  @param[in] sCommand
00244         *    Command which should be executed
00245         *
00246         *  @note
00247         *    - If 'sCommand' is empty, the console own command line will be executed
00248         */
00249         PL_API void ProcessCommand(const PLCore::String &sCommand = "");
00250 
00251         /**
00252         *  @brief
00253         *    Prints a list of all available console commands into the log
00254         *
00255         *  @param[in] bDetailed
00256         *    Should the list have all available information about each command?
00257         */
00258         PL_API void List(bool bDetailed = false);
00259 
00260 
00261     //[-------------------------------------------------------]
00262     //[ Protected functions                                   ]
00263     //[-------------------------------------------------------]
00264     protected:
00265         /**
00266         *  @brief
00267         *    Default constructor
00268         */
00269         PL_API SNConsoleBase();
00270 
00271         /**
00272         *  @brief
00273         *    Destructor
00274         */
00275         PL_API virtual ~SNConsoleBase();
00276 
00277         /**
00278         *  @brief
00279         *    Process the syntactical correct command
00280         *
00281         *  @param[in] cCommand
00282         *    The syntactical correct command
00283         */
00284         PL_API void ProcessCommand(ConsoleCommand &cCommand);
00285 
00286         /**
00287         *  @brief
00288         *    Completes the command
00289         */
00290         PL_API void CompleteCommand();
00291 
00292 
00293     //[-------------------------------------------------------]
00294     //[ Protected data                                        ]
00295     //[-------------------------------------------------------]
00296     protected:
00297         // General
00298         EState         m_nState;        /**< Current state of console */
00299         PLCore::String m_sCommand;      /**< Current command string */
00300         PLCore::String m_sFoundCommand; /**< Found command string */
00301         PLCore::uint32 m_nCursor;       /**< Current cursor position */
00302         int            m_nSelStart;     /**< Selection cursor start position */
00303         int            m_nSelEnd;       /**< Selection cursor end position */
00304 
00305         // Commands
00306         PLCore::Array<ConsoleCommand*>                   m_lstCommands; /**< The collection of registered commands */
00307         PLCore::HashMap<PLCore::String, ConsoleCommand*> m_mapCommands; /**< Commands hash map */
00308 
00309         // Command history system
00310         PLCore::uint32                m_nCurrentCommand;    /**< Current selected command entry */
00311         PLCore::Array<PLCore::String> m_lstCommandHistory;  /**< Command history list */
00312 
00313 
00314 };
00315 
00316 
00317 //[-------------------------------------------------------]
00318 //[ Namespace                                             ]
00319 //[-------------------------------------------------------]
00320 } // PLEngine
00321 
00322 
00323 #endif // __PLENGINE_COMPOSITING_CONSOLEBASE_H__


PixelLight PixelLight 0.9.11-R1
Copyright (C) 2002-2012 by The PixelLight Team
Last modified Thu Feb 23 2012 14:09:00
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported