mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-03-12 22:35:18 +00:00
Added image size and frame size labels on PreviewDialog
Just to show the image size and the frame size. The latter is only visible if the user chose to import the sprite as a spritesheet.
This commit is contained in:
parent
5ce061d793
commit
8230d9de96
3 changed files with 55 additions and 28 deletions
|
@ -22,6 +22,9 @@ msgstr ""
|
|||
msgid "Canvas Size"
|
||||
msgstr ""
|
||||
|
||||
msgid "Frame Size"
|
||||
msgstr ""
|
||||
|
||||
msgid "Width:"
|
||||
msgstr ""
|
||||
|
||||
|
|
|
@ -10,6 +10,8 @@ var spritesheet_horizontal := 1
|
|||
var spritesheet_vertical := 1
|
||||
|
||||
onready var texture_rect : TextureRect = $VBoxContainer/CenterContainer/TextureRect
|
||||
onready var image_size_label : Label = $VBoxContainer/SizeContainer/ImageSizeLabel
|
||||
onready var frame_size_label : Label = $VBoxContainer/SizeContainer/FrameSizeLabel
|
||||
onready var spritesheet_options = $VBoxContainer/HBoxContainer/SpritesheetOptions
|
||||
onready var new_frame_options = $VBoxContainer/HBoxContainer/NewFrameOptions
|
||||
onready var new_layer_options = $VBoxContainer/HBoxContainer/NewLayerOptions
|
||||
|
@ -21,6 +23,8 @@ func _on_PreviewDialog_about_to_show() -> void:
|
|||
texture_rect.texture = img_texture
|
||||
spritesheet_options.get_node("HorizontalFrames").max_value = min(spritesheet_options.get_node("HorizontalFrames").max_value, image.get_size().x)
|
||||
spritesheet_options.get_node("VerticalFrames").max_value = min(spritesheet_options.get_node("VerticalFrames").max_value, image.get_size().y)
|
||||
image_size_label.text = tr("Image Size") + ": " + str(image.get_size().x) + "×" + str(image.get_size().y)
|
||||
frame_size_label.text = tr("Frame Size") + ": " + str(image.get_size().x) + "×" + str(image.get_size().y)
|
||||
|
||||
|
||||
func _on_PreviewDialog_popup_hide() -> void:
|
||||
|
@ -75,6 +79,7 @@ func _on_PreviewDialog_confirmed() -> void:
|
|||
|
||||
func _on_ImportOption_item_selected(id : int) -> void:
|
||||
current_import_option = id
|
||||
frame_size_label.visible = false
|
||||
spritesheet_options.visible = false
|
||||
new_frame_options.visible = false
|
||||
new_layer_options.visible = false
|
||||
|
@ -82,6 +87,7 @@ func _on_ImportOption_item_selected(id : int) -> void:
|
|||
texture_rect.get_child(1).visible = false
|
||||
|
||||
if id == ImageImportOptions.SPRITESHEET:
|
||||
frame_size_label.visible = true
|
||||
spritesheet_options.visible = true
|
||||
texture_rect.get_child(0).visible = true
|
||||
texture_rect.get_child(1).visible = true
|
||||
|
@ -95,38 +101,23 @@ func _on_ImportOption_item_selected(id : int) -> void:
|
|||
new_layer_options.get_node("AtFrameSpinbox").max_value = Global.current_project.frames.size()
|
||||
|
||||
|
||||
func _on_HorizontalFrames_value_changed(value) -> void:
|
||||
func _on_HorizontalFrames_value_changed(value : int) -> void:
|
||||
spritesheet_horizontal = value
|
||||
for child in texture_rect.get_node("HorizLines").get_children():
|
||||
child.queue_free()
|
||||
|
||||
var image_size_y = texture_rect.rect_size.y
|
||||
var image_size_x = texture_rect.rect_size.x
|
||||
if image.get_size().x > image.get_size().y:
|
||||
var scale_ratio = image.get_size().x / image_size_x
|
||||
image_size_y = image.get_size().y / scale_ratio
|
||||
else:
|
||||
var scale_ratio = image.get_size().y / image_size_y
|
||||
image_size_x = image.get_size().x / scale_ratio
|
||||
|
||||
var offset_x = (300 - image_size_x) / 2
|
||||
var offset_y = (300 - image_size_y) / 2
|
||||
if value > 1:
|
||||
var line_distance = image_size_x / value
|
||||
for i in range(1, value):
|
||||
var line_2d := Line2D.new()
|
||||
line_2d.width = 1
|
||||
line_2d.position = Vector2.ZERO
|
||||
line_2d.add_point(Vector2(i * line_distance + offset_x, offset_y))
|
||||
line_2d.add_point(Vector2(i * line_distance + offset_x, image_size_y + offset_y))
|
||||
texture_rect.get_node("HorizLines").add_child(line_2d)
|
||||
spritesheet_frame_value_changed(value, false)
|
||||
|
||||
|
||||
func _on_VerticalFrames_value_changed(value) -> void:
|
||||
func _on_VerticalFrames_value_changed(value : int) -> void:
|
||||
spritesheet_vertical = value
|
||||
for child in texture_rect.get_node("VerticalLines").get_children():
|
||||
child.queue_free()
|
||||
|
||||
spritesheet_frame_value_changed(value, true)
|
||||
|
||||
|
||||
func spritesheet_frame_value_changed(value : int, vertical : bool) -> void:
|
||||
var image_size_y = texture_rect.rect_size.y
|
||||
var image_size_x = texture_rect.rect_size.x
|
||||
if image.get_size().x > image.get_size().y:
|
||||
|
@ -138,12 +129,27 @@ func _on_VerticalFrames_value_changed(value) -> void:
|
|||
|
||||
var offset_x = (300 - image_size_x) / 2
|
||||
var offset_y = (300 - image_size_y) / 2
|
||||
|
||||
if value > 1:
|
||||
var line_distance = image_size_y / value
|
||||
var line_distance
|
||||
if vertical:
|
||||
line_distance = image_size_y / value
|
||||
else:
|
||||
line_distance = image_size_x / value
|
||||
|
||||
for i in range(1, value):
|
||||
var line_2d := Line2D.new()
|
||||
line_2d.width = 1
|
||||
line_2d.position = Vector2.ZERO
|
||||
line_2d.add_point(Vector2(offset_x, i * line_distance + offset_y))
|
||||
line_2d.add_point(Vector2(image_size_x + offset_x, i * line_distance + offset_y))
|
||||
texture_rect.get_node("VerticalLines").add_child(line_2d)
|
||||
if vertical:
|
||||
line_2d.add_point(Vector2(offset_x, i * line_distance + offset_y))
|
||||
line_2d.add_point(Vector2(image_size_x + offset_x, i * line_distance + offset_y))
|
||||
texture_rect.get_node("VerticalLines").add_child(line_2d)
|
||||
else:
|
||||
line_2d.add_point(Vector2(i * line_distance + offset_x, offset_y))
|
||||
line_2d.add_point(Vector2(i * line_distance + offset_x, image_size_y + offset_y))
|
||||
texture_rect.get_node("HorizLines").add_child(line_2d)
|
||||
|
||||
var frame_width = floor(image.get_size().x / spritesheet_horizontal)
|
||||
var frame_height = floor(image.get_size().y / spritesheet_vertical)
|
||||
frame_size_label.text = tr("Frame Size") + ": " + str(frame_width) + "×" + str(frame_height)
|
||||
|
|
|
@ -47,10 +47,28 @@ __meta__ = {
|
|||
|
||||
[node name="VerticalLines" type="Control" parent="VBoxContainer/CenterContainer/TextureRect"]
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
|
||||
[node name="SizeContainer" type="HBoxContainer" parent="VBoxContainer"]
|
||||
margin_top = 304.0
|
||||
margin_right = 534.0
|
||||
margin_bottom = 324.0
|
||||
margin_bottom = 318.0
|
||||
custom_constants/separation = 32
|
||||
|
||||
[node name="ImageSizeLabel" type="Label" parent="VBoxContainer/SizeContainer"]
|
||||
margin_right = 117.0
|
||||
margin_bottom = 14.0
|
||||
text = "Image Size: 64×64"
|
||||
|
||||
[node name="FrameSizeLabel" type="Label" parent="VBoxContainer/SizeContainer"]
|
||||
visible = false
|
||||
margin_left = 149.0
|
||||
margin_right = 266.0
|
||||
margin_bottom = 14.0
|
||||
text = "Frame size: 64×64"
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
|
||||
margin_top = 322.0
|
||||
margin_right = 534.0
|
||||
margin_bottom = 342.0
|
||||
|
||||
[node name="Label" type="Label" parent="VBoxContainer/HBoxContainer"]
|
||||
margin_top = 3.0
|
||||
|
|
Loading…
Add table
Reference in a new issue