extends TextureRect

## Area where the checks of a test can be edited.

signal area_added(position: Vector2, size: Vector2, color: Color)

@onready var color_picker: ColorPickerButton = %ResultRectColorPickerButton

var start_point

func _gui_input(event: InputEvent) -> void:
	var button_event := event as InputEventMouseButton
	if button_event and button_event.button_index == MOUSE_BUTTON_LEFT:
		if button_event.is_released():
			area_added.emit(start_point, button_event.position,
					color_picker.color)
			start_point = null
		else:
			start_point = button_event.position
	queue_redraw()


func _draw() -> void:
	if start_point:
		draw_rect(Rect2(start_point, get_local_mouse_position() - start_point), color_picker.color)