1
0
Fork 0
ExampleProject/RetroWindowsGUI/DesktopWindow.gd

72 lines
2.0 KiB
GDScript3
Raw Normal View History

2024-03-19 07:52:57 +00:00
class_name DesktopWindow
extends Control
@export var desktop: Desktop # desktop
@export var maximized_windows: Control # maximized windows
@export var taskbar: Control # taskbar
var windowed_rect: Rect2
func get_descendants(node: Node) -> Array[Node]:
var nodes: Array[Node] = []
for child in node.get_children():
if child.get_child_count() > 0:
nodes.append(child)
nodes.append_array(get_descendants(child))
else:
nodes.append(child)
return nodes
func _ready() -> void:
for descendant in get_descendants(self):
descendant.gui_input.connect(_gui_input)
func _gui_input(event: InputEvent) -> void:
2024-03-19 07:52:57 +00:00
if event is InputEventMouseButton:
if event.pressed:
if get_global_rect().has_point(get_global_mouse_position()):
desktop.current_window = self
get_parent().move_child(self, get_parent().get_child_count())
func _input(event: InputEvent):
if event is InputEventKey:
2024-03-19 07:52:57 +00:00
if event.keycode == KEY_F11:
if event.pressed:
if desktop.current_window == self:
toggle_maximized()
elif event.alt_pressed and event.keycode == KEY_UP:
if event.pressed:
if desktop.current_window == self:
if not visible:
visible = true
elif not anchors_preset == Control.PRESET_FULL_RECT:
windowed_rect = get_global_rect()
set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
elif event.alt_pressed and event.keycode == KEY_DOWN:
if event.pressed:
if desktop.current_window == self:
if anchors_preset == Control.PRESET_FULL_RECT:
set_anchors_and_offsets_preset(Control.PRESET_TOP_LEFT)
position = windowed_rect.position
size = windowed_rect.size
elif visible:
visible = false
2024-03-19 07:52:57 +00:00
# toggle maximized
func toggle_maximized():
if anchors_preset == Control.PRESET_FULL_RECT:
set_anchors_and_offsets_preset(Control.PRESET_TOP_LEFT)
2024-03-19 07:52:57 +00:00
position = windowed_rect.position
size = windowed_rect.size
else:
windowed_rect = get_global_rect()
set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
2024-03-19 07:52:57 +00:00
func close():
visible = false
func minimize():
visible = false