1 | ///////////////////////////////////////////////////////////////////////////// |
---|
2 | // Name: gestureclick.h |
---|
3 | // Purpose: |
---|
4 | // Author: Cesar Mauri Loba (cesar at crea-si dot com) |
---|
5 | // Modified by: |
---|
6 | // Created: |
---|
7 | // Copyright: (C) 2008-12 Cesar Mauri Loba - CREA Software Systems |
---|
8 | // |
---|
9 | // This program is free software: you can redistribute it and/or modify |
---|
10 | // it under the terms of the GNU General Public License as published by |
---|
11 | // the Free Software Foundation, either version 3 of the License, or |
---|
12 | // (at your option) any later version. |
---|
13 | // |
---|
14 | // This program is distributed in the hope that it will be useful, |
---|
15 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
17 | // GNU General Public License for more details. |
---|
18 | // |
---|
19 | // You should have received a copy of the GNU General Public License |
---|
20 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
21 | ///////////////////////////////////////////////////////////////////////////// |
---|
22 | #ifndef GESTURECLICK_H |
---|
23 | #define GESTURECLICK_H |
---|
24 | |
---|
25 | #include "waittime.h" |
---|
26 | #include "configbase.h" |
---|
27 | #include "cvisualalert.h" |
---|
28 | #include "ckeyboardcode.h" |
---|
29 | #include "mousecommand.h" |
---|
30 | #include <math.h> |
---|
31 | #include <vector> |
---|
32 | |
---|
33 | class CMouseControl; |
---|
34 | |
---|
35 | class CGestureClick : public CConfigBase |
---|
36 | { |
---|
37 | public: |
---|
38 | CGestureClick (CMouseControl& mc); |
---|
39 | ~CGestureClick (); |
---|
40 | |
---|
41 | // Main entry point to signal that the pointer has been moved. |
---|
42 | // Expect motion performed by the pointer in pixels and current |
---|
43 | // pointer location in absolute coordinates |
---|
44 | // Return the mouse command generated |
---|
45 | mousecmd::mousecmd ProcessMotion (int dxPix, int dyPix, unsigned int xCurr, unsigned int yCurr); |
---|
46 | |
---|
47 | //bool GetEnabled() const { return m_enabled; } |
---|
48 | void SetEnabled(bool value); |
---|
49 | |
---|
50 | // Reset internal state. Useful before start calling ProcessMotion |
---|
51 | void Reset(); |
---|
52 | |
---|
53 | bool AreVisualAlertsEnabled() const { return m_visualAlertsEnabled; } |
---|
54 | void EnableVisualAlerts(bool value); |
---|
55 | |
---|
56 | unsigned int GetDwellTime() const { |
---|
57 | return (unsigned int) (m_dwellCountdown.GetWaitTimeMs() / 100); |
---|
58 | } |
---|
59 | void SetDwellTime (unsigned int ds) { |
---|
60 | if (ds> 50) ds= 50; |
---|
61 | m_dwellCountdown.SetWaitTimeMs (ds * 100); |
---|
62 | } |
---|
63 | |
---|
64 | unsigned int GetDwellToleranceArea() const { |
---|
65 | return (unsigned int) m_dwellToleranceArea; |
---|
66 | } |
---|
67 | void SetDwellToleranceArea(unsigned int value) { |
---|
68 | if (value> 8) value= 8; |
---|
69 | m_dwellToleranceArea= (float) value; |
---|
70 | } |
---|
71 | |
---|
72 | bool GetFastGestureAction() const { return m_fastGestureAction; } |
---|
73 | void SetFastGestureAction(bool value) { m_fastGestureAction= value; } |
---|
74 | |
---|
75 | // Possible actions that can be generated. Values equal or greater than |
---|
76 | // EActionLast are keystrokes picked from m_keyboardCodes |
---|
77 | enum EAction { DISABLE= 0, SINGLE, THIRD, SECONDARY, DOUBLE, DRAG, EActionLast }; |
---|
78 | enum { MOUSE_EVENTS_COUNT= EActionLast }; |
---|
79 | |
---|
80 | int GetPossibleActionsCount() const { |
---|
81 | return MOUSE_EVENTS_COUNT + (int) m_keyboardCodes.size(); |
---|
82 | } |
---|
83 | |
---|
84 | EAction GetActionLeft() const { return m_actionLeft; } |
---|
85 | void SetActionLeft(EAction action) { |
---|
86 | assert (GetPossibleActionsCount()> action); |
---|
87 | if (GetPossibleActionsCount()<= action) action= DISABLE; |
---|
88 | m_actionLeft = action; |
---|
89 | } |
---|
90 | |
---|
91 | EAction GetActionRight() const { return m_actionRight; } |
---|
92 | void SetActionRight(EAction action) { |
---|
93 | assert (GetPossibleActionsCount()> action); |
---|
94 | if (GetPossibleActionsCount()<= action) action= DISABLE; |
---|
95 | m_actionRight = action; |
---|
96 | } |
---|
97 | |
---|
98 | EAction GetActionTop() const { return m_actionTop; } |
---|
99 | void SetActionTop(EAction action) { |
---|
100 | assert (GetPossibleActionsCount()> action); |
---|
101 | if (GetPossibleActionsCount()<= action) action= DISABLE; |
---|
102 | m_actionTop = action; |
---|
103 | } |
---|
104 | |
---|
105 | EAction GetActionBottom() const { return m_actionBottom; } |
---|
106 | void SetActionBottom(EAction action) { |
---|
107 | assert (GetPossibleActionsCount()> action); |
---|
108 | if (GetPossibleActionsCount()<= action) action= DISABLE; |
---|
109 | m_actionBottom = action; |
---|
110 | } |
---|
111 | |
---|
112 | CKeyboardCode GetKeyboardCode(unsigned int position) { |
---|
113 | assert (position< m_keyboardCodes.size()); |
---|
114 | return m_keyboardCodes[position]; |
---|
115 | } |
---|
116 | unsigned int GetKeyEventsCount() const { |
---|
117 | return (unsigned int) m_keyboardCodes.size(); |
---|
118 | } |
---|
119 | |
---|
120 | // Configuration methods |
---|
121 | virtual void InitDefaults(); |
---|
122 | virtual void WriteProfileData(wxConfigBase* pConfObj); |
---|
123 | virtual void ReadProfileData(wxConfigBase* pConfObj); |
---|
124 | |
---|
125 | private: |
---|
126 | |
---|
127 | enum EState { DWELL_TIME, COMPUTE_DIRECTION, WAIT_DWELL }; |
---|
128 | |
---|
129 | void InitKeyboardCodes(); |
---|
130 | mousecmd::mousecmd DoAction (EAction action); |
---|
131 | |
---|
132 | // Working attributes |
---|
133 | volatile bool m_enabled; |
---|
134 | CWaitTime m_dwellCountdown; |
---|
135 | CVisualAlertProgress m_progressVisualAlert; |
---|
136 | CVisualAlertDirection m_gestureVisualAlert; |
---|
137 | bool m_isLeftPressed; |
---|
138 | int m_xIniGesture, m_yIniGesture; |
---|
139 | EState m_state; |
---|
140 | |
---|
141 | // Associations |
---|
142 | CMouseControl* m_mouseControl; |
---|
143 | |
---|
144 | // State |
---|
145 | //bool m_consecutiveClicksAllowed; |
---|
146 | bool m_visualAlertsEnabled; |
---|
147 | //Define maximum distance (in pixels) from pointer's starting countdown position |
---|
148 | //where is allowed to move without cancelling current countdown. |
---|
149 | float m_dwellToleranceArea; |
---|
150 | EAction m_actionLeft; |
---|
151 | EAction m_actionRight; |
---|
152 | EAction m_actionTop; |
---|
153 | EAction m_actionBottom; |
---|
154 | bool m_fastGestureAction; |
---|
155 | std::vector<CKeyboardCode> m_keyboardCodes; |
---|
156 | }; |
---|
157 | |
---|
158 | #endif |
---|