As mentioned by 1234ab in the other comment: You'll need to save and redraw all previous rectangles for that:
extends Control
var mouse_pos = Vector2()
var dragging = false
var drag_start = Vector2.ZERO
var rectangles := []
func _unhandled_input(event):
if event is InputEventMouseButton and event.button_index == BUTTON_LEFT:
if event.pressed:
dragging = true
drag_start = event.position
rectangles.push_front(Rect2(drag_start, Vector2.ZERO))
elif dragging:
dragging = false
update()
if event is InputEventMouseMotion and dragging:
rectangles[0] = Rect2(drag_start, get_global_mouse_position() - drag_start)
update()
func _draw():
for r in rectangles:
draw_rect(r, Color(.5,.5,.5), false)