Skip to content
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

InputEventMouseButton global_position becomes broken when window is resized #88460

Closed
MatrixDev opened this issue Feb 17, 2024 · 3 comments · Fixed by #88473
Closed

InputEventMouseButton global_position becomes broken when window is resized #88460

MatrixDev opened this issue Feb 17, 2024 · 3 comments · Fixed by #88473

Comments

@MatrixDev
Copy link

Tested versions

  • reproducable in v4.2.1.stable.official [b09f793]

System information

MacOS 14.1.1 - Vulkan API 1.2.231 - Forward+ - Apple M1 Max

Issue description

Following methods return "system" mouse position values:

  • InputEventMouseButton.global_position (left, pressed)

While "scaled" mouse position values are returned by:

  • InputEventMouseMotion.global_position
  • CanvasItem.get_global_mouse_position

This happens only after resizing (or maximizing) a window.

Steps to reproduce

Display -> Window -> Stretch:

  • Mode = canvas_item
  • Aspect = expand

Scene with a control node. Override _gui_input method and log InputEventMouseMotion and InputEventMouseButton events together with get_global_mouse_position result.

Before resizing a window (InputEventMouseButtonB is the same as others):

InputEventMouseButtonA -> (508, 890)
InputEventMouseButtonB -> (508, 889)
InputEventMouseMotion -> (508, 889)
InputEventMouseMotion -> (508, 888)
InputEventMouseMotion -> (508, 887)
InputEventMouseMotion -> (508, 886)
InputEventMouseMotion -> (508, 885)
InputEventMouseMotion -> (508, 884)

After resizing a window (InputEventMouseButtonB is ~2x larger than others):

InputEventMouseButtonA -> (510.00003, 951.5881)
InputEventMouseButtonB -> (918, 1712)
InputEventMouseMotion -> (510.00003, 950.47766)
InputEventMouseMotion -> (510.00003, 949.9225)
InputEventMouseMotion -> (510.00003, 949.3673)
InputEventMouseMotion -> (510.00003, 948.81213)
InputEventMouseMotion -> (510.00003, 948.25696)
InputEventMouseMotion -> (510.00003, 947.7017)

Where:

  • InputEventMouseButtonA - CanvasItem.get_global_mouse_position
  • InputEventMouseButtonB - InputEventMouseButton.global_position (left, pressed)
  • InputEventMouseMotion - InputEventMouseMotion.global_position

Minimal reproduction project (MRP)

[gd_scene load_steps=2 format=3 uid="uid://b6r6gvimt6r0p"]

[sub_resource type="GDScript" id="GDScript_gjswp"]
script/source = "extends Control

var pressed = false

func _gui_input(event):
	if event is InputEventMouseButton:
		pressed = event.is_pressed()
		
		if pressed:
			print(\"InputEventMouseButtonA -> \", get_global_mouse_position())
			print(\"InputEventMouseButtonB -> \", event.global_position)

	if event is InputEventMouseMotion && pressed:
		print(\"InputEventMouseMotion -> \", event.global_position)
"

[node name="Control" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = SubResource("GDScript_gjswp")
@AThousandShips
Copy link
Member

Please upload a project, to help with testing this and identifying the exact problem

  • A small Godot project which reproduces the issue, with no unnecessary files included. Be sure to not include the .godot folder in the archive (but keep project.godot).
  • Having an MRP is very important for contributors to be able to reproduce the bug in the same way that you are experiencing it. When testing a potential fix for the issue, contributors will use the MRP to validate that the fix is working as intended.
  • Drag and drop a ZIP archive to upload it (max 10 MB). Do not select another field until the project is done uploading.
  • Note for C# users: If your issue is not C#-specific, please upload a minimal reproduction project written in GDScript. This will make it easier for contributors to reproduce the issue locally as not everyone has a .NET setup available.

@MatrixDev
Copy link
Author

@AThousandShips, sure, no problem.
Bug88460.zip

@kleonc
Copy link
Member

kleonc commented Feb 17, 2024

Happens since... v4.0.beta13.official [caacade]. Hence likely a regression from #69598. cc @Sauermann

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants