src/tools/tConsole.h

Go to the documentation of this file.
00001 /*
00002 
00003 *************************************************************************
00004 
00005 ArmageTron -- Just another Tron Lightcycle Game in 3D.
00006 Copyright (C) 2000  Manuel Moos (manuel@moosnet.de)
00007 
00008 **************************************************************************
00009 
00010 This program is free software; you can redistribute it and/or
00011 modify it under the terms of the GNU General Public License
00012 as published by the Free Software Foundation; either version 2
00013 of the License, or (at your option) any later version.
00014 
00015 This program is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 GNU General Public License for more details.
00019 
00020 You should have received a copy of the GNU General Public License
00021 along with this program; if not, write to the Free Software
00022 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00023   
00024 ***************************************************************************
00025 
00026 */
00027 
00028 #ifndef ArmageTron_consoleBase_H
00029 #define ArmageTron_consoleBase_H
00030 
00031 #include "tString.h"
00032 #include "defs.h"
00033 #include "tLinkedList.h"
00034 
00035 class tOutput;
00036 
00038 class tConsoleFilter: public tListItem< tConsoleFilter >
00039 {
00040 public:
00041     tConsoleFilter();
00042     ~tConsoleFilter();
00043 
00045     inline void FilterLine( tString& line )
00046     {
00047         DoFilterLine( line );
00048     }
00049 
00051     inline void FilterElement( tString& element )
00052     {
00053         DoFilterElement( element );
00054     }
00055 
00056     inline int GetPriority() const
00057     {
00058         return DoGetPriority();
00059     }
00060 private:
00061     // the functions that do the real work
00062     virtual void DoFilterLine   ( tString& line         );              
00063     virtual void DoFilterElement( tString& element      );              
00064 
00065     virtual int DoGetPriority() const;                                          
00066 };
00067 
00068 // console class logging various messages
00069 class tConsole
00070 {
00071 public:
00072     // callback for messages the user should read
00073     typedef bool MessageCallback(const tOutput& message, const tOutput& interpretation, REAL timeout);
00074 
00075     // idle callback; called from various spots when the progam is waiting.
00076     // return true if the waiting should be aborted
00077     typedef bool IdleCallback();
00078 
00079     virtual ~tConsole();
00080 
00081     tConsole & Print(tString s);
00082 
00083     template<class T> tConsole & operator<<(const T&x){
00084         tColoredString s;
00085         s << x;
00086         return Print(s);
00087     }
00088 
00089     void CenterDisplay(tString s,REAL timeout=5,REAL r=1,REAL g=1,REAL b=1);
00090 
00091     // give a message to the user
00092     static bool Message(const tOutput& message, const tOutput& interpetation, REAL timeout = -1);
00093 
00094     // idle around a bit (return value true: abort whatever you're doing)
00095     static bool Idle();
00096 
00097     virtual tString ColorString(REAL r, REAL g, REAL b) const;
00098 
00099     static void RegisterMessageCallback(MessageCallback *callback);
00100     static void RegisterIdleCallback(IdleCallback *callback);
00101 
00102 protected:
00103     static void RegisterBetterConsole(tConsole *better);
00104 
00105 private:
00106     static tConsole *s_betterConsole;
00107 
00108     virtual tConsole & DoPrint(const tString& s);
00109     virtual void DoCenterDisplay(const tString& s,REAL timeout=5,REAL r=1,REAL g=1,REAL b=1);
00110 };
00111 
00112 extern tConsole con;
00113 
00114 #endif

Generated on Sat Mar 15 22:55:59 2008 for Armagetron Advanced by  doxygen 1.5.4