extends Node2D

## Custom Draw Demo: Understanding _draw() and queue_redraw()

var target_position = Vector2.ZERO

func _ready():
	$Label.text = "Mouse is moving!\nTarget: " + str(target_position)
	$StatusLabel.text = "Drawing Active!"
	$StatusLabel.modulate = Color.GREEN

func _process(_delta):
	# We ALWAYS update the logic (target position)
	target_position = get_global_mouse_position()
	
	$Label.text = "Mouse is moving!\nTarget: " + str(target_position)
	
	# But we ONLY tell Godot to visually update if the checkbox is checked
	if $CheckBox.button_pressed:
		queue_redraw()
		$StatusLabel.text = "queue_redraw() is RUNNING\nScreen updates match logic."
		$StatusLabel.modulate = Color.GREEN
	else:
		$StatusLabel.text = "queue_redraw() is STOPPED\nLogic updates, but visual is frozen!"
		$StatusLabel.modulate = Color.RED

func _draw():
	# This function only runs when queue_redraw() schedules it!
	
	var radius = 40.0
	var color = Color(0.2, 0.6, 1.0, 0.8) if $CheckBox.button_pressed else Color(1.0, 0.2, 0.2, 0.8)
	
	# Draw a crosshair target
	draw_circle(target_position, radius, Color(color.r, color.g, color.b, 0.3))
	draw_arc(target_position, radius, 0, TAU, 32, color, 3.0)
	draw_line(target_position - Vector2(15, 0), target_position + Vector2(15, 0), color, 3.0)
	draw_line(target_position - Vector2(0, 15), target_position + Vector2(0, 15), color, 3.0)
	
	# Draw connecting line from center
	var screen_center = get_viewport_rect().size / 2.0
	draw_line(screen_center, target_position, color, 2.0)
