ScrollBar.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. GWEN
  3. Copyright (c) 2010 Facepunch Studios
  4. See license in Gwen.h
  5. */
  6. #include "Gwen/Controls/ScrollBar.h"
  7. #include "Gwen/Controls/ScrollBarButton.h"
  8. #include "Gwen/Controls/ScrollBarBar.h"
  9. using namespace Gwen;
  10. using namespace Gwen::Controls;
  11. using namespace Gwen::ControlsInternal;
  12. GWEN_CONTROL_CONSTRUCTOR( BaseScrollBar )
  13. {
  14. for (int i = 0; i < 2; i++)
  15. {
  16. m_ScrollButton[i] = new ScrollBarButton( this );
  17. }
  18. m_Bar = new ScrollBarBar( this );
  19. SetBounds( 0, 0, 15, 15 );
  20. m_bDepressed = false;
  21. m_fScrolledAmount = 0;
  22. m_fContentSize = 0;
  23. m_fViewableContentSize = 0;
  24. SetNudgeAmount( 20 );
  25. }
  26. void BaseScrollBar::Render( Skin::Base* skin )
  27. {
  28. skin->DrawScrollBar( this, false, m_bDepressed );
  29. }
  30. void BaseScrollBar::OnBarMoved( Controls::Base* /*control*/ )
  31. {
  32. onBarMoved.Call( this );
  33. }
  34. void BaseScrollBar::BarMovedNotification()
  35. {
  36. OnBarMoved( this );
  37. }
  38. void BaseScrollBar::SetContentSize( float size )
  39. {
  40. if ( m_fContentSize != size )
  41. {
  42. Invalidate();
  43. }
  44. m_fContentSize = size;
  45. }
  46. void BaseScrollBar::SetViewableContentSize( float size )
  47. {
  48. if ( m_fViewableContentSize != size )
  49. Invalidate();
  50. m_fViewableContentSize = size;
  51. }
  52. bool BaseScrollBar::SetScrolledAmount( float amount, bool /*forceUpdate*/ )
  53. {
  54. if ( m_fScrolledAmount == amount ) return false;
  55. m_fScrolledAmount = amount;
  56. Invalidate();
  57. BarMovedNotification();
  58. return true;
  59. }