Skip to content

Commit ef6bc3a

Browse files
authored
Added Custom Dialog Scaling
1 parent 665fc67 commit ef6bc3a

2 files changed

Lines changed: 113 additions & 28 deletions

File tree

Lines changed: 88 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
extends 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
1923
var 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
2033
var 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

Code/Example/src/Extensions/Example/Main.tscn

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,38 @@
33
[ext_resource path="res://src/Extensions/Example/Main.gd" type="Script" id=1]
44

55
[node name="Main" type="Panel"]
6-
margin_right = 378.0
7-
margin_bottom = 256.0
8-
rect_min_size = Vector2( 378, 256 )
6+
margin_right = 423.0
7+
margin_bottom = 357.0
8+
rect_min_size = Vector2( 150, 150 )
99
script = ExtResource( 1 )
10-
__meta__ = {
11-
"_edit_use_anchors_": false
12-
}
1310

1411
[node name="VBoxContainer" type="VBoxContainer" parent="."]
1512
anchor_right = 1.0
1613
anchor_bottom = 1.0
17-
margin_left = 6.0
18-
margin_right = -6.0
19-
rect_min_size = Vector2( 366, 256 )
20-
__meta__ = {
21-
"_edit_use_anchors_": false
22-
}
14+
margin_left = 12.0
15+
margin_top = 12.0
16+
margin_right = -12.0
17+
margin_bottom = -12.0
18+
19+
[node name="ColorRect" type="ColorRect" parent="VBoxContainer"]
20+
margin_right = 399.0
21+
margin_bottom = 40.0
22+
rect_min_size = Vector2( 0, 40 )
23+
color = Color( 0.0941176, 0.0941176, 0.0941176, 1 )
2324

24-
[node name="Title" type="Label" parent="VBoxContainer"]
25-
margin_right = 366.0
26-
margin_bottom = 14.0
25+
[node name="Title" type="Label" parent="VBoxContainer/ColorRect"]
26+
anchor_right = 1.0
27+
anchor_bottom = 1.0
28+
rect_min_size = Vector2( 0, 40 )
29+
mouse_filter = 0
2730
text = "Instructions"
2831
align = 1
2932
valign = 1
3033

31-
[node name="Instructions" type="RichTextLabel" parent="VBoxContainer"]
32-
margin_top = 18.0
33-
margin_right = 366.0
34-
margin_bottom = 256.0
34+
[node name="Content" type="RichTextLabel" parent="VBoxContainer"]
35+
margin_top = 44.0
36+
margin_right = 399.0
37+
margin_bottom = 333.0
3538
focus_mode = 2
3639
size_flags_vertical = 3
3740
text = "This is a simple example of how you can make an extension for pixelorama.
@@ -66,5 +69,6 @@ __meta__ = {
6669
"_edit_use_anchors_": false
6770
}
6871

69-
[connection signal="gui_input" from="." to="." method="_on_Main_gui_input"]
70-
[connection signal="gui_input" from="VBoxContainer/Title" to="." method="_on_Title_gui_input"]
72+
[connection signal="mouse_entered" from="." to="." method="_on_Main_mouse_entered"]
73+
[connection signal="mouse_exited" from="." to="." method="_on_Main_mouse_exited"]
74+
[connection signal="gui_input" from="VBoxContainer/ColorRect/Title" to="." method="_on_Title_gui_input"]

0 commit comments

Comments
 (0)