summaryrefslogtreecommitdiff
path: root/ui/window.gd
diff options
context:
space:
mode:
Diffstat (limited to 'ui/window.gd')
-rw-r--r--ui/window.gd55
1 files changed, 54 insertions, 1 deletions
diff --git a/ui/window.gd b/ui/window.gd
index 25b0988..8e6525a 100644
--- a/ui/window.gd
+++ b/ui/window.gd
@@ -1,9 +1,33 @@
-extends PanelContainer
+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:
@@ -12,9 +36,38 @@ func _process(_delta: float) -> void:
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()