-
Notifications
You must be signed in to change notification settings - Fork 1
/
FOWindow.gd
65 lines (46 loc) · 1.7 KB
/
FOWindow.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
tool
class_name FOWindow
extends NinePatchRect
export var Title: String = "Window Title" setget set_title
enum {NONE, RESIZE, DRAG, PINNED}
var state = NONE
var mouse_pos_offset: Vector2
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
func _input(event):
if event is InputEventMouseButton:
if event.button_index != BUTTON_LEFT:
return
match state:
NONE:
if event.pressed:
var mouse_pos = get_global_mouse_position()
if $Title.get_global_rect().has_point(mouse_pos):
mouse_pos_offset = mouse_pos - get_global_rect().position
state = DRAG
elif $ResizeWidget.get_global_rect().has_point(mouse_pos):
mouse_pos_offset = mouse_pos - get_global_rect().end
state = RESIZE
DRAG, RESIZE:
if not event.pressed:
state = NONE
elif event is InputEventMouseMotion:
match state:
DRAG:
var pos = get_global_mouse_position() - mouse_pos_offset
if pos.y < 0:
pos.y = 0
set_position(pos)
get_tree().set_input_as_handled()
RESIZE:
set_size(get_global_mouse_position() - mouse_pos_offset - get_global_rect().position)
get_tree().set_input_as_handled()
func set_title(new_title):
Title = new_title
$Title.text = Title
func _on_PinWidget_toggled(button_pressed):
if button_pressed:
state = PINNED
else:
state = NONE