11extends Panel
22
33
4- # var global :Node #Needed for reference to "Global" node of Pixelorama (Used most of the time)
4+ var global :Node # Needed for reference to "Global" node of Pixelorama (Used most of the time)
5+
6+ func _ready () -> void :
7+ set_global_position (OS .window_size / 2.0 - rect_size / 2.0 )
8+
59
610# This script acts as a setup for the extension
711# func _enter_tree() -> void:
8- # global = get_node ("/root/Global")
12+ # global = get_node_or_null ("/root/Global")
913# if global:
1014# pass
1115
@@ -15,15 +19,21 @@ extends Panel
1519# pass
1620
1721
18- # An example extension below (Remove it and make your own)
22+ ## ## Template Code for custom Dialog movement and Scale
1923var moving = false
24+ var scaling = false
25+ var can_scale = false
26+ var mode = 0
27+ var scale_left = false
28+ var scale_right = false
29+ var scale_up = false
30+ var scale_down = false
31+ enum Mode { NONE , LEFT , RIGHT , UP , DOWN , T_LEFT , T_RIGHT , B_LEFT , B_RIGHT }
32+ var scale_limit = 5
2033var offset = Vector2 .ZERO
2134
22- func _ready () -> void :
23- set_global_position (OS .window_size / 2.0 - rect_size / 2.0 )
2435
25-
26- func _on_Main_gui_input (event : InputEvent ) -> void :
36+ func _on_Title_gui_input (event : InputEvent ) -> void :
2737 if event is InputEventMouseButton :
2838 if event .pressed :
2939 moving = true
@@ -34,3 +44,74 @@ func _on_Main_gui_input(event: InputEvent) -> void:
3444 if event is InputEventMouseMotion :
3545 if moving :
3646 set_global_position (get_global_mouse_position () - offset )
47+
48+
49+ func _on_Main_mouse_entered () -> void :
50+ can_scale = true
51+
52+
53+ func _on_Main_mouse_exited () -> void :
54+ if ! scaling :
55+ can_scale = false
56+
57+
58+ func _input (event : InputEvent ) -> void :
59+ if event is InputEventMouse : # Set cursor and mode accordingly
60+ var mouse_pos = get_local_mouse_position ()
61+ if event is InputEventMouseMotion and ! scaling :
62+ # Decide Scale direction
63+ scale_left = false
64+ scale_right = false
65+ scale_up = false
66+ scale_down = false
67+ if ((mouse_pos .x < scale_limit and mouse_pos .x > - scale_limit )
68+ and (mouse_pos .y > 0 and mouse_pos .y < rect_size .y )): # Left
69+ scale_left = true
70+ elif (mouse_pos .x >= rect_size .x - scale_limit and mouse_pos .x <= rect_size .x + scale_limit
71+ and (mouse_pos .y > 0 and mouse_pos .y < rect_size .y )): # Right
72+ scale_right = true
73+ if ((mouse_pos .y < scale_limit and mouse_pos .y > - scale_limit )
74+ and (mouse_pos .x > 0 and mouse_pos .x < rect_size .x )): # Up
75+ scale_up = true
76+ elif (mouse_pos .y >= rect_size .y - scale_limit and mouse_pos .y <= rect_size .y + scale_limit
77+ and (mouse_pos .x > 0 and mouse_pos .x < rect_size .x )): # Down
78+ scale_down = true
79+
80+ # Decide Cursors
81+ if (scale_up and scale_left ) or (scale_down and scale_right ):
82+ mouse_default_cursor_shape = Control .CURSOR_FDIAGSIZE
83+ elif (scale_up and scale_right ) or (scale_down and scale_left ):
84+ mouse_default_cursor_shape = Control .CURSOR_BDIAGSIZE
85+ elif (scale_up or scale_down ):
86+ mouse_default_cursor_shape = Control .CURSOR_VSIZE
87+ elif (scale_left or scale_right ):
88+ mouse_default_cursor_shape = Control .CURSOR_HSIZE
89+ else :
90+ mouse_default_cursor_shape = Control .CURSOR_ARROW
91+
92+ elif event is InputEventMouseMotion and scaling : # Here's where the scaling is done
93+ if can_scale :
94+ # SIDES
95+ if scale_right :
96+ rect_size .x += get_global_mouse_position ().x - rect_global_position .x - (rect_size .x )
97+ elif scale_left :
98+ if rect_size .x + (rect_global_position .x - get_global_mouse_position ().x ) > rect_min_size .x :
99+ rect_size .x += rect_global_position .x - get_global_mouse_position ().x
100+ rect_position .x -= (rect_global_position .x ) - get_global_mouse_position ().x
101+ if scale_down :
102+ rect_size .y += get_global_mouse_position ().y - rect_global_position .y - (rect_size .y )
103+ elif scale_up :
104+ if rect_size .y + (rect_global_position .y - get_global_mouse_position ().y ) > rect_min_size .y :
105+ rect_size .y += rect_global_position .y - get_global_mouse_position ().y
106+ rect_position .y -= (rect_global_position .y ) - get_global_mouse_position ().y
107+
108+ if event is InputEventMouseButton :
109+ if event .pressed :
110+ scaling = true
111+ else :
112+ scaling = false
113+ can_scale = false
114+ scale_left = false
115+ scale_right = false
116+ scale_up = false
117+ scale_down = false
0 commit comments