KiCad PCB EDA Suite
zoom_controller.h
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) 2013-2018 KiCad Developers, see AUTHORS.txt for contributors.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  *
23  */
24 
30 #ifndef __ZOOM_CONTROLLER_H
31 #define __ZOOM_CONTROLLER_H
32 
33 #include <chrono>
34 #include <memory>
35 
36 namespace KIGFX
37 {
38 
43 {
44 public:
45  virtual ~ZOOM_CONTROLLER() = default;
46 
53  virtual double GetScaleForRotation( int aRotation ) = 0;
54 };
55 
56 
61 {
62 public:
64  using TIMEOUT = std::chrono::milliseconds;
65 
67  using CLOCK = std::chrono::steady_clock;
68 
70  using TIME_PT = std::chrono::time_point<CLOCK>;
71 
73  static constexpr TIMEOUT DEFAULT_TIMEOUT = std::chrono::milliseconds( 500 );
74 
76  static constexpr double DEFAULT_ACCELERATION_SCALE = 5.0;
77 
78  /*
79  * A class interface that provides timestamps for events
80  */
82  {
83  public:
84  virtual ~TIMESTAMP_PROVIDER() = default;
85 
86  /*
87  * @return the timestamp at the current time
88  */
89  virtual TIME_PT GetTimestamp() = 0;
90  };
91 
100  const TIMEOUT& aAccTimeout = DEFAULT_TIMEOUT,
101  TIMESTAMP_PROVIDER* aTimestampProv = nullptr );
102 
103  double GetScaleForRotation( int aRotation ) override;
104 
106  {
107  return m_accTimeout;
108  }
109 
110  void SetTimeout( const TIMEOUT& aNewTimeout )
111  {
112  m_accTimeout = aNewTimeout;
113  }
114 
115 private:
118 
120  std::unique_ptr<TIMESTAMP_PROVIDER> m_ownTimestampProv;
121 
126 
128  double m_scale;
129 };
130 
131 
137 {
138 public:
143  CONSTANT_ZOOM_CONTROLLER( double aScale );
144 
145  double GetScaleForRotation( int aRotation ) override;
146 
148  static constexpr double GTK3_SCALE = 0.002;
149 
151  static constexpr double MAC_SCALE = 0.01;
152 
154  static constexpr double MANUAL_SCALE_FACTOR = 0.001;
155 
156 private:
158  double m_scale;
159 };
160 
161 } // namespace KIGFX
162 
163 #endif
double GetScaleForRotation(int aRotation) override
Gets the scale factor produced by a given mousewheel rotation.
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:175
std::chrono::time_point< CLOCK > TIME_PT
The type of the time stamps.
virtual double GetScaleForRotation(int aRotation)=0
Gets the scale factor produced by a given mousewheel rotation.
Class that handles the response of the zoom scale to external inputs.
TIME_PT m_lastTimestamp
The timestamp of the last event.
static constexpr TIMEOUT DEFAULT_TIMEOUT
The default timeout, after which a another scroll will not be accelerated.
double m_scale
A multiplier for the minimum zoom step size.
static constexpr double DEFAULT_ACCELERATION_SCALE
The default minimum step factor for accelerating controller.
TIMESTAMP_PROVIDER * m_timestampProv
The timestamp provider to use (might be provided externally)
std::chrono::steady_clock CLOCK
The clock used for the timestamp (guaranteed to be monotonic)
ACCELERATING_ZOOM_CONTROLLER(double aScale=DEFAULT_ACCELERATION_SCALE, const TIMEOUT &aAccTimeout=DEFAULT_TIMEOUT, TIMESTAMP_PROVIDER *aTimestampProv=nullptr)
static constexpr double GTK3_SCALE
A suitable (magic) scale factor for GTK3 systems.
std::chrono::milliseconds TIMEOUT
The type of the acceleration timeout.
double m_scale
The scale factor set by the constructor.
Class that zooms faster if scroll events happen very close together.
static constexpr double MAC_SCALE
A suitable (magic) scale factor for Mac systems.
double GetScaleForRotation(int aRotation) override
Gets the scale factor produced by a given mousewheel rotation.
TIMEOUT m_accTimeout
The timeout value.
A ZOOM_CONTROLLER that zooms by a fixed factor based only on the magnitude of the scroll wheel rotati...
static constexpr double MANUAL_SCALE_FACTOR
Multipler for manual scale ssetting.
virtual ~ZOOM_CONTROLLER()=default
std::unique_ptr< TIMESTAMP_PROVIDER > m_ownTimestampProv
Any provider owned by this class (the default one, if used)
void SetTimeout(const TIMEOUT &aNewTimeout)