Torque3D Documentation / _generateds / messageVector.h

messageVector.h

Engine/source/gui/utility/messageVector.h

More...

Classes:

class

Store a list of chat messages.

Detailed Description

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#ifndef _MESSAGEVECTOR_H_
 25#define _MESSAGEVECTOR_H_
 26
 27#ifndef _PLATFORM_H_
 28#include "platform/platform.h"
 29#endif
 30#ifndef _TVECTOR_H_
 31#include "core/util/tVector.h"
 32#endif
 33#ifndef _SIMBASE_H_
 34#include "console/simBase.h"
 35#endif
 36
 37/// Store a list of chat messages.
 38///
 39/// This is responsible for managing messages which appear in the chat HUD.
 40///
 41/// @see GuiMessageVectorCtrl for more details on how this is used.
 42class MessageVector : public SimObject
 43{
 44   typedef SimObject Parent;
 45
 46   //-------------------------------------- Public interface...
 47  public:
 48   MessageVector();
 49   ~MessageVector();
 50
 51  public:
 52   struct MessageLine {
 53      char* message;
 54      S32   messageTag;
 55   };
 56
 57
 58   // Spectator registration...
 59  public:
 60   enum MessageCode {
 61      LineInserted   = 0,
 62      LineDeleted    = 1,
 63
 64      VectorDeletion = 2
 65   };
 66
 67   typedef void (*SpectatorCallback)(void *            spectatorKey,
 68                                     const MessageCode code,
 69                                     const U32         argument);
 70
 71   void registerSpectator(SpectatorCallback, void * spectatorKey);
 72   void unregisterSpectator(void *spectatorKey);
 73
 74   // Query functions
 75  public:
 76   U32                getNumLines() const;
 77   const MessageLine& getLine(const U32 line) const;
 78
 79   // Mutators
 80  public:
 81   void pushBackLine(const char*, const S32);
 82   void popBackLine();
 83   void pushFrontLine(const char*, const S32);
 84   void popFrontLine();
 85   void clear();
 86
 87   virtual void insertLine(const U32 position, const char*, const S32);
 88   virtual void deleteLine(const U32);
 89
 90   bool dump( const char* filename, const char* header = NULL );
 91
 92
 93   //-------------------------------------- Internal interface
 94  protected:
 95   bool onAdd();
 96   void onRemove();
 97
 98  private:
 99   struct SpectatorRef {
100      SpectatorCallback callback;
101      void *               key;
102   };
103
104   Vector<MessageLine>  mMessageLines;
105
106   Vector<SpectatorRef> mSpectators;
107   void spectatorMessage(MessageCode, const U32 arg);
108
109  public:
110   DECLARE_CONOBJECT(MessageVector);
111   static void initPersistFields();
112};
113
114
115//--------------------------------------------------------------------------
116inline U32 MessageVector::getNumLines() const
117{
118   return mMessageLines.size();
119}
120
121//--------------------------------------------------------------------------
122inline const MessageVector::MessageLine& MessageVector::getLine(const U32 line) const
123{
124   AssertFatal(line < mMessageLines.size(), "MessageVector::getLine: out of bounds line index");
125   return mMessageLines[line];
126}
127
128#endif  // _H_GUICHATVECTOR_
129