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

Editor viewport global_canvas_transform auto reset when mouse hover on viewport #57898

Open
yikescloud opened this issue Feb 10, 2022 · 4 comments

Comments

@yikescloud
Copy link

Godot version

3.4.2 stable[45eaa2d] steam version

System information

windows 10

Issue description

When use set_global_canvas_transform() on editor viewport, the editor viewport transform immediately
EditorTransform tscn - EditorCanvasTransform - Godot Engine-2022-02-10 16_20_52
But when any input(keyboard pressed, or mouse hovered on canvas editor), it will be reset as before. And the transform only change the item on canvas but not the hints( grids, axis..etc)

Steps to reproduce

Add a tool script then call
get_tree().edited_scene_root.get_viewport().set_global_canvas_transform()

Minimal reproduction project

EditorCanvasTransform.zip

@yikescloud
Copy link
Author

yikescloud commented Feb 11, 2022

Finally I figure it out that you cannot change canvas item editor position by set the viewport's global_canvas_transform. I think the document should be point it out maybe.

Canvas Item Editor hierarchy

  • Control
    • ViewportContainer
      • Viewport(edit_scene_root viewport)
    • CanvasItemEditorViewport
      • HScrollBar(CanvasItem Editor scrollbar)
      • VScrollBar(CanvasItem Editor scrollbar)
      • VBoxContainer
    • VBoxContainer

For anyone who wants change editor center by code:

func set_editor_centor(var _center: Vector2):#set editor 2d center
	var v = get_tree().edited_scene_root.get_viewport()
	var t = v.global_canvas_transform
	var s = t.get_scale()
	var _center_offset = (v.size/s.x)/2#canvas editor center offset
	_center = _center - _center_offset
	
	var p = v.get_parent().get_parent()
	for i in p.get_children():
		print(i.get_class())
		if i.get_class() == "CanvasItemEditorViewport":
			for j in i.get_children():
				if j.get_class() == "HScrollBar":
					j.set_value(_center.x)
				elif j.get_class() == "VScrollBar":
					j.set_value(_center.y)

@Calinou
Copy link
Member

Calinou commented Feb 11, 2022

See also godotengine/godot-proposals#1302.

@KoBeWi
Copy link
Member

KoBeWi commented Dec 30, 2023

Reopening. #68696 was merged and changing global_canvas_transform is supposedly the recommended way to access canvas transform (and modify it). However this issue still persists.

Not sure how it should be solved.

@KoBeWi
Copy link
Member

KoBeWi commented Dec 31, 2023

In the meantime, here's a more robust solution for setting both zoom and position:

var editor = EditorInterface.get_base_control().find_child("@CanvasItemEditorViewport*", true, false)

var zoomer = editor.find_child("@EditorZoomWidget*", true, false)
zoomer.set_zoom(zoom)
zoomer.zoom_changed.emit(zoom)

var scroll = editor.find_child("@HScrollBar*", true, false)
scroll.value = pos.x
scroll = editor.find_child("@VScrollBar*", true, false)
scroll.value = pos.y

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

No branches or pull requests

4 participants