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.

189 lines
5.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "cbase.h"
  7. #include <convar.h>
  8. #include "cdll_int.h"
  9. #include <ienginevgui.h>
  10. #include "filesystem.h"
  11. #include <vgui/ISystem.h>
  12. #include "career_button.h"
  13. #include <vgui_controls/Label.h>
  14. #include <vgui_controls/URLLabel.h>
  15. #include <vgui_controls/ComboBox.h>
  16. #include <vgui/ISurface.h>
  17. #include <vgui/ILocalize.h>
  18. #include <vgui_controls/ScrollBar.h>
  19. #include <vgui_controls/BuildGroup.h>
  20. #include <vgui_controls/ImageList.h>
  21. #include <vgui_controls/TextImage.h>
  22. #include <vgui_controls/Button.h>
  23. #include "KeyValues.h"
  24. using namespace vgui;
  25. #ifndef _DEBUG
  26. #define PROPORTIONAL_CAREER_FRAMES 1
  27. #endif
  28. //--------------------------------------------------------------------------------------------------------------
  29. //--------------------------------------------------------------------------------------------------------------
  30. CCareerButton::CCareerButton(vgui::Panel *parent, const char *buttonName, const char *buttonText, const char *image, bool textFirst) : BaseClass( parent, buttonName, "" )
  31. {
  32. m_armedBorder = NULL;
  33. m_textImage = new TextImage(buttonText);
  34. m_image = scheme()->GetImage(image, true);
  35. m_textFirst = textFirst;
  36. }
  37. //--------------------------------------------------------------------------------------------------------------
  38. void CCareerButton::SetImage( const char *image )
  39. {
  40. m_image = scheme()->GetImage(image, true);
  41. }
  42. //--------------------------------------------------------------------------------------------------------------
  43. void CCareerButton::Paint()
  44. {
  45. int buttonWide, buttonTall;
  46. GetSize(buttonWide, buttonTall);
  47. int imageWide, imageTall;
  48. if ( m_image )
  49. {
  50. m_image->GetSize(imageWide, imageTall);
  51. }
  52. else
  53. {
  54. imageWide = imageTall = 0;
  55. }
  56. int textOffset = m_textPad;
  57. if (m_textFirst)
  58. {
  59. if ( m_image )
  60. {
  61. m_image->SetPos(buttonWide - imageWide - m_imagePad, (buttonTall - imageTall)/2);
  62. m_image->Paint();
  63. }
  64. }
  65. else
  66. {
  67. if ( m_image )
  68. {
  69. m_image->SetPos(m_imagePad, (buttonTall - imageTall)/2);
  70. m_image->Paint();
  71. }
  72. textOffset += imageWide + m_imagePad;
  73. }
  74. int textTall, textWide;
  75. m_textImage->GetSize(textWide, textTall);
  76. int textSpace = buttonWide - imageWide - m_imagePad - 2*m_textPad;
  77. if ( IsEnabled() )
  78. {
  79. m_textImage->SetColor( m_textNormalColor );
  80. }
  81. else
  82. {
  83. m_textImage->SetColor( m_textDisabledColor );
  84. }
  85. m_textImage->SetPos(textOffset + (textSpace - textWide)/2, (buttonTall - textTall)/2);
  86. m_textImage->Paint();
  87. if (HasFocus() && IsEnabled() )
  88. {
  89. int x0, y0, x1, y1;
  90. x0 = 3, y0 = 3, x1 = buttonWide - 4 , y1 = buttonTall - 2;
  91. DrawFocusBorder(x0, y0, x1, y1);
  92. }
  93. }
  94. //--------------------------------------------------------------------------------------------------------------
  95. void CCareerButton::SetArmedBorder(IBorder *border)
  96. {
  97. m_armedBorder = border;
  98. InvalidateLayout(false);
  99. }
  100. //--------------------------------------------------------------------------------------------------------------
  101. IBorder* CCareerButton::GetBorder(bool depressed, bool armed, bool selected, bool keyfocus)
  102. {
  103. if ( /*_buttonBorderEnabled &&*/ armed && !depressed && IsEnabled() )
  104. {
  105. return m_armedBorder;
  106. }
  107. return BaseClass::GetBorder( depressed, armed, selected, keyfocus );
  108. }
  109. //--------------------------------------------------------------------------------------------------------------
  110. void CCareerButton::ApplySchemeSettings( vgui::IScheme *pScheme )
  111. {
  112. BaseClass::ApplySchemeSettings( pScheme );
  113. SetDefaultBorder( pScheme->GetBorder("CareerButtonBorder") );
  114. SetDepressedBorder( pScheme->GetBorder("CareerButtonDepressedBorder") );
  115. m_armedBorder = pScheme->GetBorder("CareerButtonArmedBorder");
  116. m_textNormalColor = pScheme->GetColor( "Label.TextBrightColor", Color(255, 255, 255, 255) );
  117. m_textDisabledColor = pScheme->GetColor( "Label.DisabledFgColor2", Color(128, 128, 128, 255) );
  118. m_textImage->SetColor( m_textNormalColor );
  119. if ( m_image )
  120. {
  121. m_image->SetColor( GetFgColor() );
  122. }
  123. m_textImage->SetFont( pScheme->GetFont( "Default", IsProportional() ) );
  124. m_textPad = atoi(pScheme->GetResourceString( "CareerButtonTextPad" ));
  125. m_imagePad = atoi(pScheme->GetResourceString( "CareerButtonImagePad" ));
  126. if (IsProportional())
  127. {
  128. m_textPad = scheme()->GetProportionalScaledValueEx( GetScheme(),m_textPad);
  129. m_imagePad = scheme()->GetProportionalScaledValueEx( GetScheme(),m_imagePad);
  130. }
  131. const int BufLen = 128;
  132. char buf[BufLen];
  133. GetText(buf, BufLen);
  134. m_textImage->SetText(buf);
  135. m_textImage->ResizeImageToContent();
  136. int buttonWide, buttonTall;
  137. GetSize(buttonWide, buttonTall);
  138. int imageWide, imageTall;
  139. if ( m_image )
  140. {
  141. m_image->GetSize(imageWide, imageTall);
  142. }
  143. else
  144. {
  145. imageWide = imageTall = 0;
  146. }
  147. int textSpace = buttonWide - imageWide - m_imagePad - 2*m_textPad;
  148. int textWide, textTall;
  149. m_textImage->GetContentSize(textWide, textTall);
  150. if (textSpace < textWide)
  151. m_textImage->SetSize(textSpace, textTall);
  152. Color bgColor = pScheme->GetColor( "CareerButtonBG", Color(0, 0, 0, 0) );
  153. SetDefaultColor( bgColor, bgColor );
  154. SetArmedColor( bgColor, bgColor );
  155. SetDepressedColor( bgColor, bgColor );
  156. }
  157. //--------------------------------------------------------------------------------------------------------------