forked from LGDG/ExampleProject
64 lines
1.8 KiB
GDScript3
64 lines
1.8 KiB
GDScript3
|
extends Button
|
||
|
#var p : DesktopWindow
|
||
|
# add this script to all resize handle buttons, which should be direct
|
||
|
# child of object that is "class_name DesktopWindow"
|
||
|
@onready var parent = $".."
|
||
|
|
||
|
var tracking:bool=false
|
||
|
var start_position:Vector2
|
||
|
var start_size:Vector2
|
||
|
# Called when the node enters the scene tree for the first time.
|
||
|
func _ready():
|
||
|
#var par = get_parent()
|
||
|
if parent is DesktopWindow:
|
||
|
#p = par
|
||
|
button_down.connect(_on_button_down);
|
||
|
button_up.connect(_on_button_up);
|
||
|
else:
|
||
|
print("error we expected to be under desktopwindow instead ",parent)
|
||
|
# setup the handler
|
||
|
#pass
|
||
|
|
||
|
#ISSUE: maximize screen, make window big, unmaximize screen, window now too big
|
||
|
#and resizer box is stuck off the bottom of the screen...
|
||
|
var oldWindowSize:Vector2i
|
||
|
func fixToBigForScreen():
|
||
|
var window := get_window()
|
||
|
if oldWindowSize.x == 0:
|
||
|
oldWindowSize = window.size
|
||
|
return
|
||
|
var scalex:float = float(window.size.x)/float(oldWindowSize.x)
|
||
|
var scaley:float= float(window.size.y)/float(oldWindowSize.y)
|
||
|
if oldWindowSize != window.size:
|
||
|
print(scalex," ",scaley)
|
||
|
parent.size.x = int(float(parent.size.x)*scalex)
|
||
|
parent.size.y = int(float(parent.size.y)*scaley)
|
||
|
oldWindowSize=window.size
|
||
|
|
||
|
func _input(e):
|
||
|
#print (e)
|
||
|
#pass
|
||
|
if e is InputEventMouseMotion and tracking:
|
||
|
var moved:Vector2 = e.position - start_position
|
||
|
#print(moved)
|
||
|
parent.size = start_size + moved
|
||
|
#print(e)
|
||
|
|
||
|
func _on_button_down():
|
||
|
var p = get_parent()
|
||
|
if p is DesktopWindow:
|
||
|
# print(p)
|
||
|
tracking=true
|
||
|
start_position = get_global_mouse_position()
|
||
|
start_size = parent.size
|
||
|
#print(start_position," ",start_size)
|
||
|
|
||
|
#else:
|
||
|
#print("not")
|
||
|
func _on_button_up():
|
||
|
tracking=false
|
||
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||
|
func _process(_delta):
|
||
|
#pass
|
||
|
fixToBigForScreen()
|