Zooming runs great now. Had to implement some Limits to not get into the negative area.
For the drag & drop of the scene position I now have two approaches which are both somehow working.
One approach moves the Camera which causes some impreciseness concerning the relation between mouse, cam and scene position. I think this is caused by the zoom of the camera and the non linar relation between camera and scene position.
The other approach which might be the better one, moves the main node, but makes some problems withe the viewport or similar, which causes the scene to snap back the sceneposition when the mouse leaves a certain area.
Edit: It now works. Just had to disable current for the camera again.
Here is the script:
#Input handler, listen for ESC to exit app
func _input(event):
if(event.is_pressed()):
if(Input.is_key_pressed(KEY_ESCAPE)):
get_tree().quit()
var zoom = get_node("camera").get_zoom()
if (event.type == InputEvent.MOUSE_MOTION):
if(drag == true):
# print(initPosMouse)
var mouse_pos = get_global_mouse_pos()
# var cam_pos = get_node("camera").get_pos()
var dist_x
var dist_y
dist_x = initPosMouse.x - mouse_pos.x
dist_y = initPosMouse.y - mouse_pos.y
# var mx = cam_pos.x - (mouse_pos.x)
# var my = cam_pos.y - (mouse_pos.y)
var mx = initPosCam.x - (0 - dist_x)
var my = initPosCam.y - (0 - dist_y)
var nx = initPosNode.x - (0 + dist_x)
var ny = initPosNode.y - (0 + dist_y)
# get_node("camera").set_pos(Vector2(mx,my))
get_node(".").set_pos(Vector2(nx,ny))
elif(drag == false):
# print("undrag")
pass
# get_node("camera").set_pos()
if (event.type == InputEvent.MOUSE_BUTTON):
if (event.button_index == BUTTON_WHEEL_UP):
# print("wheel up (event)")
zoom[0] = zoom[0] + 0.25
zoom[1] = zoom[1] + 0.25
if (event.button_index == BUTTON_WHEEL_DOWN):
# print("wheel down (event)")
if(zoom[0] - 0.25 > 0 && zoom[1] - 0.25 > 0):
zoom[0] = zoom[0] - 0.25
zoom[1] = zoom[1] - 0.25
if (event.button_index == BUTTON_MIDDLE):
if(Input.is_mouse_button_pressed(3)):
print("button middle")
# print(get_viewport().get_mouse_pos())
# var mouse_pos = get_global_mouse_pos()
# initPos = get_viewport().get_mouse_pos()
initPosMouse = get_global_mouse_pos()
initPosCam = get_node("camera").get_pos()
initPosNode = get_node(".").get_pos()
drag = true
else:
print("button middle release")
drag = false
get_node("camera").set_zoom(zoom)