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.

86 lines
2.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================
  7. #include "vgui_controls/ScrollableEditablePanel.h"
  8. #include "vgui_controls/ScrollBar.h"
  9. #include "vgui_controls/ScrollBarSlider.h"
  10. #include "vgui_controls/Button.h"
  11. #include "KeyValues.h"
  12. // NOTE: This has to be the last file included!
  13. #include "tier0/memdbgon.h"
  14. using namespace vgui;
  15. ScrollableEditablePanel::ScrollableEditablePanel( vgui::Panel *pParent, vgui::EditablePanel *pChild, const char *pName ) :
  16. BaseClass( pParent, pName )
  17. {
  18. m_pChild = pChild;
  19. m_pChild->SetParent( this );
  20. m_pScrollBar = new vgui::ScrollBar( this, "VerticalScrollBar", true );
  21. m_pScrollBar->SetWide( 16 );
  22. m_pScrollBar->SetAutoResize( PIN_TOPRIGHT, AUTORESIZE_DOWN, 0, 0, -16, 0 );
  23. m_pScrollBar->AddActionSignalTarget( this );
  24. }
  25. void ScrollableEditablePanel::ApplySettings( KeyValues *pInResourceData )
  26. {
  27. BaseClass::ApplySettings( pInResourceData );
  28. KeyValues *pScrollbarKV = pInResourceData->FindKey( "Scrollbar" );
  29. if ( pScrollbarKV )
  30. {
  31. m_pScrollBar->ApplySettings( pScrollbarKV );
  32. }
  33. }
  34. void ScrollableEditablePanel::PerformLayout()
  35. {
  36. BaseClass::PerformLayout();
  37. m_pChild->SetWide( GetWide() - m_pScrollBar->GetWide() );
  38. m_pScrollBar->SetRange( 0, m_pChild->GetTall() );
  39. m_pScrollBar->SetRangeWindow( GetTall() );
  40. if ( m_pScrollBar->GetSlider() )
  41. {
  42. m_pScrollBar->GetSlider()->SetFgColor( GetFgColor() );
  43. }
  44. if ( m_pScrollBar->GetButton(0) )
  45. {
  46. m_pScrollBar->GetButton(0)->SetFgColor( GetFgColor() );
  47. }
  48. if ( m_pScrollBar->GetButton(1) )
  49. {
  50. m_pScrollBar->GetButton(1)->SetFgColor( GetFgColor() );
  51. }
  52. }
  53. //-----------------------------------------------------------------------------
  54. // Called when the scroll bar moves
  55. //-----------------------------------------------------------------------------
  56. void ScrollableEditablePanel::OnScrollBarSliderMoved()
  57. {
  58. InvalidateLayout();
  59. int nScrollAmount = m_pScrollBar->GetValue();
  60. m_pChild->SetPos( 0, -nScrollAmount );
  61. }
  62. //-----------------------------------------------------------------------------
  63. // respond to mouse wheel events
  64. //-----------------------------------------------------------------------------
  65. void ScrollableEditablePanel::OnMouseWheeled(int delta)
  66. {
  67. int val = m_pScrollBar->GetValue();
  68. val -= (delta * 50);
  69. m_pScrollBar->SetValue( val );
  70. }