First commit

This commit is contained in:
Davide Di Staso committed 2025-10-05 18:13:56 +02:00
1 parent 3016a8f489
commit cc9e7b1c40
44 files changed
+1413 -2

No files matched your search

@@ -0,0 +1,99 @@
@tool
extends HBoxContainer
signal resolution_edited
@export var preset_option_button: OptionButton
var presets : Dictionary[String, Vector2i] = {
"iPhone 6.9\" (portrait)" : Vector2i(1320, 2868),
"iPhone 6.9\" (landscape)" : Vector2i(2868, 1320),
"iPad 13\" (portrait)" : Vector2i(2064, 2752),
"iPad 13\" (landscape)" : Vector2i(2752, 2064)
}
func _ready() -> void:
var i = 0
preset_option_button.clear()
for preset in presets:
preset_option_button.add_item(preset)
preset_option_button.set_item_metadata(i, presets[preset])
i+=1
preset_option_button.add_item("Custom")
preset_option_button.item_selected.connect(_on_preset_selected)
if preset_option_button.selected == -1:
preset_option_button.select(0)
_on_preset_selected(0)
%XLineEdit.text_changed.connect(_on_resolution_edited.bind("x"))
%YLineEdit.text_changed.connect(_on_resolution_edited.bind("y"))
%AddButton.pressed.connect(_on_add_button_pressed)
%AddButton.icon = get_theme_icon("Add", "EditorIcons")
%XLabel.add_theme_color_override("font_color", get_theme_color("property_color_x", "Editor"))
%YLabel.add_theme_color_override("font_color", get_theme_color("property_color_y", "Editor"))
%PixelsLabel.add_theme_color_override("font_color", get_theme_color("disabled_font_color", "Editor"))
%PixelsLabel2.add_theme_color_override("font_color", get_theme_color("disabled_font_color", "Editor"))
%TrashButton.pressed.connect(_on_trash_button_pressed)
%TrashButton.icon = get_theme_icon("Remove", "EditorIcons")
func _on_trash_button_pressed() -> void:
queue_free()
func set_trash_button_disabled(p_disabled : bool) -> void:
%TrashButton.disabled = p_disabled
func set_add_button_visibility(p_visible: bool) -> void:
%AddButton.visible = p_visible
func _on_add_button_pressed() -> void:
var size_panel = load("res://addons/screenshots/debugger/bottom_panel/size/size.tscn")
get_parent().add_child(size_panel.instantiate())
$AddButton.hide()
func _on_preset_selected(idx: int) -> void:
var resolution : Vector2i = preset_option_button.get_item_metadata(idx)
if not resolution:
return
%XLineEdit.text = str(resolution.x)
%YLineEdit.text = str(resolution.y)
resolution_edited.emit()
func set_resolution(p_resolution: Vector2i) -> void:
%XLineEdit.text = str(p_resolution.x)
%YLineEdit.text = str(p_resolution.y)
select_preset_option(p_resolution)
func select_preset_option(resolution: Vector2i) -> void:
if not is_node_ready():
await ready
var idx = preset_option_button.item_count - 1
for i in range(0, preset_option_button.item_count):
var button_res = preset_option_button.get_item_metadata(i)
if button_res == resolution:
idx = i
preset_option_button.select(idx)
func get_resolution() -> Vector2i:
var res : Vector2i
res.x = int(%XLineEdit.text)
res.y = int(%YLineEdit.text)
return res
func _on_resolution_edited(new_text: String, axis: String) -> void:
# Remove all non-digit characters
var filtered := ""
for c in new_text:
if c.is_valid_int():
filtered += c
# Update the correct line edit only if text was modified
if axis == "x":
if %XLineEdit.text != filtered:
%XLineEdit.text = filtered
elif axis == "y":
if %YLineEdit.text != filtered:
%YLineEdit.text = filtered
select_preset_option(get_resolution())
resolution_edited.emit()
@@ -0,0 +1 @@
uid://dgo7yugttb2sl
@@ -0,0 +1,94 @@
[gd_scene load_steps=3 format=3 uid="uid://dbrgvcn8hvchs"]
[ext_resource type="Script" uid="uid://dgo7yugttb2sl" path="res://addons/screenshots/debugger/bottom_panel/size/size.gd" id="1_7ypgp"]
[sub_resource type="DPITexture" id="DPITexture_v8sxj"]
_source = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"16\" height=\"16\"><path fill=\"#ff5d5d\" d=\"M2 1v8.586l1.293-1.293a1 1 0 0 1 1.414 0L7 10.587l2.293-2.293a1 1 0 0 1 1.414 0L13 10.586l1-1V6H9V1H2zm8 0v4h4zm-6 9.414-2 2V15h12v-2.586l-.293.293a1 1 0 0 1-1.414 0L10 10.414l-2.293 2.293a1 1 0 0 1-1.414 0L4 10.414z\"/></svg>
"
[node name="Size" type="HBoxContainer" node_paths=PackedStringArray("preset_option_button")]
script = ExtResource("1_7ypgp")
preset_option_button = NodePath("VBoxContainer2/HBoxContainer/OptionButton")
[node name="VBoxContainer2" type="VBoxContainer" parent="."]
layout_mode = 2
[node name="VBoxContainer" type="VBoxContainer" parent="VBoxContainer2"]
layout_mode = 2
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer2/VBoxContainer"]
layout_mode = 2
[node name="XLabel" type="Label" parent="VBoxContainer2/VBoxContainer/HBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
theme_override_colors/font_color = Color(0, 0, 0, 1)
text = "x"
[node name="XLineEdit" type="LineEdit" parent="VBoxContainer2/VBoxContainer/HBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
text = "1320"
virtual_keyboard_type = 2
[node name="PixelsLabel" type="Label" parent="VBoxContainer2/VBoxContainer/HBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
theme_override_colors/font_color = Color(0, 0, 0, 1)
text = "px"
[node name="HBoxContainer2" type="HBoxContainer" parent="VBoxContainer2/VBoxContainer"]
layout_mode = 2
[node name="YLabel" type="Label" parent="VBoxContainer2/VBoxContainer/HBoxContainer2"]
unique_name_in_owner = true
layout_mode = 2
theme_override_colors/font_color = Color(0, 0, 0, 1)
text = "y"
[node name="YLineEdit" type="LineEdit" parent="VBoxContainer2/VBoxContainer/HBoxContainer2"]
unique_name_in_owner = true
layout_mode = 2
text = "2868"
virtual_keyboard_type = 2
[node name="PixelsLabel2" type="Label" parent="VBoxContainer2/VBoxContainer/HBoxContainer2"]
unique_name_in_owner = true
layout_mode = 2
theme_override_colors/font_color = Color(0, 0, 0, 1)
text = "px"
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer2"]
layout_mode = 2
[node name="OptionButton" type="OptionButton" parent="VBoxContainer2/HBoxContainer"]
custom_minimum_size = Vector2(300, 0)
layout_mode = 2
flat = true
text_overrun_behavior = 3
selected = 0
fit_to_longest_item = false
item_count = 5
popup/item_0/text = "iPhone 6.9\" (portrait)"
popup/item_0/id = 0
popup/item_1/text = "iPhone 6.9\" (landscape)"
popup/item_1/id = 1
popup/item_2/text = "iPad 13\" (portrait)"
popup/item_2/id = 2
popup/item_3/text = "iPad 13\" (landscape)"
popup/item_3/id = 3
popup/item_4/text = "Custom"
popup/item_4/id = 4
[node name="TrashButton" type="Button" parent="VBoxContainer2/HBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
disabled = true
icon = SubResource("DPITexture_v8sxj")
flat = true
[node name="AddButton" type="Button" parent="."]
unique_name_in_owner = true
visible = false
layout_mode = 2
icon = SubResource("DPITexture_v8sxj")