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.

73 lines
1.9 KiB

  1. //========= Copyright (c) 1996-2001, Valve LLC, 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. // NOTE: This has to be the last file included!
  12. #include "tier0/memdbgon.h"
  13. using namespace vgui;
  14. ScrollableEditablePanel::ScrollableEditablePanel( vgui::Panel *pParent, vgui::EditablePanel *pChild, const char *pName ) :
  15. BaseClass( pParent, pName )
  16. {
  17. m_pChild = pChild;
  18. m_pChild->SetParent( this );
  19. m_pScrollBar = new vgui::ScrollBar( this, "VerticalScrollBar", true );
  20. m_pScrollBar->SetWide( 16 );
  21. m_pScrollBar->SetAutoResize( PIN_TOPRIGHT, AUTORESIZE_DOWN, 0, 0, -16, 0 );
  22. m_pScrollBar->AddActionSignalTarget( this );
  23. }
  24. void ScrollableEditablePanel::PerformLayout()
  25. {
  26. BaseClass::PerformLayout();
  27. m_pChild->SetWide( GetWide() - m_pScrollBar->GetWide() );
  28. m_pScrollBar->SetRange( 0, m_pChild->GetTall() );
  29. m_pScrollBar->SetRangeWindow( GetTall() );
  30. if ( m_pScrollBar->GetSlider() )
  31. {
  32. m_pScrollBar->GetSlider()->SetFgColor( GetFgColor() );
  33. }
  34. if ( m_pScrollBar->GetButton(0) )
  35. {
  36. m_pScrollBar->GetButton(0)->SetFgColor( GetFgColor() );
  37. }
  38. if ( m_pScrollBar->GetButton(1) )
  39. {
  40. m_pScrollBar->GetButton(1)->SetFgColor( GetFgColor() );
  41. }
  42. }
  43. void ScrollableEditablePanel::OnMouseWheeled(int delta)
  44. {
  45. int val = m_pScrollBar->GetValue();
  46. val -= (delta * 30);
  47. m_pScrollBar->SetValue(val);
  48. }
  49. //-----------------------------------------------------------------------------
  50. // Called when the scroll bar moves
  51. //-----------------------------------------------------------------------------
  52. void ScrollableEditablePanel::OnScrollBarSliderMoved()
  53. {
  54. InvalidateLayout();
  55. int nScrollAmount = m_pScrollBar->GetValue();
  56. m_pChild->SetPos( 0, -nScrollAmount );
  57. }