-
-
Notifications
You must be signed in to change notification settings - Fork 899
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Added the onLongTapDown event #1587
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
7bc25c5
make variable var lastGeneratedDragId = 0;
st-pasha 978457a
refactor code in advanced gesture detectors
st-pasha 6f4f020
added MultiTapListener
st-pasha 40638ac
added onLongTapDown
st-pasha 6bfedd1
docs
st-pasha a172de5
Merge branch 'main' into ps/merge-events
st-pasha 37be0a6
move has_tappables
st-pasha 04c928b
moved MultiTouchTapDetector
st-pasha 6e8defe
Move multi_tap_listener
st-pasha e4719e2
format
st-pasha 908aa2b
move tappable
st-pasha 150a7b6
update docstrings
st-pasha f6a0332
added test for long tap down
st-pasha 77f2a44
docs
st-pasha be31f72
Merge branch 'main' into ps/merge-events
st-pasha bf30a44
move back Tappable
st-pasha 8d58f26
move back HasTappables
st-pasha 6562837
move MultiTouchTapDetector
st-pasha f3436d6
format
st-pasha aca5354
Merge branch 'main' into ps/merge-events
st-pasha 08b7eb6
Update packages/flame/lib/src/game/mixins/has_tappables.dart
st-pasha 5b6c1b5
Merge branch 'main' into ps/merge-events
spydon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
/// {@canonicalFor joystick_component.JoystickComponent} | ||
/// {@canonicalFor joystick_component.JoystickDirection} | ||
|
||
export 'src/components/input/button_component.dart'; | ||
export 'src/components/input/hud_button_component.dart'; | ||
export 'src/components/input/hud_margin_component.dart'; | ||
export 'src/components/input/joystick_component.dart'; | ||
export 'src/components/input/sprite_button_component.dart'; | ||
export 'src/extensions/vector2.dart'; | ||
export 'src/game/mixins/keyboard.dart'; | ||
export 'src/game/mixins/multi_touch_tap_detector.dart'; | ||
export 'src/gestures/detectors.dart'; | ||
export 'src/gestures/events.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
packages/flame/lib/src/events/interfaces/multi_tap_listener.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import 'package:flutter/gestures.dart'; | ||
|
||
import '../../game/mixins/has_tappables.dart'; | ||
import '../../game/mixins/multi_touch_tap_detector.dart'; | ||
|
||
/// Interface that must be implemented by a game in order for it to be eligible | ||
/// to receive events from a [MultiTapGestureRecognizer]. | ||
/// | ||
/// Instead of implementing this class directly consider using one of the | ||
/// prebuilt mixins: | ||
/// - [HasTappables] for a `FlameGame` | ||
/// - [MultiTouchTapDetector] for a custom `Game` | ||
abstract class MultiTapListener { | ||
/// The amount of time before the "long tap down" event is triggered. | ||
double get longTapDelay; | ||
|
||
/// A tap has occurred. | ||
void handleTap(int pointerId); | ||
|
||
/// A pointer has touched the screen. | ||
void handleTapDown(int pointerId, TapDownDetails details); | ||
|
||
/// A pointer stopped contacting the screen. | ||
void handleTapUp(int pointerId, TapUpDetails details); | ||
|
||
/// A pointer that already triggered [handleTapDown] will not trigger | ||
/// [handleTap]. | ||
void handleTapCancel(int pointerId); | ||
|
||
/// A pointer that has previously triggered [handleTapDown] is still touching | ||
/// the screen after [longTapDelay] seconds. | ||
void handleLongTapDown(int pointerId, TapDownDetails details); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
packages/flame/lib/src/game/mixins/multi_touch_tap_detector.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import 'package:flutter/gestures.dart'; | ||
|
||
import '../../events/interfaces/multi_tap_listener.dart'; | ||
import '../../gestures/events.dart'; | ||
import 'game.dart'; | ||
import 'has_tappables.dart'; | ||
|
||
/// Mixin that can be added to a [Game] allowing it to receive tap events. | ||
/// | ||
/// The user can override one of the callback methods | ||
/// - [onTapDown] | ||
/// - [onLongTapDown] | ||
/// - [onTapUp] | ||
/// - [onTapCancel] | ||
/// - [onTap] | ||
/// in order to respond to each corresponding event. Those events whose methods | ||
/// are not overridden are ignored. | ||
/// | ||
/// See [MultiTapGestureRecognizer] for the description of each individual | ||
/// event. If your game is derived from the FlameGame class, consider using the | ||
/// [HasTappables] mixin instead. | ||
mixin MultiTouchTapDetector on Game implements MultiTapListener { | ||
void onTapDown(int pointerId, TapDownInfo info) {} | ||
void onLongTapDown(int pointerId, TapDownInfo info) {} | ||
void onTapUp(int pointerId, TapUpInfo info) {} | ||
void onTapCancel(int pointerId) {} | ||
void onTap(int pointerId) {} | ||
|
||
//#region MultiTapListener API | ||
@override | ||
double get longTapDelay => 0.300; | ||
|
||
@override | ||
void handleTap(int pointerId) => onTap(pointerId); | ||
|
||
@override | ||
void handleTapCancel(int pointerId) => onTapCancel(pointerId); | ||
|
||
@override | ||
void handleTapDown(int pointerId, TapDownDetails details) { | ||
onTapDown(pointerId, TapDownInfo.fromDetails(this, details)); | ||
} | ||
|
||
@override | ||
void handleTapUp(int pointerId, TapUpDetails details) { | ||
onTapUp(pointerId, TapUpInfo.fromDetails(this, details)); | ||
} | ||
|
||
@override | ||
void handleLongTapDown(int pointerId, TapDownDetails details) { | ||
onLongTapDown(pointerId, TapDownInfo.fromDetails(this, details)); | ||
} | ||
//#endregion | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe I am misremembering, lmk if this comment makes sense, but can't you use MultiTouchTapDetector on
FlameGames
if you are not using tappables and want to listen to multi-touch events?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since FlameGame is a Game, you can absolutely use MultiTouchTapDetector on it. The HasTappables mixing is just a more concrete implementation, which ensures the event propagates down into the component tree.