cc-pets 1.1.2 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Sources/CCPets/PetView.m +17 -6
- package/package.json +1 -1
package/Sources/CCPets/PetView.m
CHANGED
|
@@ -205,6 +205,13 @@ static const CGFloat PetDragThreshold = 3.0;
|
|
|
205
205
|
}
|
|
206
206
|
- (void)nextFrame:(NSTimer *)timer {
|
|
207
207
|
if (self.lookDirection >= 0) return;
|
|
208
|
+
// performWindowDragWithEvent: 会立即返回,且窗口服务器可能吞掉 mouseUp。
|
|
209
|
+
// 动画时钟同时作为释放兜底,避免拖动状态永久停留在 running 行。
|
|
210
|
+
if (self.draggingPet &&
|
|
211
|
+
!CGEventSourceButtonState(kCGEventSourceStateCombinedSessionState, kCGMouseButtonLeft)) {
|
|
212
|
+
[self endPetDrag];
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
208
215
|
self.sequenceIndex += 1;
|
|
209
216
|
if (self.sequenceIndex >= self.frames.count) {
|
|
210
217
|
if (self.oneShot) {
|
|
@@ -286,9 +293,9 @@ static const CGFloat PetDragThreshold = 3.0;
|
|
|
286
293
|
if (hypot(horizontal, vertical) < PetDragThreshold) return;
|
|
287
294
|
[self runWindowDragWithEvent:event movingRight:horizontal >= 0];
|
|
288
295
|
}
|
|
289
|
-
//
|
|
290
|
-
//
|
|
291
|
-
//
|
|
296
|
+
// 拖动交给窗口服务器:它不依赖应用事件流,所以掠过其他窗口、拖出屏幕、
|
|
297
|
+
// 应用非活跃都不会中断。这个 API 会立即返回,且 mouseUp 可能不会发回应用,
|
|
298
|
+
// 因此不能在调用后立刻恢复 idle;释放兜底由 nextFrame: 检查物理按键状态。
|
|
292
299
|
- (void)runWindowDragWithEvent:(NSEvent *)event movingRight:(BOOL)movingRight {
|
|
293
300
|
self.draggingPet = YES;
|
|
294
301
|
if (self.pocketHoverChanged) self.pocketHoverChanged(NO);
|
|
@@ -296,14 +303,18 @@ static const CGFloat PetDragThreshold = 3.0;
|
|
|
296
303
|
[self playRow:movingRight ? 1 : 2 throughFrame:7 oneShot:NO];
|
|
297
304
|
|
|
298
305
|
[self.window performWindowDragWithEvent:event];
|
|
299
|
-
|
|
306
|
+
}
|
|
307
|
+
- (void)endPetDrag {
|
|
308
|
+
if (!self.draggingPet) return;
|
|
300
309
|
self.draggingPet = NO;
|
|
301
310
|
if (self.dragStateChanged) self.dragStateChanged(NO);
|
|
302
311
|
[self playRow:0 throughFrame:5 oneShot:NO];
|
|
303
312
|
}
|
|
304
|
-
// 拖动会话(含 mouseUp)已被 performWindowDragWithEvent: 消费,所以能走到这里
|
|
305
|
-
// 就说明本次按下没有拖动过,不需要额外的标志来区分。
|
|
306
313
|
- (void)mouseUp:(NSEvent *)event {
|
|
314
|
+
if (self.draggingPet) {
|
|
315
|
+
[self endPetDrag];
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
307
318
|
[self playRow:7 throughFrame:5 oneShot:YES];
|
|
308
319
|
}
|
|
309
320
|
- (void)drawRect:(NSRect)dirtyRect {
|