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-2020 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
36namespace KIGFX
37{
38
43{
44public:
45 virtual ~ZOOM_CONTROLLER() = default;
46
54 virtual double GetScaleForRotation( int aRotation ) = 0;
55};
56
57
62{
63public:
65 using TIMEOUT = std::chrono::milliseconds;
66
68 using CLOCK = std::chrono::steady_clock;
69
71 using TIME_PT = std::chrono::time_point<CLOCK>;
72
74 static constexpr TIMEOUT DEFAULT_TIMEOUT = std::chrono::milliseconds( 500 );
75
77 static constexpr double DEFAULT_ACCELERATION_SCALE = 5.0;
78
79 /*
80 * A class interface that provides timestamps for events.
81 */
83 {
84 public:
85 virtual ~TIMESTAMP_PROVIDER() = default;
86
87 /*
88 * @return the timestamp at the current time.
89 */
90 virtual TIME_PT GetTimestamp() = 0;
91 };
92
101 const TIMEOUT& aAccTimeout = DEFAULT_TIMEOUT,
102 TIMESTAMP_PROVIDER* aTimestampProv = nullptr );
103
104 double GetScaleForRotation( int aRotation ) override;
105
107 {
108 return m_accTimeout;
109 }
110
111 void SetTimeout( const TIMEOUT& aNewTimeout )
112 {
113 m_accTimeout = aNewTimeout;
114 }
115
116private:
119
121 std::unique_ptr<TIMESTAMP_PROVIDER> m_ownTimestampProv;
122
125
128
130 double m_scale;
131};
132
133
139{
140public:
145 CONSTANT_ZOOM_CONTROLLER( double aScale );
146
147 double GetScaleForRotation( int aRotation ) override;
148
150 static constexpr double GTK3_SCALE = 0.002;
151
153 static constexpr double MAC_SCALE = 0.01;
154
156 static constexpr double MSW_SCALE = 0.005;
157
159 static constexpr double MANUAL_SCALE_FACTOR = 0.001;
160
161private:
163 double m_scale;
164};
165
166} // namespace KIGFX
167
168#endif
Class that zooms faster if scroll events happen very close together.
void SetTimeout(const TIMEOUT &aNewTimeout)
std::chrono::time_point< CLOCK > TIME_PT
The default timeout, after which a another scroll will not be accelerated.
static constexpr TIMEOUT DEFAULT_TIMEOUT
The default minimum step factor for accelerating controller.
TIME_PT m_lastTimestamp
The timeout value.
std::chrono::milliseconds TIMEOUT
The clock used for the timestamp (guaranteed to be monotonic).
std::chrono::steady_clock CLOCK
The type of the time stamps.
double m_scale
A multiplier for the minimum zoom step size.
TIMESTAMP_PROVIDER * m_timestampProv
< The timestamp provider to use (might be provided externally).
double GetScaleForRotation(int aRotation) override
Get the scale factor produced by a given mousewheel rotation.
ACCELERATING_ZOOM_CONTROLLER(double aScale=DEFAULT_ACCELERATION_SCALE, const TIMEOUT &aAccTimeout=DEFAULT_TIMEOUT, TIMESTAMP_PROVIDER *aTimestampProv=nullptr)
static constexpr double DEFAULT_ACCELERATION_SCALE
std::unique_ptr< TIMESTAMP_PROVIDER > m_ownTimestampProv
The timestamp of the last event.
A #ZOOM_CONTROLLER that zooms by a fixed factor based only on the magnitude of the scroll wheel rotat...
double GetScaleForRotation(int aRotation) override
A suitable (magic) scale factor for GTK3 systems.
static constexpr double MSW_SCALE
A suitable (magic) scale factor for Windows systems.
double m_scale
< The scale factor set by the constructor.
static constexpr double MAC_SCALE
static constexpr double GTK3_SCALE
A suitable (magic) scale factor for Mac systems.
static constexpr double MANUAL_SCALE_FACTOR
Handle the response of the zoom scale to external inputs.
virtual ~ZOOM_CONTROLLER()=default
virtual double GetScaleForRotation(int aRotation)=0
Get the scale factor produced by a given mousewheel rotation.
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:243