class_name GameWindow extends Control var is_dragging := false var drag_anchor := Vector2.ZERO var is_resizeing := false @export var closeable := false: set = _set_closeable @export var resizeable := false: set = _set_resizeable @export var minimum_size: Vector2 func _ready() -> void: # trigger initially closeable = closeable resizeable = resizeable if not minimum_size: minimum_size = size # move elements above resize handle for node: Control in %ButtonBarElements.get_children(): node.z_index += 1 func _process(_delta: float) -> void: if is_dragging: global_position += get_global_mouse_position() - drag_anchor #%TitleBar.size # TODO: use title bar size as min/max. dont let the bar vanish drag_anchor = get_global_mouse_position() func _input(event: InputEvent) -> void: if is_resizeing and event is InputEventMouseMotion: size = Vector2( max(minimum_size.x, size.x + event.relative.x), max(minimum_size.y, size.y + event.relative.y) ) func _set_closeable(value: bool) -> void: closeable = value %CloseButton.visible = closeable func _set_resizeable(value: bool) -> void: resizeable = value %ResizeHandle.visible = resizeable func _on_title_bar_gui_input(event: InputEvent) -> void: if event.is_action_pressed("primary_click"): is_dragging = true drag_anchor = get_global_mouse_position() elif event.is_action_released("primary_click"): is_dragging = false func _on_resize_handle_gui_input(event: InputEvent) -> void: if event.is_action_pressed("primary_click"): is_resizeing = true elif event.is_action_released("primary_click"): is_resizeing = false func _on_close_button_pressed() -> void: queue_free()