guiMessageVectorCtrl.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _GUIMESSAGEVECTORCTRL_H_
  23. #define _GUIMESSAGEVECTORCTRL_H_
  24. #ifndef _GUICONTROL_H_
  25. #include "gui/core/guiControl.h"
  26. #endif
  27. #ifndef _MESSAGEVECTOR_H_
  28. #include "gui/utility/messageVector.h"
  29. #endif
  30. /// Render a MessageVector (chat HUD)
  31. ///
  32. /// This renders messages from a MessageVector; the important thing
  33. /// here is that the MessageVector holds all the messages we care
  34. /// about, while we can destroy and create these GUI controls as
  35. /// needed. (For instance, Tribes 2 used seperate GuiMessageVectorCtrl
  36. /// controls in the different HUD modes.)
  37. class GuiMessageVectorCtrl : public GuiControl
  38. {
  39. typedef GuiControl Parent;
  40. //-------------------------------------- Public interfaces...
  41. public:
  42. struct SpecialMarkers {
  43. struct Special {
  44. S32 specialType;
  45. S32 start;
  46. S32 end;
  47. };
  48. U32 numSpecials;
  49. Special* specials;
  50. };
  51. GuiMessageVectorCtrl();
  52. ~GuiMessageVectorCtrl();
  53. bool isAttached() const;
  54. bool attach(MessageVector*);
  55. void detach();
  56. // Gui control overrides
  57. protected:
  58. bool onAdd();
  59. void onRemove();
  60. bool onWake();
  61. void onSleep();
  62. void onRender(Point2I offset, const RectI &updateRect);
  63. void inspectPostApply();
  64. void parentResized(const RectI& oldParentRect, const RectI& newParentRect);
  65. void onMouseUp(const GuiEvent &event);
  66. void onMouseDown(const GuiEvent &event);
  67. // void onMouseMove(const GuiEvent &event);
  68. // Overrideables
  69. protected:
  70. virtual void lineInserted(const U32);
  71. virtual void lineDeleted(const U32);
  72. virtual void vectorDeleted();
  73. MessageVector* mMessageVector;
  74. // Font resource
  75. protected:
  76. U32 mMinSensibleWidth;
  77. U32 mLineSpacingPixels;
  78. U32 mLineContinuationIndent;
  79. StringTableEntry mAllowedMatches[16];
  80. ColorI mSpecialColor;
  81. U32 mMaxColorIndex;
  82. bool mMouseDown;
  83. S32 mMouseSpecialLine;
  84. S32 mMouseSpecialRef;
  85. /// Derived classes must keep this set of variables consistent if they
  86. /// use this classes onRender. Note that this has the fairly large
  87. /// disadvantage of requiring lots of ugly, tiny mem allocs. A rewrite
  88. /// to a more memory friendly version might be a good idea...
  89. struct LineWrapping {
  90. struct SEPair {
  91. S32 start;
  92. S32 end;
  93. };
  94. U32 numLines;
  95. SEPair* startEndPairs; /// start[linex] = startEndPairs[linex*2+0]
  96. /// end[linex] = startEndPairs[linex*2+1]
  97. /// if end < start, line is empty...
  98. };
  99. struct TextElement {
  100. TextElement* nextInLine;
  101. TextElement* nextPhysicalLine;
  102. S32 specialReference; /// if (!= -1), indicates a special reference
  103. S32 start;
  104. S32 end;
  105. };
  106. struct LineElement {
  107. U32 physicalLineStart;
  108. TextElement* headLineElements;
  109. };
  110. Vector<LineWrapping> mLineWrappings;
  111. Vector<SpecialMarkers> mSpecialMarkers;
  112. Vector<LineElement> mLineElements;
  113. void createLineWrapping(LineWrapping&, const char*);
  114. void createSpecialMarkers(SpecialMarkers&, const char*);
  115. void createLineElement(LineElement&, LineWrapping&, SpecialMarkers&);
  116. void findSpecialFromCoord(const Point2I&, S32*, S32*);
  117. public:
  118. void callbackRouter(const MessageVector::MessageCode, const U32);
  119. public:
  120. DECLARE_CONOBJECT(GuiMessageVectorCtrl);
  121. DECLARE_CATEGORY( "Gui Game" );
  122. DECLARE_DESCRIPTION( "A chat HUD control that displays messages from a MessageVector." );
  123. static void initPersistFields();
  124. };
  125. #endif // _H_GUIMESSAGEVECTORCTRL_