1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-18 17:19:50 +00:00

Add get_position() and get_minimum_size() methods to AnimationTag

This commit is contained in:
OverloadedOrama 2024-02-07 03:17:39 +02:00
parent a5a0ac103c
commit e11ecb2e8d
3 changed files with 23 additions and 21 deletions

View file

@ -43,6 +43,8 @@ extends RefCounted
## Global.current_project.undo_redo.commit_action()
## [/codeblock]
const CEL_SEPARATION := 4
var name: String ## Name of tag
var color: Color ## Color of tag
var from: int ## First frame number in the tag (first frame in timeline is numbered 1)
@ -55,3 +57,14 @@ func _init(_name, _color, _from, _to) -> void:
color = _color
from = _from
to = _to
func get_position() -> Vector2:
var tag_base_size: int = Global.animation_timeline.cel_size + CEL_SEPARATION
return Vector2((from - 1) * tag_base_size + 1, 1)
func get_minimum_size() -> int:
var tag_base_size: int = Global.animation_timeline.cel_size + CEL_SEPARATION
var tag_size := to - from
return (tag_size + 1) * tag_base_size - 8

View file

@ -556,7 +556,6 @@ func _animation_tags_changed(value: Array[AnimationTag]) -> void:
child.queue_free()
for tag in animation_tags:
var tag_base_size = Global.animation_timeline.cel_size + 4
var tag_c: Container = animation_tag_node.instantiate()
Global.tag_container.add_child(tag_c)
tag_c.tag = tag
@ -565,13 +564,8 @@ func _animation_tags_changed(value: Array[AnimationTag]) -> void:
tag_c.get_node("Label").text = tag.name
tag_c.get_node("Label").modulate = tag.color
tag_c.get_node("Line2D").default_color = tag.color
# Added 1 to answer to get starting position of next cel
tag_c.position.x = (tag.from - 1) * tag_base_size + 1
var tag_size := tag.to - tag.from
# We dont need the 4 pixels at the end of last cel
tag_c.custom_minimum_size.x = (tag_size + 1) * tag_base_size - 8
tag_c.position.y = 1 # To make top line of tag visible
tag_c.position = tag.get_position()
tag_c.custom_minimum_size.x = tag.get_minimum_size()
tag_c.get_node("Line2D").points[2] = Vector2(tag_c.custom_minimum_size.x, 0)
tag_c.get_node("Line2D").points[3] = Vector2(tag_c.custom_minimum_size.x, 32)

View file

@ -173,30 +173,25 @@ func _cel_size_changed(value: int) -> void:
cel_size = clampi(value, min_cel_size, max_cel_size)
update_minimum_size()
Global.config_cache.set_value("timeline", "cel_size", cel_size)
for layer_button in Global.layer_vbox.get_children():
for layer_button: Control in Global.layer_vbox.get_children():
layer_button.custom_minimum_size.y = cel_size
layer_button.size.y = cel_size
for cel_hbox in Global.cel_vbox.get_children():
for cel_button in cel_hbox.get_children():
for cel_hbox: Control in Global.cel_vbox.get_children():
for cel_button: Control in cel_hbox.get_children():
cel_button.custom_minimum_size.x = cel_size
cel_button.custom_minimum_size.y = cel_size
cel_button.size.x = cel_size
cel_button.size.y = cel_size
for frame_id in Global.frame_hbox.get_children():
for frame_id: Control in Global.frame_hbox.get_children():
frame_id.custom_minimum_size.x = cel_size
frame_id.size.x = cel_size
for tag_c in Global.tag_container.get_children():
var tag_base_size := cel_size + 4
for tag_c: Control in Global.tag_container.get_children():
var tag: AnimationTag = tag_c.tag
# Added 1 to answer to get starting position of next cel
tag_c.position.x = (tag.from - 1) * tag_base_size + 1
var tag_size := tag.to - tag.from
# We dont need the 4 pixels at the end of last cel
tag_c.custom_minimum_size.x = (tag_size + 1) * tag_base_size - 4
# We dont need the 4 pixels at the end of last cel
tag_c.size.x = (tag_size + 1) * tag_base_size - 4
tag_c.position = tag.get_position()
tag_c.custom_minimum_size.x = tag.get_minimum_size()
tag_c.size.x = tag_c.custom_minimum_size.x
tag_c.get_node("Line2D").points[2] = Vector2(tag_c.custom_minimum_size.x, 0)
tag_c.get_node("Line2D").points[3] = Vector2(tag_c.custom_minimum_size.x, 32)