Skip to content

Commit e320baf

Browse files
committed
Fix mouse button state lock bug
1 parent ecd5c35 commit e320baf

File tree

1 file changed

+25
-26
lines changed

1 file changed

+25
-26
lines changed

Sources/GateEngine/UI/GestureRecognizers/PanGestureRecognizer.swift

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ final public class PanGestureRecognizer: GestureRecognizer {
110110
}
111111

112112
public override func touchesBegan(_ touches: Set<Touch>) {
113-
guard let view else {return}
114113
guard recognizedSources.contains(.screen) else {return}
114+
guard let view else {return}
115115

116116
for touch in touches {
117117
switch touchKinds {
@@ -169,31 +169,29 @@ final public class PanGestureRecognizer: GestureRecognizer {
169169
var mouseButtonsMatch: Bool = false {
170170
didSet {
171171
if mouseButtonsMatch == false {
172-
self.phase = .unrecognized
173-
position1 = nil
174-
position2 = nil
172+
self.invalidate()
175173
}
176174
}
177175
}
178176
var mouseButtonsDown: [GateEngine.MouseButton] = [] {
179177
didSet {
180-
switch mouseButtons {
178+
switch self.mouseButtons {
181179
case .none:
182-
mouseButtonsMatch = mouseButtonsDown.isEmpty
180+
self.mouseButtonsMatch = mouseButtonsDown.isEmpty
183181
case .any:
184-
mouseButtonsMatch = mouseButtonsDown.isEmpty == false
182+
self.mouseButtonsMatch = mouseButtonsDown.isEmpty == false
185183
case .exactly(let buttons):
186184
for button in buttons {
187-
if mouseButtonsDown.contains(button) == false {
188-
mouseButtonsMatch = false
185+
if self.mouseButtonsDown.contains(button) == false {
186+
self.mouseButtonsMatch = false
189187
return
190188
}
191189
}
192190
self.mouseButtonsMatch = true
193191
case .anyOf(let buttons):
194192
for button in buttons {
195-
if mouseButtonsDown.contains(button) == false {
196-
mouseButtonsMatch = true
193+
if self.mouseButtonsDown.contains(button) == false {
194+
self.mouseButtonsMatch = true
197195
return
198196
}
199197
}
@@ -202,7 +200,6 @@ final public class PanGestureRecognizer: GestureRecognizer {
202200
}
203201

204202
func performSurfaceRecognition() {
205-
guard recognizedSources.contains(.surface) else {return}
206203
guard self.surfaceTouches.count == touchCount else {return}
207204
func avgTouchPosition() -> Position2 {
208205
var p: Position2 = .zero
@@ -213,43 +210,44 @@ final public class PanGestureRecognizer: GestureRecognizer {
213210
return p
214211
}
215212

216-
guard mouseButtonsMatch else {
217-
self.phase = .unrecognized
213+
guard self.mouseButtonsMatch else {
214+
//self.phase = .unrecognized
218215
return
219216
}
220217

221-
if position1 == nil {
222-
position1 = avgTouchPosition()
218+
if self.position1 == nil {
219+
self.position1 = avgTouchPosition()
223220
self.phase = .recognizing
224-
}else if position2 == nil {
225-
position2 = avgTouchPosition()
221+
}else if self.position2 == nil {
222+
self.position2 = avgTouchPosition()
226223

227224
#if os(macOS) || os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
228225
// Good for Magic Trackpad
229-
let delta = (position1! - position2!) * 750
226+
let delta = (self.position1! - self.position2!) * 750
230227
#else
231-
let delta = (position1! - position2!)
228+
let delta = (self.position1! - self.position2!)
232229
#endif
233230

234-
if phase != .recognized {
231+
if self.phase != .recognized {
235232
// Require the pan gesture to move before activating
236233
// This allows other gestures to activate first
237234
if abs(delta.length) <= 2 {
238-
position2 = nil
235+
self.position2 = nil
239236
return
240237
}
241238
}
242239

243240
self.phase = .recognized
244-
for action in actions {
245-
action(position2!, delta)
241+
for action in self.actions {
242+
action(self.position2!, delta)
246243
}
247-
position1 = position2
248-
position2 = nil
244+
self.position1 = self.position2
245+
self.position2 = nil
249246
}
250247
}
251248

252249
public override func cursorButtonDown(button: MouseButton, mouse: Mouse) {
250+
guard recognizedSources.contains(.mouse) else {return}
253251
mouseButtonsDown.append(button)
254252
}
255253

@@ -258,6 +256,7 @@ final public class PanGestureRecognizer: GestureRecognizer {
258256
}
259257

260258
public override func surfaceTouchesBegan(_ touches: Set<SurfaceTouch>, mouse: Mouse) {
259+
guard recognizedSources.contains(.surface) else {return}
261260
for touch in touches {
262261
surfaceTouches.insert(touch)
263262
}

0 commit comments

Comments
 (0)