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 The 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
29
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
91 virtual TIME_PT GetTimestamp() = 0;
92 };
93
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
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
void SetTimeout(const TIMEOUT &aNewTimeout)
std::chrono::time_point< CLOCK > TIME_PT
The type of the time stamps.
std::chrono::milliseconds TIMEOUT
The type of the acceleration timeout.
static constexpr TIMEOUT DEFAULT_TIMEOUT
The default timeout, after which a another scroll will not be accelerated.
TIME_PT m_prevTimestamp
The timestamp of the previous event.
TIMEOUT m_accTimeout
The timeout value.
std::chrono::steady_clock CLOCK
The clock used for the timestamp (guaranteed to be monotonic).
bool m_prevRotationPositive
Previous rotation was positive.
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
The default minimum step factor for accelerating controller.
std::unique_ptr< TIMESTAMP_PROVIDER > m_ownTimestampProv
Any provider owned by this class (the default one, if used).
double GetScaleForRotation(int aRotation) override
Get the scale factor produced by a given mousewheel rotation.
static constexpr double MAC_SCALE
A suitable (magic) scale factor for Mac systems.
double m_scale
The scale factor set by the constructor.
static constexpr double MSW_SCALE
A suitable (magic) scale factor for Windows systems.
static constexpr double GTK3_SCALE
A suitable (magic) scale factor for GTK3 systems.
static constexpr double MANUAL_SCALE_FACTOR
Multiplier for manual scale ssetting.
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 eda_group.h:33