Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

152 lines
4.4 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef TEXTIMAGE_H
  8. #define TEXTIMAGE_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include <vgui/vgui.h>
  13. #include <vgui/ILocalize.h>
  14. #include <vgui_controls/Image.h>
  15. #include <utlvector.h>
  16. #include <utlsortvector.h>
  17. class KeyValues;
  18. namespace vgui
  19. {
  20. struct label_colorchange_t
  21. {
  22. Color color;
  23. int textStreamIndex;
  24. };
  25. // Used to sort the color changes into sequential order.
  26. class CColorChangeListLess
  27. {
  28. public:
  29. bool Less( const label_colorchange_t &src1, const label_colorchange_t &src2, void *pCtx )
  30. {
  31. if ( src1.textStreamIndex < src2.textStreamIndex )
  32. return true;
  33. return false;
  34. }
  35. };
  36. //-----------------------------------------------------------------------------
  37. // Purpose: Image that handles drawing of a text string
  38. //-----------------------------------------------------------------------------
  39. class TextImage : public Image
  40. {
  41. public:
  42. TextImage(const char *text);
  43. TextImage(const wchar_t *wszText);
  44. ~TextImage();
  45. public:
  46. // takes the string and looks it up in the localization file to convert it to unicode
  47. virtual void SetText(const char *text);
  48. // sets unicode text directly
  49. virtual void SetText(const wchar_t *text, bool bClearUnlocalizedSymbol = false);
  50. // get the full text in the image
  51. virtual void GetText(char *buffer, int bufferSize);
  52. virtual void GetText(wchar_t *buffer, int bufferLength);
  53. // get the text in it's unlocalized form
  54. virtual void GetUnlocalizedText(char *buffer, int bufferSize);
  55. virtual StringIndex_t GetUnlocalizedTextSymbol();
  56. // set the font of the text
  57. virtual void SetFont(vgui::HFont font);
  58. // get the font of the text
  59. virtual vgui::HFont GetFont();
  60. // set the width of the text to be drawn
  61. // use this function if the textImage is in another window to cause
  62. // the text to be truncated to the width of the window (elipsis added)
  63. void SetDrawWidth(int width);
  64. // get the width of the text to be drawn
  65. void GetDrawWidth(int &width);
  66. void ResizeImageToContent();
  67. void ResizeImageToContentMaxWidth( int nMaxWidth );
  68. // set the size of the image
  69. virtual void SetSize(int wide,int tall);
  70. // get the full size of a text string
  71. virtual void GetContentSize(int &wide, int &tall);
  72. // draws the text
  73. virtual void Paint();
  74. void SetWrap( bool bWrap );
  75. void RecalculateNewLinePositions();
  76. void SetUseFallbackFont( bool bState, HFont hFallback );
  77. void SetAllCaps( bool bAllCaps );
  78. void SetCenterWrap( bool bWrap );
  79. void RecalculateCenterWrapIndents();
  80. void SetNoShortcutSyntax( bool bNoShortcutSyntax );
  81. const wchar_t *GetUText( void ) { return _utext; }
  82. void AddColorChange( Color col, int iTextStreamIndex );
  83. void SetColorChangeStream( CUtlSortVector<label_colorchange_t,CColorChangeListLess> *pUtlVecStream );
  84. void ClearColorChangeStream( void ) { m_ColorChangeStream.Purge(); }
  85. void SetBounds( int x, int y, int w, int h );
  86. protected:
  87. // truncate the _text string to fit into the draw width
  88. void SizeText(wchar_t *tempText, int stringLength);
  89. // gets the size of a specified piece of text
  90. virtual void GetTextSize(int &wide, int &tall);
  91. private:
  92. void RecalculateEllipsesPosition();
  93. void SetUseAsianWordWrapping();
  94. wchar_t *_utext; // unicode version of the text
  95. short _textBufferLen; // size of the text buffer
  96. short _textLen; // length of the text string
  97. vgui::HFont _font; // font of the text string
  98. vgui::HFont _fallbackFont;
  99. int _drawWidth; // this is the width of the window we are drawing into.
  100. // if there is not enough room truncate the txt and add an elipsis
  101. StringIndex_t _unlocalizedTextSymbol; // store off the unlocalized text index for build mode
  102. wchar_t *m_pwszEllipsesPosition;
  103. bool m_bRecalculateTruncation : 1;
  104. bool m_bWrap : 1;
  105. bool m_bWrapCenter : 1; // Separate from m_bWrap to ensure it doesn't break legacy code.
  106. bool m_bUseFallbackFont : 1;
  107. bool m_bRenderUsingFallbackFont : 1;
  108. bool m_bAllCaps : 1;
  109. bool m_bNoShortcutSyntax : 1;
  110. bool m_bUseAsianWordWrapping : 1;
  111. CUtlVector<wchar_t *> m_LineBreaks; // an array that holds the index in the buffer to wrap lines at
  112. CUtlVector<int> m_LineXIndent; // For centered word wrap. The X indent for each line.
  113. CUtlSortVector<label_colorchange_t,CColorChangeListLess> m_ColorChangeStream;
  114. };
  115. } // namespace vgui
  116. #endif // TEXTIMAGE_H