Skip to content

Commit 2f3673f

Browse files
authored
Merge pull request #56 from GrandChaman/fix-window-as-anchor
Prevent windows hits from being used as anchors
2 parents 1ae39bd + d25a334 commit 2f3673f

File tree

2 files changed

+29
-22
lines changed

2 files changed

+29
-22
lines changed

Cargo.toml

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,27 @@ extension_anchor_indicator = ["bevy_gizmos"]
1515
extension_independent_skybox = ["bevy_asset", "bevy_core_pipeline"]
1616

1717
[dependencies]
18-
bevy_app = "0.17.1"
19-
bevy_color = "0.17.1"
20-
bevy_derive = "0.17.1"
21-
bevy_ecs = "0.17.1"
22-
bevy_image = "0.17.1"
23-
bevy_input = "0.17.1"
24-
bevy_log = "0.17.1"
25-
bevy_math = "0.17.1"
26-
bevy_picking = "0.17.1"
27-
bevy_reflect = "0.17.1"
28-
bevy_camera = "0.17.1"
29-
bevy_render = "0.17.1"
30-
bevy_time = "0.17.1"
31-
bevy_transform = "0.17.1"
32-
bevy_utils = "0.17.1"
33-
bevy_window = "0.17.1"
34-
bevy_platform = "0.17.1"
18+
bevy_app = "0.17.3"
19+
bevy_color = "0.17.3"
20+
bevy_derive = "0.17.3"
21+
bevy_ecs = "0.17.3"
22+
bevy_image = "0.17.3"
23+
bevy_input = "0.17.3"
24+
bevy_log = "0.17.3"
25+
bevy_math = "0.17.3"
26+
bevy_picking = "0.17.3"
27+
bevy_reflect = "0.17.3"
28+
bevy_camera = "0.17.3"
29+
bevy_render = "0.17.3"
30+
bevy_time = "0.17.3"
31+
bevy_transform = "0.17.3"
32+
bevy_utils = "0.17.3"
33+
bevy_window = "0.17.3"
34+
bevy_platform = "0.17.3"
3535
# Optional
36-
bevy_asset = { version = "0.17.1", optional = true }
37-
bevy_core_pipeline = { version = "0.17.1", optional = true }
38-
bevy_gizmos = { version = "0.17.1", optional = true }
36+
bevy_asset = { version = "0.17.3", optional = true }
37+
bevy_core_pipeline = { version = "0.17.3", optional = true }
38+
bevy_gizmos = { version = "0.17.3", optional = true }
3939

4040
[dev-dependencies]
4141
bevy_framepace = "0.20"
@@ -44,7 +44,7 @@ indoc = "2.0.5"
4444
rand = "0.9"
4545

4646
[dev-dependencies.bevy]
47-
version = "0.17.0"
47+
version = "0.17.3"
4848
features = [
4949
"bevy_gizmos",
5050
"bevy_gltf",

src/input.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use bevy_math::{prelude::*, DVec2, DVec3};
1212
use bevy_platform::collections::HashMap;
1313
use bevy_reflect::prelude::*;
1414
use bevy_transform::prelude::*;
15-
use bevy_window::PrimaryWindow;
15+
use bevy_window::{PrimaryWindow, Window};
1616

1717
use bevy_picking::pointer::{
1818
PointerAction, PointerId, PointerInput, PointerInteraction, PointerLocation, PointerMap,
@@ -183,6 +183,7 @@ impl EditorCamInputMessage {
183183
}
184184

185185
/// Receive [`EditorCamInputMessage`]s, and use these to start and end moves on the [`EditorCam`].
186+
#[allow(clippy::too_many_arguments)]
186187
pub fn receive_messages(
187188
mut events: MessageReader<Self>,
188189
mut controllers: Query<(&mut EditorCam, &GlobalTransform)>,
@@ -191,6 +192,7 @@ impl EditorCamInputMessage {
191192
pointer_interactions: Query<&PointerInteraction>,
192193
pointer_locations: Query<&PointerLocation>,
193194
cameras: Query<(&Camera, &Projection)>,
195+
windows: Query<&Window>,
194196
) {
195197
for event in events.read() {
196198
let Ok((mut controller, cam_transform)) = controllers.get_mut(event.camera()) else {
@@ -206,6 +208,11 @@ impl EditorCamInputMessage {
206208
.get_entity(*pointer)
207209
.and_then(|entity| pointer_interactions.get(entity).ok())
208210
.and_then(|interaction| interaction.get_nearest_hit())
211+
// Since `bevy` 0.17.3:
212+
//
213+
// If the current hit is on a window, we cannot use the `hit.position` as an anchor
214+
// as the `hit.position` is in viewport coordinates.
215+
.filter(|(entity, _hit)| !windows.contains(*entity))
209216
.and_then(|(_, hit)| hit.position)
210217
.map(|world_space_hit| {
211218
// Convert the world space hit to view (camera) space

0 commit comments

Comments
 (0)