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, see <https://www.gnu.org/licenses/>.
18 *
19 */
20
25
26#ifndef __ZOOM_CONTROLLER_H
27#define __ZOOM_CONTROLLER_H
28
29#include <gal/gal.h>
30#include <chrono>
31#include <memory>
32
33namespace KIGFX
34{
35
40{
41public:
42 virtual ~ZOOM_CONTROLLER() = default;
43
51 virtual double GetScaleForRotation( int aRotation ) = 0;
52};
53
54
59{
60public:
62 using TIMEOUT = std::chrono::milliseconds;
63
65 using CLOCK = std::chrono::steady_clock;
66
68 using TIME_PT = std::chrono::time_point<CLOCK>;
69
71 static constexpr TIMEOUT DEFAULT_TIMEOUT = std::chrono::milliseconds( 500 );
72
74 static constexpr double DEFAULT_ACCELERATION_SCALE = 5.0;
75
80 {
81 public:
82 virtual ~TIMESTAMP_PROVIDER() = default;
83
87 virtual TIME_PT GetTimestamp() = 0;
88 };
89
99 const TIMEOUT& aAccTimeout = DEFAULT_TIMEOUT,
100 TIMESTAMP_PROVIDER* aTimestampProv = nullptr );
101
102 double GetScaleForRotation( int aRotation ) override;
103
105 {
106 return m_accTimeout;
107 }
108
109 void SetTimeout( const TIMEOUT& aNewTimeout )
110 {
111 m_accTimeout = aNewTimeout;
112 }
113
114private:
117
119 std::unique_ptr<TIMESTAMP_PROVIDER> m_ownTimestampProv;
120
123
126
129
131 double m_scale;
132};
133
134
140{
141public:
146 CONSTANT_ZOOM_CONTROLLER( double aScale );
147
148 double GetScaleForRotation( int aRotation ) override;
149
151 static constexpr double GTK3_SCALE = 0.002;
152
154 static constexpr double MAC_SCALE = 0.01;
155
157 static constexpr double MSW_SCALE = 0.005;
158
160 static constexpr double MANUAL_SCALE_FACTOR = 0.001;
161
162private:
164 double m_scale;
165};
166
167} // namespace KIGFX
168
169#endif
A interface that provides timestamps for events.
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:27
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:30