Team Fortress 2 Source Code as on 22/4/2020
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.

119 lines
2.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef MOUSEOVERHTMLBUTTON_H
  8. #define MOUSEOVERHTMLBUTTON_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. //-----------------------------------------------------------------------------
  13. // Purpose: Triggers a new html page when the mouse goes over the button
  14. //-----------------------------------------------------------------------------
  15. class MouseOverHTMLButton : public vgui::Button
  16. {
  17. public:
  18. MouseOverHTMLButton(vgui::Panel *parent, const char *panelName, vgui::HTML *html, const char *page) :
  19. Button( parent, panelName, "MouseOverHTMLButton")
  20. {
  21. m_pHTML = html;
  22. m_iClass = 0;
  23. m_iIndex = -1;
  24. m_bAddShortCut = true;
  25. if ( page )
  26. {
  27. Q_strncpy( m_sPage, page, sizeof( m_sPage ) );
  28. }
  29. else
  30. {
  31. memset(m_sPage, 0x0, sizeof( m_sPage ) );
  32. }
  33. }
  34. void SetClass(int pClass, int index) { m_iClass = pClass; m_iIndex = index;}
  35. int GetClass() { return m_iClass; }
  36. void SetAddHotKey( bool state ) { m_bAddShortCut = state; }
  37. void SetPage( const char *page )
  38. {
  39. if ( page )
  40. {
  41. Q_strncpy( m_sPage, page, sizeof( m_sPage ) );
  42. }
  43. else
  44. {
  45. memset(m_sPage, 0x0, sizeof( m_sPage ) );
  46. }
  47. }
  48. void SetHTML( vgui::HTML *html)
  49. {
  50. m_pHTML = html;
  51. }
  52. private:
  53. virtual void OnCursorEntered()
  54. {
  55. Button::OnCursorEntered();
  56. if ( m_pHTML && strlen(m_sPage) > 0 )
  57. {
  58. m_pHTML->OpenURL(m_sPage);
  59. }
  60. }
  61. virtual void SetText(const char *text)
  62. {
  63. if ( m_iIndex != -1 )
  64. {
  65. wchar_t newText[ 128 ];
  66. wchar_t localizeText[ 128 ];
  67. wchar_t *ansiLocal;
  68. if ( text[0] == '#' && ( ansiLocal = g_pVGuiLocalize->Find( text ) ) )
  69. {
  70. // wcsncpy will crash if ansiLocal is null... *sigh*
  71. wcsncpy(localizeText, ansiLocal, sizeof(localizeText)/sizeof(wchar_t));
  72. }
  73. else
  74. {
  75. g_pVGuiLocalize->ConvertANSIToUnicode( text, localizeText, sizeof( localizeText ) );
  76. }
  77. if ( m_bAddShortCut )
  78. {
  79. #ifdef WIN32
  80. _snwprintf( newText, sizeof( newText )/ sizeof( wchar_t ), L"&%i %s", m_iIndex, localizeText);
  81. #else
  82. _snwprintf( newText, sizeof( newText )/ sizeof( wchar_t ), L"&%i %S", m_iIndex, localizeText);
  83. #endif
  84. }
  85. else
  86. {
  87. memcpy( newText, localizeText, sizeof( newText ) );
  88. }
  89. Button::SetText( newText );
  90. }
  91. else
  92. {
  93. Button::SetText( text );
  94. }
  95. }
  96. vgui::HTML *m_pHTML;
  97. char m_sPage[ 255 ];
  98. int m_iClass;
  99. int m_iIndex;
  100. bool m_bAddShortCut;
  101. };
  102. #endif // MOUSEOVERHTMLBUTTON_H