Debian Codegraph @

src/Gui/Navigation/GestureNavigationStyle.h

raw
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 /***************************************************************************
3 * Copyright (c) 2019 Victor Titov (DeepSOIC) <[email protected]> *
4 * *
5 * This file is part of the FreeCAD CAx development system. *
6 * *
7 * This library is free software; you can redistribute it and/or *
8 * modify it under the terms of the GNU Library General Public *
9 * License as published by the Free Software Foundation; either *
10 * version 2 of the License, or (at your option) any later version. *
11 * *
12 * This library is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU Library General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU Library General Public *
18 * License along with this library; see the file COPYING.LIB. If not, *
19 * write to the Free Software Foundation, Inc., 59 Temple Place, *
20 * Suite 330, Boston, MA 02111-1307, USA *
21 * *
22 ***************************************************************************/
23
24 #ifndef GESTURENAVIGATIONSTYLE2_H
25 #define GESTURENAVIGATIONSTYLE2_H
26
27 #include "Navigation/NavigationStyle.h"
28
29 #include <queue>
30 #include <memory>
31
32 namespace Gui
33 {
34
35
36 class GestureNavigationStyle: public UserNavigationStyle
37 {
38 using superclass = UserNavigationStyle;
39
40 TYPESYSTEM_HEADER_WITH_OVERRIDE();
41
42 public:
43 GestureNavigationStyle();
44 ~GestureNavigationStyle() override;
45 const char* mouseButtons(ViewerMode) override;
46 ClarifySelectionMode clarifySelectionMode() const override
47 {
48 return ClarifySelectionMode::Ctrl;
49 }
50
51 protected:
52 SbBool processSoEvent(const SoEvent* const ev) override;
53
54 public:
55 /// calls processSoEvent of NavigationStyle.
56 SbBool processSoEvent_bypass(const SoEvent* const ev);
57
58 protected: // state machine classes
59 /// State machine event, a wrapper around SoEvent
60 class Event;
61
62 class NaviMachine;
63
64 class IdleState;
65 /// when operating a dragger, for example
66 class InteractState;
67 /// button was pressed, but the cursor hasn't moved yet
68 class AwaitingMoveState;
69 /// when in a two-finger touchscreen gestures
70 class GestureState;
71 /// rotating the viewed model with mouse drag
72 class RotateState;
73 /// panning with mouse drag
74 class PanState;
75 /// panning triggered by tap-and-hold. It won't switch to Tilt and Rotate upon
76 /// pressing/releasing mouse buttons
77 class StickyPanState;
78 /// tilting with mouse drag
79 class TiltState;
80 /// this state discards all mouse input (except detecting button roll gestures), until all
81 /// buttons are released.
82 class AwaitingReleaseState;
83
84 class EventQueue: public std::queue<SoMouseButtonEvent>
85 {
86 public:
87 EventQueue(GestureNavigationStyle& ns)
88 : ns(ns)
89 {}
90
91 void post(const Event& ev);
92 void discardAll();
93 void forwardAll();
94
95 public:
96 GestureNavigationStyle& ns;
97 };
98
99
100 protected: // members variables
101 std::unique_ptr<NaviMachine> naviMachine;
102 EventQueue postponedEvents;
103
104 // settings:
105 /// if false, tilting with touchscreen gestures will be disabled
106 bool enableGestureTilt = false;
107 /// distance in px to treat as a definite drag (noise gate)
108 int mouseMoveThreshold = 5;
109 /// used by roll gesture detection logic, in AwaitingMoveState and AwaitingReleaseState.
110 int rollDir = 0;
111 bool logging = false;
112
113 public:
114 bool is2DViewing() const;
115
116 public: // gesture reactions
117 /// Roll gesture is like: press LMB, press RMB, release LMB, release RMB.
118 /// This function is called by state machine whenever it picks up roll gesture.
119 void onRollGesture(int direction);
120 };
121
122 } // namespace Gui
123 #endif // GESTURENAVIGATIONSTYLE2_H