-
-
Notifications
You must be signed in to change notification settings - Fork 899
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added componentsAtPoint() iterable (#1518)
- Loading branch information
Showing
19 changed files
with
354 additions
and
29 deletions.
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
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
27 changes: 27 additions & 0 deletions
27
packages/flame/lib/src/components/component_point_pair.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,27 @@ | ||
import 'dart:ui'; | ||
|
||
import 'package:meta/meta.dart'; | ||
import 'package:vector_math/vector_math_64.dart'; | ||
|
||
import 'component.dart'; | ||
|
||
/// A simple tuple of a component and a point. This is a helper class for the | ||
/// [Component.componentsAtPoint] method. | ||
@immutable | ||
class ComponentPointPair { | ||
const ComponentPointPair(this.component, this.point); | ||
final Component component; | ||
final Vector2 point; | ||
|
||
@override | ||
bool operator ==(Object other) => | ||
other is ComponentPointPair && | ||
other.component == component && | ||
other.point == point; | ||
|
||
@override | ||
int get hashCode => hashValues(component, point); | ||
|
||
@override | ||
String toString() => '<$component, $point>'; | ||
} |
24 changes: 24 additions & 0 deletions
24
packages/flame/lib/src/components/mixins/coordinate_transform.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,24 @@ | ||
import 'package:vector_math/vector_math_64.dart'; | ||
import '../component.dart'; | ||
|
||
/// Interface to be implemented by components that perform a coordinate change. | ||
/// | ||
/// Any [Component] that does any coordinate transformation of the canvas during | ||
/// rendering should consider implementing this interface in order to describe | ||
/// how the points from the parent's coordinate system relate to the component's | ||
/// local coordinate system. | ||
/// | ||
/// This interface assumes that the component performs a "uniform" coordinate | ||
/// transformation, that is, the transform applies to all children of the | ||
/// component equally. If that is not the case (for example, the component does | ||
/// different transformations for some of its children), then that component | ||
/// must implement [Component.componentsAtPoint] method instead. | ||
/// | ||
/// The two methods of this interface convert between the parent's coordinate | ||
/// space and the local coordinates. The methods may also return `null`, | ||
/// indicating that the given cannot be mapped to any local/parent point. | ||
abstract class CoordinateTransform { | ||
Vector2? parentToLocal(Vector2 point); | ||
|
||
Vector2? localToParent(Vector2 point); | ||
} |
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
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
Oops, something went wrong.