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.

77 lines
1.9 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors.
  5. *
  6. * This program is free software: you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation, either version 3 of the License, or (at your
  9. * option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <widgets/stepped_slider.h>
  20. #include <wx/event.h>
  21. BEGIN_EVENT_TABLE( STEPPED_SLIDER, wxSlider )
  22. EVT_SCROLL( STEPPED_SLIDER::OnScroll )
  23. END_EVENT_TABLE()
  24. STEPPED_SLIDER::STEPPED_SLIDER(
  25. wxWindow* aParent,
  26. wxWindowID aId,
  27. int aValue,
  28. int aMinValue,
  29. int aMaxValue,
  30. const wxPoint& aPos,
  31. const wxSize& aSize,
  32. long aStyle,
  33. const wxValidator& aValidator,
  34. const wxString& aName )
  35. :wxSlider( aParent, aId, aValue, aMinValue, aMaxValue,
  36. aPos, aSize, aStyle, aValidator, aName ),
  37. m_step( 1 )
  38. {}
  39. STEPPED_SLIDER::~STEPPED_SLIDER()
  40. {}
  41. void STEPPED_SLIDER::SetStep( int aSize )
  42. {
  43. wxASSERT( aSize > 0 );
  44. m_step = ( aSize > 0 ) ? aSize : 1;
  45. #ifdef __WXMSW__
  46. ClearTicks();
  47. if( aSize > 1 )
  48. SetTickFreq( aSize );
  49. #endif // __WXMSW__
  50. }
  51. int STEPPED_SLIDER::GetStep() const
  52. {
  53. return m_step;
  54. }
  55. void STEPPED_SLIDER::OnScroll( wxScrollEvent& aEvent )
  56. {
  57. const int value = GetValue();
  58. const int rounded = value - value % m_step;
  59. SetValue( rounded );
  60. aEvent.Skip();
  61. }