Torque3D Documentation / _generateds / guiMessageVectorCtrl.h

guiMessageVectorCtrl.h

Engine/source/gui/game/guiMessageVectorCtrl.h

More...

Classes:

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 _GUIMESSAGEVECTORCTRL_H_
 25#define _GUIMESSAGEVECTORCTRL_H_
 26
 27#ifndef _GUICONTROL_H_
 28#include "gui/core/guiControl.h"
 29#endif
 30#ifndef _MESSAGEVECTOR_H_
 31#include "gui/utility/messageVector.h"
 32#endif
 33
 34/// Render a MessageVector (chat HUD)
 35///
 36/// This renders messages from a MessageVector; the important thing
 37/// here is that the MessageVector holds all the messages we care
 38/// about, while we can destroy and create these GUI controls as
 39/// needed. (For instance, Tribes 2 used seperate GuiMessageVectorCtrl
 40/// controls in the different HUD modes.)
 41class GuiMessageVectorCtrl : public GuiControl
 42{
 43   typedef GuiControl Parent;
 44
 45   //-------------------------------------- Public interfaces...
 46  public:
 47   struct SpecialMarkers {
 48      struct Special {
 49         S32 specialType;
 50         S32 start;
 51         S32 end;
 52      };
 53
 54      U32      numSpecials;
 55      Special* specials;
 56   };
 57
 58   GuiMessageVectorCtrl();
 59   ~GuiMessageVectorCtrl();
 60
 61   bool isAttached() const;
 62   bool attach(MessageVector*);
 63   void detach();
 64
 65   // Gui control overrides
 66  protected:
 67   bool onAdd();
 68   void onRemove();
 69
 70   bool onWake();
 71   void onSleep();
 72   void onRender(Point2I offset, const RectI &updateRect);
 73   void inspectPostApply();
 74   void parentResized(const RectI& oldParentRect, const RectI& newParentRect);
 75
 76   void onMouseUp(const GuiEvent &event);
 77   void onMouseDown(const GuiEvent &event);
 78//   void onMouseMove(const GuiEvent &event);
 79
 80   // Overrideables
 81  protected:
 82   virtual void lineInserted(const U32);
 83   virtual void lineDeleted(const U32);
 84   virtual void vectorDeleted();
 85
 86   MessageVector* mMessageVector;
 87
 88   // Font resource
 89  protected:
 90   U32             mMinSensibleWidth;
 91
 92   U32             mLineSpacingPixels;
 93   U32             mLineContinuationIndent;
 94
 95   StringTableEntry mAllowedMatches[16];
 96   ColorI           mSpecialColor;
 97
 98   U32   mMaxColorIndex;
 99
100   bool mMouseDown;
101   S32  mMouseSpecialLine;
102   S32  mMouseSpecialRef;
103
104   /// Derived classes must keep this set of variables consistent if they
105   ///  use this classes onRender.  Note that this has the fairly large
106   ///  disadvantage of requiring lots of ugly, tiny mem allocs.  A rewrite
107   ///  to a more memory friendly version might be a good idea...
108   struct LineWrapping {
109      struct SEPair {
110         S32 start;
111         S32 end;
112      };
113
114      U32     numLines;
115      SEPair* startEndPairs;     /// start[linex] = startEndPairs[linex*2+0]
116                                 /// end[linex]   = startEndPairs[linex*2+1]
117                                 /// if end < start, line is empty...
118   };
119
120   struct TextElement {
121      TextElement* nextInLine;
122      TextElement* nextPhysicalLine;
123
124      S32 specialReference;  /// if (!= -1), indicates a special reference
125
126      S32 start;
127      S32 end;
128   };
129   struct LineElement {
130      U32 physicalLineStart;
131
132      TextElement* headLineElements;
133   };
134
135   Vector<LineWrapping>   mLineWrappings;
136   Vector<SpecialMarkers> mSpecialMarkers;
137   Vector<LineElement>    mLineElements;
138
139   void createLineWrapping(LineWrapping&, const char*);
140   void createSpecialMarkers(SpecialMarkers&, const char*);
141   void createLineElement(LineElement&, LineWrapping&, SpecialMarkers&);
142
143   void findSpecialFromCoord(const Point2I&, S32*, S32*);
144
145  public:
146   void callbackRouter(const MessageVector::MessageCode, const U32);
147
148  public:
149   
150   DECLARE_CONOBJECT(GuiMessageVectorCtrl);
151   DECLARE_CATEGORY( "Gui Game" );
152   DECLARE_DESCRIPTION( "A chat HUD control that displays messages from a MessageVector." );
153   
154   static void initPersistFields();
155};
156
157#endif  // _H_GUIMESSAGEVECTORCTRL_
158