KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 <gal/gal.h>
34#include <chrono>
35#include <memory>
36
37namespace KIGFX
38{
39
44{
45public:
46 virtual ~ZOOM_CONTROLLER() = default;
47
55 virtual double GetScaleForRotation( int aRotation ) = 0;
56};
57
58
63{
64public:
66 using TIMEOUT = std::chrono::milliseconds;
67
69 using CLOCK = std::chrono::steady_clock;
70
72 using TIME_PT = std::chrono::time_point<CLOCK>;
73
75 static constexpr TIMEOUT DEFAULT_TIMEOUT = std::chrono::milliseconds( 500 );
76
78 static constexpr double DEFAULT_ACCELERATION_SCALE = 5.0;
79
80 /*
81 * A class interface that provides timestamps for events.
82 */
84 {
85 public:
86 virtual ~TIMESTAMP_PROVIDER() = default;
87
88 /*
89 * @return the timestamp at the current time.
90 */
91 virtual TIME_PT GetTimestamp() = 0;
92 };
93
101 ACCELERATING_ZOOM_CONTROLLER( double aScale = DEFAULT_ACCELERATION_SCALE,
102 const TIMEOUT& aAccTimeout = DEFAULT_TIMEOUT,
103 TIMESTAMP_PROVIDER* aTimestampProv = nullptr );
104
105 double GetScaleForRotation( int aRotation ) override;
106
108 {
109 return m_accTimeout;
110 }
111
112 void SetTimeout( const TIMEOUT& aNewTimeout )
113 {
114 m_accTimeout = aNewTimeout;
115 }
116
117private:
120
122 std::unique_ptr<TIMESTAMP_PROVIDER> m_ownTimestampProv;
123
126
129
131 bool m_prevRotationPositive = false;
132
134 double m_scale;
135};
136
137
143{
144public:
149 CONSTANT_ZOOM_CONTROLLER( double aScale );
150
151 double GetScaleForRotation( int aRotation ) override;
152
154 static constexpr double GTK3_SCALE = 0.002;
155
157 static constexpr double MAC_SCALE = 0.01;
158
160 static constexpr double MSW_SCALE = 0.005;
161
163 static constexpr double MANUAL_SCALE_FACTOR = 0.001;
164
165private:
167 double m_scale;
168};
169
170} // namespace KIGFX
171
172#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.
std::chrono::milliseconds TIMEOUT
The clock used for the timestamp (guaranteed to be monotonic).
TIME_PT m_prevTimestamp
The timeout value.
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).
std::unique_ptr< TIMESTAMP_PROVIDER > m_ownTimestampProv
The timestamp of the previous event.
A CONSTANT_ZOOM_CONTROLLER that zooms by a fixed factor based only on the magnitude of the scroll whe...
double m_scale
< The scale factor set by the constructor.
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.
#define GAL_API
Definition: gal.h:28
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:247