KiCad PCB EDA Suite
stepped_slider.cpp
Go to the documentation of this file.
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 
20 #include <widgets/stepped_slider.h>
21 #include <wx/event.h>
22 
23 
24 BEGIN_EVENT_TABLE( STEPPED_SLIDER, wxSlider )
25  EVT_SCROLL( STEPPED_SLIDER::OnScroll )
26 END_EVENT_TABLE()
27 
28 
30  wxWindow* aParent,
31  wxWindowID aId,
32  int aValue,
33  int aMinValue,
34  int aMaxValue,
35  const wxPoint& aPos,
36  const wxSize& aSize,
37  long aStyle,
38  const wxValidator& aValidator,
39  const wxString& aName )
40  :wxSlider( aParent, aId, aValue, aMinValue, aMaxValue,
41  aPos, aSize, aStyle, aValidator, aName ),
42  m_step( 1 )
43 {}
44 
45 
47 {}
48 
49 
50 void STEPPED_SLIDER::SetStep( int aSize )
51 {
52  wxASSERT( aSize > 0 );
53  m_step = ( aSize > 0 ) ? aSize : 1;
54 
55 #ifdef __WXMSW__
56  ClearTicks();
57 
58  if( aSize > 1 )
59  SetTickFreq( aSize );
60 #endif // __WXMSW__
61 }
62 
63 
65 {
66  return m_step;
67 }
68 
69 
70 void STEPPED_SLIDER::OnScroll( wxScrollEvent& aEvent )
71 {
72  const int value = GetValue();
73  const int rounded = value - value % m_step;
74 
75  SetValue( rounded );
76  aEvent.Skip();
77 }
void OnScroll(wxScrollEvent &aEvent)
int GetStep() const
Get the step size.
virtual ~STEPPED_SLIDER()
Customized wxSlider with forced stepping.
void SetStep(int aSize)
Set the step size.