File: wx_view_controls.h

package info (click to toggle)
kicad 9.0.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 769,124 kB
  • sloc: cpp: 960,330; ansic: 121,001; xml: 66,428; python: 18,382; sh: 1,010; awk: 301; asm: 292; makefile: 227; javascript: 167; perl: 10
file content (214 lines) | stat: -rw-r--r-- 7,319 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * Copyright (C) 2012 Torsten Hueter, torstenhtr <at> gmx.de
 * Copyright (C) 2013 CERN
 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
 *
 * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, you may find one here:
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * or you may search the http://www.gnu.org website for the version 2 license,
 * or you may write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */

/**
 * @file wx_view_controls.h
 * @brief WX_VIEW_CONTROLS class definition.
 */

#ifndef __WX_VIEW_CONTROLS_H
#define __WX_VIEW_CONTROLS_H

#include <view/view_controls.h>
#include <wx/timer.h>
#include <memory>

class EDA_DRAW_PANEL_GAL;
class PROF_COUNTER;

namespace KIGFX
{

class ZOOM_CONTROLLER;

/**
 * An implementation of class #VIEW_CONTROLS for wxWidgets library.
 */
class WX_VIEW_CONTROLS : public VIEW_CONTROLS, public wxEvtHandler
{
public:
    WX_VIEW_CONTROLS( VIEW* aView, EDA_DRAW_PANEL_GAL* aParentPanel );
    virtual ~WX_VIEW_CONTROLS();

    /// Handler functions
    void onWheel( wxMouseEvent& aEvent );
    void onMotion( wxMouseEvent& aEvent );
    void onMagnify( wxMouseEvent& aEvent );
    void onButton( wxMouseEvent& aEvent );
    void onEnter( wxMouseEvent& WXUNUSED( aEvent ) );
    void onLeave( wxMouseEvent& WXUNUSED( aEvent ) );
    void onTimer( wxTimerEvent& WXUNUSED( aEvent ) );
    void onZoomGesture( wxZoomGestureEvent& aEvent );
    void onPanGesture( wxPanGestureEvent& aEvent );
    void onScroll( wxScrollWinEvent& aEvent );
    void onCaptureLost( wxMouseEvent& WXUNUSED( aEvent ) );


    /**
     * Force the cursor to stay within the drawing panel area.
     *
     * @param aEnabled determines if the cursor should be captured.
     */
    void CaptureCursor( bool aEnabled ) override;


    void PinCursorInsideNonAutoscrollArea( bool aWarpMouseCursor ) override;

    /// @copydoc VIEW_CONTROLS::GetMousePosition()
    VECTOR2D GetMousePosition( bool aWorldCoordinates = true ) const override;

    using VIEW_CONTROLS::GetCursorPosition;

    /// @copydoc VIEW_CONTROLS::GetCursorPosition()
    VECTOR2D GetCursorPosition( bool aSnappingEnabled ) const override;

    /// @copydoc VIEW_CONTROLS::GetRawCursorPosition()
    VECTOR2D GetRawCursorPosition( bool aSnappingEnabled = true ) const override;

    void SetCursorPosition( const VECTOR2D& aPosition, bool warpView,
                            bool aTriggeredByArrows, long aArrowCommand ) override;

    /// @copydoc VIEW_CONTROLS::SetCrossHairCursorPosition()
    void SetCrossHairCursorPosition( const VECTOR2D& aPosition, bool aWarpView ) override;

    /// @copydoc VIEW_CONTROLS::CursorWarp()
    void WarpMouseCursor( const VECTOR2D& aPosition, bool aWorldCoordinates = false,
                          bool aWarpView = false ) override;

    /// @copydoc VIEW_CONTROLS::CenterOnCursor()
    void CenterOnCursor() override;

    /// Adjusts the scrollbars position to match the current viewport.
    void UpdateScrollbars();

    /// End any mouse drag action still in progress.
    void CancelDrag();

    void ForceCursorPosition( bool aEnabled,
                              const VECTOR2D& aPosition = VECTOR2D( 0, 0 ) ) override;

    /// Applies VIEW_CONTROLS settings from the program #COMMON_SETTINGS.
    void LoadSettings() override;

    /// Event that forces mouse move event in the dispatcher (eg. used in autopanning, when
    /// mouse cursor does not move in screen coordinates, but does in world coordinates)
    static const wxEventType EVT_REFRESH_MOUSE;

    std::unique_ptr<PROF_COUNTER> m_MotionEventCounter;

private:
    /// Possible states for WX_VIEW_CONTROLS.
    enum STATE
    {
        IDLE = 1,           ///< Nothing is happening.
        DRAG_PANNING,       ///< Panning with mouse button pressed.
        AUTO_PANNING,       ///< Panning on approaching borders of the frame.
        DRAG_ZOOMING,       ///< Zooming with mouse button pressed.
    };

    /**
     * Set the interaction state, simply a internal setter to make it easier to debug changes.
     */
    void setState( STATE aNewState );

    /**
     * Compute new viewport settings while in autopanning mode.
     *
     * @param aEvent is an event to be processed and decide if autopanning should happen.
     * @return true if it is currently autopanning (ie. autopanning is active and mouse cursor
     *         is in the area that causes autopanning to happen).
     */
    bool handleAutoPanning( const wxMouseEvent& aEvent );

    /**
     * Limit the cursor position to within the canvas by warping it
     *
     * @param x Mouse position
     * @param y Mouse position
     */
    void handleCursorCapture( int x, int y );

    /**
     * Send an event to refresh mouse position.
     *
     * It is mostly used for notifying the tools that the cursor position in the world
     * coordinates has changed, whereas the screen coordinates remained the same (e.g.
     * frame edge autopanning).
     *
     * @param aSetModifiers If false, don't change the modifiers (they were set using the
     *                      keyboard motion).
     */
    void refreshMouse( bool aSetModifiers);

    /**
     * Get the cursor position in the screen coordinates.
     */
    wxPoint getMouseScreenPosition() const;

    /// Current state of VIEW_CONTROLS.
    STATE       m_state;

    /// Panel that is affected by VIEW_CONTROLS.
    EDA_DRAW_PANEL_GAL* m_parentPanel;

    /// Store information about point where dragging has started.
    VECTOR2D    m_dragStartPoint;

    /// Current direction of panning (only autopanning mode).
    VECTOR2D    m_panDirection;

    /// Timer responsible for handling autopanning.
    wxTimer     m_panTimer;

    /// Ratio used for scaling world coordinates to scrollbar position.
    VECTOR2D    m_scrollScale;

    /// Current scrollbar position.
    VECTOR2I    m_scrollPos;

    /// The mouse position when a drag zoom started.
    VECTOR2D      m_zoomStartPoint;

    /// Current cursor position (world coordinates).
    VECTOR2D    m_cursorPos;

    /// Flag deciding whether the cursor position should be calculated using the mouse position.
    bool        m_updateCursor;

    /// Flag to indicate if infinite panning works on this platform.
    bool m_infinitePanWorks;

    /// A #ZOOM_CONTROLLER that determines zoom steps. This is platform-specific.
    std::unique_ptr<ZOOM_CONTROLLER> m_zoomController;

    /// Used to track gesture events.
    double   m_gestureLastZoomFactor;
    VECTOR2D m_gestureLastPos;
};
} // namespace KIGFX

#endif