2023-11-23 23:02:18 +00:00
|
|
|
tool
|
|
|
|
extends Sprite
|
|
|
|
class_name TK_FittingSprite
|
|
|
|
|
|
|
|
## A Sprite that is resized to absolute pixel size, no matter the texture.
|
|
|
|
|
2023-11-25 13:27:41 +00:00
|
|
|
const NO_SIZE_SENTINEL = Vector2(-1, -1)
|
|
|
|
|
|
|
|
export var target_size: Vector2 = NO_SIZE_SENTINEL setget _set_target_size
|
|
|
|
|
|
|
|
# todo: Ask context about preferred sizing if there's any.
|
|
|
|
func _enter_tree() -> void:
|
|
|
|
if target_size == NO_SIZE_SENTINEL:
|
|
|
|
self.target_size = texture.get_size()
|
2023-11-23 23:02:18 +00:00
|
|
|
|
|
|
|
func _set_target_size(p_size: Vector2) -> void:
|
|
|
|
target_size = p_size
|
|
|
|
_update_scale()
|
|
|
|
|
|
|
|
func _update_scale() -> void:
|
|
|
|
scale = target_size / texture.get_size()
|