commit
7842d5b670
@ -310,19 +310,19 @@ class ImageModel with ChangeNotifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
double get maxScale {
|
double get maxScale {
|
||||||
if (_image == null) return 1.0;
|
if (_image == null) return 1.5;
|
||||||
final size = MediaQueryData.fromWindow(ui.window).size;
|
final size = MediaQueryData.fromWindow(ui.window).size;
|
||||||
final xscale = size.width / _image!.width;
|
final xscale = size.width / _image!.width;
|
||||||
final yscale = size.height / _image!.height;
|
final yscale = size.height / _image!.height;
|
||||||
return max(1.0, max(xscale, yscale));
|
return max(1.5, max(xscale, yscale));
|
||||||
}
|
}
|
||||||
|
|
||||||
double get minScale {
|
double get minScale {
|
||||||
if (_image == null) return 1.0;
|
if (_image == null) return 1.5;
|
||||||
final size = MediaQueryData.fromWindow(ui.window).size;
|
final size = MediaQueryData.fromWindow(ui.window).size;
|
||||||
final xscale = size.width / _image!.width;
|
final xscale = size.width / _image!.width;
|
||||||
final yscale = size.height / _image!.height;
|
final yscale = size.height / _image!.height;
|
||||||
return min(xscale, yscale);
|
return min(xscale, yscale) / 1.5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -481,6 +481,7 @@ class _RemotePageState extends State<RemotePage> {
|
|||||||
/// DoubleFiner -> right click
|
/// DoubleFiner -> right click
|
||||||
/// HoldDrag -> left drag
|
/// HoldDrag -> left drag
|
||||||
|
|
||||||
|
Offset _cacheLongPressPosition = Offset(0, 0);
|
||||||
Widget getBodyForMobileWithGesture() {
|
Widget getBodyForMobileWithGesture() {
|
||||||
final touchMode = FFI.ffiModel.touchMode;
|
final touchMode = FFI.ffiModel.touchMode;
|
||||||
return getMixinGestureDetector(
|
return getMixinGestureDetector(
|
||||||
@ -504,10 +505,14 @@ class _RemotePageState extends State<RemotePage> {
|
|||||||
},
|
},
|
||||||
onLongPressDown: (d) {
|
onLongPressDown: (d) {
|
||||||
if (touchMode) {
|
if (touchMode) {
|
||||||
FFI.cursorModel.move(d.localPosition.dx, d.localPosition.dy);
|
_cacheLongPressPosition = d.localPosition;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onLongPress: () {
|
onLongPress: () {
|
||||||
|
if (touchMode) {
|
||||||
|
FFI.cursorModel
|
||||||
|
.move(_cacheLongPressPosition.dx, _cacheLongPressPosition.dy);
|
||||||
|
}
|
||||||
FFI.tap(MouseButtons.right);
|
FFI.tap(MouseButtons.right);
|
||||||
},
|
},
|
||||||
onDoubleFinerTap: (d) {
|
onDoubleFinerTap: (d) {
|
||||||
@ -534,6 +539,15 @@ class _RemotePageState extends State<RemotePage> {
|
|||||||
if (touchMode) {
|
if (touchMode) {
|
||||||
FFI.cursorModel.move(d.localPosition.dx, d.localPosition.dy);
|
FFI.cursorModel.move(d.localPosition.dx, d.localPosition.dy);
|
||||||
FFI.sendMouse('down', MouseButtons.left);
|
FFI.sendMouse('down', MouseButtons.left);
|
||||||
|
} else {
|
||||||
|
final cursorX = FFI.cursorModel.x;
|
||||||
|
final cursorY = FFI.cursorModel.y;
|
||||||
|
final visible =
|
||||||
|
FFI.cursorModel.getVisibleRect().inflate(1); // extend edges
|
||||||
|
final size = MediaQueryData.fromWindow(ui.window).size;
|
||||||
|
if (!visible.contains(Offset(cursorX, cursorY))) {
|
||||||
|
FFI.cursorModel.move(size.width / 2, size.height / 2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onOneFingerPanUpdate: (d) {
|
onOneFingerPanUpdate: (d) {
|
||||||
|
@ -2,7 +2,7 @@ import 'dart:async';
|
|||||||
import 'package:flutter/gestures.dart';
|
import 'package:flutter/gestures.dart';
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
|
|
||||||
enum CustomTouchGestureState {
|
enum GestureState {
|
||||||
none,
|
none,
|
||||||
oneFingerPan,
|
oneFingerPan,
|
||||||
twoFingerScale,
|
twoFingerScale,
|
||||||
@ -35,64 +35,41 @@ class CustomTouchGestureRecognizer extends ScaleGestureRecognizer {
|
|||||||
GestureDragUpdateCallback? onThreeFingerVerticalDragUpdate;
|
GestureDragUpdateCallback? onThreeFingerVerticalDragUpdate;
|
||||||
GestureDragEndCallback? onThreeFingerVerticalDragEnd;
|
GestureDragEndCallback? onThreeFingerVerticalDragEnd;
|
||||||
|
|
||||||
var _currentState = CustomTouchGestureState.none;
|
var _currentState = GestureState.none;
|
||||||
Timer? _startEventDebounceTimer;
|
Timer? _debounceTimer;
|
||||||
|
|
||||||
void _init() {
|
void _init() {
|
||||||
debugPrint("CustomTouchGestureRecognizer init");
|
debugPrint("CustomTouchGestureRecognizer init");
|
||||||
onStart = (d) {
|
// onStart = (d) {};
|
||||||
_startEventDebounceTimer?.cancel();
|
onUpdate = (d) {
|
||||||
if (d.pointerCount == 1) {
|
_debounceTimer?.cancel();
|
||||||
_currentState = CustomTouchGestureState.oneFingerPan;
|
if (d.pointerCount == 1 && _currentState != GestureState.oneFingerPan) {
|
||||||
if (onOneFingerPanStart != null) {
|
onOneFingerStartDebounce(d);
|
||||||
onOneFingerPanStart!(DragStartDetails(
|
} else if (d.pointerCount == 2 &&
|
||||||
localPosition: d.localFocalPoint, globalPosition: d.focalPoint));
|
_currentState != GestureState.twoFingerScale) {
|
||||||
}
|
onTwoFingerStartDebounce(d);
|
||||||
debugPrint("start oneFingerPan");
|
} else if (d.pointerCount == 3 &&
|
||||||
} else if (d.pointerCount == 2) {
|
_currentState != GestureState.threeFingerVerticalDrag) {
|
||||||
if (_currentState == CustomTouchGestureState.threeFingerVerticalDrag) {
|
_currentState = GestureState.threeFingerVerticalDrag;
|
||||||
// 3 -> 2 debounce
|
|
||||||
_startEventDebounceTimer = Timer(Duration(milliseconds: 200), () {
|
|
||||||
_currentState = CustomTouchGestureState.twoFingerScale;
|
|
||||||
if (onTwoFingerScaleStart != null) {
|
|
||||||
onTwoFingerScaleStart!(ScaleStartDetails(
|
|
||||||
localFocalPoint: d.localFocalPoint,
|
|
||||||
focalPoint: d.focalPoint));
|
|
||||||
}
|
|
||||||
debugPrint("debounce start twoFingerScale success");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
_currentState = CustomTouchGestureState.twoFingerScale;
|
|
||||||
// startWatchTimer();
|
|
||||||
if (onTwoFingerScaleStart != null) {
|
|
||||||
onTwoFingerScaleStart!(ScaleStartDetails(
|
|
||||||
localFocalPoint: d.localFocalPoint, focalPoint: d.focalPoint));
|
|
||||||
}
|
|
||||||
debugPrint("start twoFingerScale");
|
|
||||||
} else if (d.pointerCount == 3) {
|
|
||||||
_currentState = CustomTouchGestureState.threeFingerVerticalDrag;
|
|
||||||
if (onThreeFingerVerticalDragStart != null) {
|
if (onThreeFingerVerticalDragStart != null) {
|
||||||
onThreeFingerVerticalDragStart!(
|
onThreeFingerVerticalDragStart!(
|
||||||
DragStartDetails(globalPosition: d.localFocalPoint));
|
DragStartDetails(globalPosition: d.localFocalPoint));
|
||||||
}
|
}
|
||||||
debugPrint("start threeFingerScale");
|
debugPrint("start threeFingerScale");
|
||||||
// _reset();
|
|
||||||
}
|
}
|
||||||
};
|
if (_currentState != GestureState.none) {
|
||||||
onUpdate = (d) {
|
|
||||||
if (_currentState != CustomTouchGestureState.none) {
|
|
||||||
switch (_currentState) {
|
switch (_currentState) {
|
||||||
case CustomTouchGestureState.oneFingerPan:
|
case GestureState.oneFingerPan:
|
||||||
if (onOneFingerPanUpdate != null) {
|
if (onOneFingerPanUpdate != null) {
|
||||||
onOneFingerPanUpdate!(_getDragUpdateDetails(d));
|
onOneFingerPanUpdate!(_getDragUpdateDetails(d));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CustomTouchGestureState.twoFingerScale:
|
case GestureState.twoFingerScale:
|
||||||
if (onTwoFingerScaleUpdate != null) {
|
if (onTwoFingerScaleUpdate != null) {
|
||||||
onTwoFingerScaleUpdate!(d);
|
onTwoFingerScaleUpdate!(d);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CustomTouchGestureState.threeFingerVerticalDrag:
|
case GestureState.threeFingerVerticalDrag:
|
||||||
if (onThreeFingerVerticalDragUpdate != null) {
|
if (onThreeFingerVerticalDragUpdate != null) {
|
||||||
onThreeFingerVerticalDragUpdate!(_getDragUpdateDetails(d));
|
onThreeFingerVerticalDragUpdate!(_getDragUpdateDetails(d));
|
||||||
}
|
}
|
||||||
@ -105,21 +82,22 @@ class CustomTouchGestureRecognizer extends ScaleGestureRecognizer {
|
|||||||
};
|
};
|
||||||
onEnd = (d) {
|
onEnd = (d) {
|
||||||
debugPrint("ScaleGestureRecognizer onEnd");
|
debugPrint("ScaleGestureRecognizer onEnd");
|
||||||
|
_debounceTimer?.cancel();
|
||||||
// end
|
// end
|
||||||
switch (_currentState) {
|
switch (_currentState) {
|
||||||
case CustomTouchGestureState.oneFingerPan:
|
case GestureState.oneFingerPan:
|
||||||
debugPrint("TwoFingerState.pan onEnd");
|
debugPrint("TwoFingerState.pan onEnd");
|
||||||
if (onOneFingerPanEnd != null) {
|
if (onOneFingerPanEnd != null) {
|
||||||
onOneFingerPanEnd!(_getDragEndDetails(d));
|
onOneFingerPanEnd!(_getDragEndDetails(d));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CustomTouchGestureState.twoFingerScale:
|
case GestureState.twoFingerScale:
|
||||||
debugPrint("TwoFingerState.scale onEnd");
|
debugPrint("TwoFingerState.scale onEnd");
|
||||||
if (onTwoFingerScaleEnd != null) {
|
if (onTwoFingerScaleEnd != null) {
|
||||||
onTwoFingerScaleEnd!(d);
|
onTwoFingerScaleEnd!(d);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CustomTouchGestureState.threeFingerVerticalDrag:
|
case GestureState.threeFingerVerticalDrag:
|
||||||
debugPrint("ThreeFingerState.vertical onEnd");
|
debugPrint("ThreeFingerState.vertical onEnd");
|
||||||
if (onThreeFingerVerticalDragEnd != null) {
|
if (onThreeFingerVerticalDragEnd != null) {
|
||||||
onThreeFingerVerticalDragEnd!(_getDragEndDetails(d));
|
onThreeFingerVerticalDragEnd!(_getDragEndDetails(d));
|
||||||
@ -128,10 +106,50 @@ class CustomTouchGestureRecognizer extends ScaleGestureRecognizer {
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
_currentState = CustomTouchGestureState.none;
|
_debounceTimer = Timer(Duration(milliseconds: 200), () {
|
||||||
|
_currentState = GestureState.none;
|
||||||
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void onOneFingerStartDebounce(ScaleUpdateDetails d) {
|
||||||
|
final start = (ScaleUpdateDetails d) {
|
||||||
|
_currentState = GestureState.oneFingerPan;
|
||||||
|
if (onOneFingerPanStart != null) {
|
||||||
|
onOneFingerPanStart!(DragStartDetails(
|
||||||
|
localPosition: d.localFocalPoint, globalPosition: d.focalPoint));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if (_currentState != GestureState.none) {
|
||||||
|
_debounceTimer = Timer(Duration(milliseconds: 200), () {
|
||||||
|
start(d);
|
||||||
|
debugPrint("debounce start oneFingerPan");
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
start(d);
|
||||||
|
debugPrint("start oneFingerPan");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void onTwoFingerStartDebounce(ScaleUpdateDetails d) {
|
||||||
|
final start = (ScaleUpdateDetails d) {
|
||||||
|
_currentState = GestureState.twoFingerScale;
|
||||||
|
if (onTwoFingerScaleStart != null) {
|
||||||
|
onTwoFingerScaleStart!(ScaleStartDetails(
|
||||||
|
localFocalPoint: d.localFocalPoint, focalPoint: d.focalPoint));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if (_currentState == GestureState.threeFingerVerticalDrag) {
|
||||||
|
_debounceTimer = Timer(Duration(milliseconds: 200), () {
|
||||||
|
start(d);
|
||||||
|
debugPrint("debounce start twoFingerScale");
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
start(d);
|
||||||
|
debugPrint("start twoFingerScale");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
DragUpdateDetails _getDragUpdateDetails(ScaleUpdateDetails d) =>
|
DragUpdateDetails _getDragUpdateDetails(ScaleUpdateDetails d) =>
|
||||||
DragUpdateDetails(
|
DragUpdateDetails(
|
||||||
globalPosition: d.focalPoint,
|
globalPosition: d.focalPoint,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user