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 
75  /*
76  * A class interface that provides timestamps for events
77  */
79  {
80  public:
81  virtual ~TIMESTAMP_PROVIDER() = default;
82 
83  /*
84  * @return the timestamp at the current time
85  */
86  virtual TIME_PT GetTimestamp() = 0;
87  };
88 
97  TIMESTAMP_PROVIDER* aTimestampProv = nullptr );
98 
99  double GetScaleForRotation( int aRotation ) override;
100 
102  {
103  return m_accTimeout;
104  }
105 
106  void SetTimeout( const TIMEOUT& aNewTimeout )
107  {
108  m_accTimeout = aNewTimeout;
109  }
110 
111 private:
114 
116  std::unique_ptr<TIMESTAMP_PROVIDER> m_ownTimestampProv;
117 
122 };
123 
124 
130 {
131 public:
136  CONSTANT_ZOOM_CONTROLLER( double aScale );
137 
138  double GetScaleForRotation( int aRotation ) override;
139 
141  static constexpr double GTK3_SCALE = 0.002;
142 
144  static constexpr double MAC_SCALE = 0.01;
145 
146 private:
148  double m_scale;
149 };
150 
151 } // namespace KIGFX
152 
153 #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: class_module.h:58
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.
TIMESTAMP_PROVIDER * m_timestampProv
The timestamp provider to use (might be provided externally)
ACCELERATING_ZOOM_CONTROLLER(const TIMEOUT &aAccTimeout=DEFAULT_TIMEOUT, TIMESTAMP_PROVIDER *aTimestampProv=nullptr)
std::chrono::steady_clock CLOCK
The clock used for the timestamp (guaranteed to be monotonic)
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...
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)