-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
2d
or viewport
stretch mode does not scale mouse coordinates
#34805
Comments
You can manually compensate the mouse coordinates to take scaling into account: # `get_size_override()` will return a valid size only if the stretch mode is `2d`.
# Otherwise, the viewport size is used directly.
var viewport_base_size = (
get_viewport().get_size_override() if get_viewport().get_size_override() > Vector2(0, 0)
else get_viewport().size
) This should make the coordinates behave seamlessly regardless of the current stretch mode. |
@Calinou Sorry, I'm still not a pro with Godot. Where do I have to place this code in my demo project? I tried it in the Viewport.gd script and in a script attached only to the real Viewport in the scene. Both didn't work. I guess I will have to tell Godot somehow to use the result of this variable for the mouse scaling, but I'm not sure how exactly. |
I just got bitten by that one! Workaround: instead of using |
@Calinou In 3d gui , code uses "on mouse enter" how can I fix it? |
@RedHeadphone This repository is meant to be used for bug reports only. For support questions, please use one of the other community channels instead. |
Hello, We have the same error, you can see the projet here https://github.com/salty64/Godot_Obj_viewer/tree/master/src. I made the little project with this error in a days. Parameters are "2d" and "Keep". We correct it with : #get the real size of the viewport
var root_size = $"/root".size
#calculate black strip
var correction = (OS.get_window_size() - root_size)/2.0
#we use fixed resolution of 1600 * 900
var ratio = Vector2(1600.0, 900.0)/root_size
var real_mouse_position = (get_viewport().get_mouse_position()-correction)*ratio Scene Tree : Where get_mouse_position() is declared in scene/main/viewport.cpp : here |
For drag-and-drop code, use something like this (tested with the func _input(event):
# ...
var viewport_base_size = (
get_viewport().get_size_override() if get_viewport().get_size_override() > Vector2(0, 0)
else get_viewport().size
)
var scale_factor = OS.window_size / viewport_base_size
target.global_position = event.global_position / scale_factor Regarding the original issue, I wonder if a |
2d
or viewport
stretch mode does not scale mouse coordinates
Godot version:
Godot_v3.2-beta5_x11
OS/device including version:
Manjaro Linux (rolling (as of 2020-01-04))
Issue description:
I placed my games view in a viewport which itself is placed within a ViewportContainer.
I attached a script to it to scale the viewport to the current display/window size.
The scaling of the graphics work, but the mouse coordinates are not scaled with them.
Mouse detection on Controls is still acting as if the Viewport would not be scaled up.
You can see it in action in the beginning of this video I made:
https://www.youtube.com/watch?v=c58L8MyqYEU
Additional / what I found out so far:
If i disable and re-enable the "handle input locally" option of the viewport during runtime, it works as long as I don't change the window size. (another bug?)
Steps to reproduce:
Make a 2D scene with some controls in it (for example buttons).
Scale up this scene with with a Viewport within a ViewportContainer.
(You can do it easier and during the game is running for example by using a script like the one that I used in the demo / reproduction project linked below.)
Minimal reproduction project:
https://github.com/Bleuzen/godot-viewport-scaling-bug-demo
The text was updated successfully, but these errors were encountered: