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.

246 lines
7.2 KiB

  1. //========= Copyright 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef LABEL_H
  8. #define LABEL_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "utlvector.h"
  13. #include "vgui/vgui.h"
  14. #include "vgui_controls/Panel.h"
  15. #include "vgui_controls/PHandle.h"
  16. #include "dmxloader/dmxelement.h"
  17. namespace vgui
  18. {
  19. //-----------------------------------------------------------------------------
  20. // Purpose: Contains and displays a set of images
  21. // By default starts with one TextImage
  22. //-----------------------------------------------------------------------------
  23. class Label : public Panel
  24. {
  25. DECLARE_CLASS_SIMPLE( Label, Panel );
  26. DECLARE_DMXELEMENT_UNPACK_NAMESPACE(vgui);
  27. public:
  28. // Constructors
  29. Label(Panel *parent, const char *panelName, const char *text);
  30. Label(Panel *parent, const char *panelName, const wchar_t *wszText);
  31. ~Label();
  32. public:
  33. // Take the string and looks it up in the localization file to convert it to unicode
  34. virtual void SetText(const char *tokenName);
  35. // Set unicode text directly
  36. virtual void SetText(const wchar_t *unicodeString, bool bClearUnlocalizedSymbol = false );
  37. // Get the current text
  38. virtual void GetText(OUT_Z_BYTECAP(bufferLen) char *textOut, int bufferLen);
  39. virtual void GetText(OUT_Z_BYTECAP(bufLenInBytes) wchar_t *textOut, int bufLenInBytes);
  40. // Content alignment
  41. // Get the size of the content within the label
  42. virtual void GetContentSize(int &wide, int &tall);
  43. // Set how the content aligns itself within the label
  44. // alignment code, used to determine how the images are layed out within the Label
  45. enum Alignment
  46. {
  47. a_northwest = 0,
  48. a_north,
  49. a_northeast,
  50. a_west,
  51. a_center,
  52. a_east,
  53. a_southwest,
  54. a_south,
  55. a_southeast,
  56. };
  57. virtual void SetContentAlignment(Alignment alignment);
  58. virtual void SetEnabled(bool state);
  59. // Additional offset at the Start of the text (from whichever sides it is aligned)
  60. virtual void SetTextInset(int xInset, int yInset);
  61. virtual void GetTextInset(int *xInset, int *yInset );
  62. // Text colors
  63. virtual void SetFgColor(Color color);
  64. virtual Color GetFgColor();
  65. // colors to use when the label is disabled
  66. virtual void SetDisabledFgColor1(Color color);
  67. virtual void SetDisabledFgColor2(Color color);
  68. virtual Color GetDisabledFgColor1();
  69. virtual Color GetDisabledFgColor2();
  70. // Set whether the text is displayed bright or dull
  71. enum EColorState
  72. {
  73. CS_NORMAL,
  74. CS_DULL,
  75. CS_BRIGHT,
  76. };
  77. virtual void SetTextColorState(EColorState state);
  78. // Font
  79. virtual void SetFont(HFont font);
  80. virtual HFont GetFont();
  81. // Hotkey
  82. virtual Panel *HasHotkey(wchar_t key);
  83. virtual void SetHotkey(wchar_t key);
  84. virtual wchar_t GetHotKey();
  85. // Labels can be associated with controls, and alter behaviour based on the associates behaviour
  86. // If the associate is disabled, so are we
  87. // If the associate has focus, we may alter how we draw
  88. // If we get a hotkey press or focus message, we forward the focus to the associate
  89. virtual void SetAssociatedControl(Panel *control);
  90. // Multiple image handling
  91. // Images are drawn from left to right across the label, ordered by index
  92. // By default there is a TextImage in position 0 (see GetTextImage()/SetTextImageIndex())
  93. virtual int AddImage(IImage *image, int preOffset); // Return the index the image was placed in
  94. virtual void SetImage(IImage *image, int preOffset ); // Clears all images and sets the only remaining image to the passed in image
  95. virtual void SetImageAtIndex(int index, IImage *image, int preOffset);
  96. virtual void SetImagePreOffset(int index, int preOffset); // Set the offset in pixels before the image
  97. virtual IImage *GetImageAtIndex(int index);
  98. virtual int GetImageCount();
  99. virtual void ClearImages();
  100. virtual void ResetToSimpleTextImage();
  101. // fixes the layout bounds of the image within the label
  102. virtual void SetImageBounds(int index, int x, int width);
  103. // Teturns a pointer to the default text image
  104. virtual TextImage *GetTextImage();
  105. // Moves where the default text image is within the image array (it starts in position 0)
  106. // Setting it to -1 removes it from the image list
  107. // Returns the index the default text image was previously in
  108. virtual int SetTextImageIndex(int newIndex);
  109. // Message handling
  110. // outputData - keyName is the name of the attribute requested.
  111. // for Labels "text" is an option that returns the default text image text
  112. // returns true on success in finding the requested value. false on failure.
  113. virtual bool RequestInfo(KeyValues *outputData);
  114. /* INFO HANDLING
  115. "GetText"
  116. returns:
  117. "text" - text contained in the label
  118. */
  119. /* CUSTOM MESSAGE HANDLING
  120. "SetText"
  121. input: "text" - label text is set to be this string
  122. */
  123. virtual void SizeToContents();
  124. // the +8 is padding to the content size
  125. // the code which uses it should really set that itself;
  126. // however a lot of existing code relies on this
  127. enum Padding
  128. {
  129. Content = 8,
  130. };
  131. void SetWrap( bool bWrap );
  132. void SetCenterWrap( bool bWrap );
  133. void SetNoShortcutSyntax( bool bNoShortcutSyntax );
  134. void SetAllCaps( bool bAllCaps );
  135. virtual void GetSizerMinimumSize(int &wide, int &tall);
  136. protected:
  137. virtual void PerformLayout();
  138. virtual wchar_t CalculateHotkey(const char *text);
  139. virtual wchar_t CalculateHotkey(const wchar_t *text);
  140. virtual void ComputeAlignment(int &tx0, int &ty0, int &tx1, int &ty1);
  141. virtual void Paint();
  142. MESSAGE_FUNC_PARAMS( OnSetText, "SetText", params );
  143. virtual void DrawDashedLine(int x0, int y0, int x1, int y1, int dashLen, int gapLen);
  144. virtual void OnRequestFocus(VPANEL subFocus, VPANEL defaultPanel);
  145. MESSAGE_FUNC( OnHotkeyPressed, "Hotkey" );
  146. virtual void OnMousePressed(MouseCode code);
  147. virtual void OnSizeChanged(int wide, int tall);
  148. // makes sure that the maxIndex will be a valid index
  149. virtual void EnsureImageCapacity(int maxIndex);
  150. // editing
  151. virtual void ApplySchemeSettings(IScheme *pScheme);
  152. public:
  153. virtual void GetSettings( KeyValues *outResourceData );
  154. virtual void ApplySettings( KeyValues *inResourceData );
  155. protected:
  156. virtual const char *GetDescription( void );
  157. MESSAGE_FUNC_PARAMS( OnDialogVariablesChanged, "DialogVariables", dialogVariables );
  158. void HandleAutoSizing( void );
  159. // Derived can override to, e.g., recenter text image text if there is space.
  160. virtual void RepositionTextImage( int &x, int &y, TextImage *pTextImage ) {}
  161. Alignment _contentAlignment;
  162. private:
  163. void Init();
  164. TextImage *_textImage; // this is the textImage, if the full text will not
  165. // fit we put as much as we can and add an elipsis (...)
  166. struct TImageInfo
  167. {
  168. IImage *image;
  169. short offset;
  170. short xpos;
  171. short width;
  172. };
  173. CUtlVector<TImageInfo> _imageDar;
  174. int _textInset[2];
  175. Color _disabledFgColor1;
  176. Color _disabledFgColor2;
  177. Color _associateColor;
  178. int _textImageIndex; // index in the image array that the default _textimage resides
  179. EColorState _textColorState;
  180. PHandle _associate;
  181. char *_associateName;
  182. char *_fontOverrideName;
  183. wchar_t _hotkey; // the hotkey contained in the text
  184. bool m_bWrap;
  185. bool m_bCenterWrap;
  186. bool m_bAllCaps;
  187. bool m_bAutoWideToContents;
  188. bool m_bAutoWideDirty;
  189. bool m_bAutoTallToContents;
  190. bool m_bAutoTallDirty;
  191. bool m_bNoShortcutSyntax;
  192. bool m_bUseProportionalInsets;
  193. };
  194. } // namespace vgui
  195. #endif // LABEL_H