ProgressBar.cpp 843 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. GWEN
  3. Copyright (c) 2010 Facepunch Studios
  4. See license in Gwen.h
  5. */
  6. #include "Gwen/Controls/ScrollControl.h"
  7. #include "Gwen/Controls/ProgressBar.h"
  8. #include "Gwen/Utility.h"
  9. using namespace Gwen;
  10. using namespace Gwen::Controls;
  11. GWEN_CONTROL_CONSTRUCTOR( ProgressBar )
  12. {
  13. SetMouseInputEnabled( true );
  14. SetBounds( Gwen::Rect( 0, 0, 128, 32 ) );
  15. SetTextPadding( Padding( 3, 3, 3, 3 ) );
  16. SetHorizontal();
  17. SetAlignment( Gwen::Pos::Center );
  18. m_fProgress = 0.0f;
  19. m_bAutoLabel = true;
  20. }
  21. void ProgressBar::SetValue(float val)
  22. {
  23. if ( val < 0 )
  24. val = 0;
  25. if ( val > 1 )
  26. val = 1;
  27. m_fProgress = val;
  28. if ( m_bAutoLabel )
  29. {
  30. int displayVal = m_fProgress * 100;
  31. SetText( Utility::ToString( displayVal ) + "%" );
  32. }
  33. }
  34. void ProgressBar::Render( Skin::Base* skin )
  35. {
  36. skin->DrawProgressBar( this, m_bHorizontal, m_fProgress);
  37. }