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
76 /*
77 * A class interface that provides timestamps for events.
78 */
80 {
81 public:
82 virtual ~TIMESTAMP_PROVIDER() = default;
83
87 virtual TIME_PT GetTimestamp() = 0;
88 };
89
98 const TIMEOUT& aAccTimeout = DEFAULT_TIMEOUT,
99 TIMESTAMP_PROVIDER* aTimestampProv = nullptr );
100
101 double GetScaleForRotation( int aRotation ) override;
102
104 {
105 return m_accTimeout;
106 }
107
108 void SetTimeout( const TIMEOUT& aNewTimeout )
109 {
110 m_accTimeout = aNewTimeout;
111 }
112
113private:
116
118 std::unique_ptr<TIMESTAMP_PROVIDER> m_ownTimestampProv;
119
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
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:29