1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-02-20 12:33:14 +00:00

Make reference images work on the Web version*

* Pxos saved with the Web version will have reference images, since their paths will not be stored.
This commit is contained in:
Emmanouil Papadeas 2022-12-07 15:38:44 +02:00
parent 99ed933d7f
commit f46c376056
3 changed files with 30 additions and 8 deletions

View file

@ -596,7 +596,7 @@ func open_image_as_new_layer(image: Image, file_name: String, frame_index := 0)
project.undo_redo.commit_action()
func import_reference_image_from_path(path: String):
func import_reference_image_from_path(path: String) -> void:
var project: Project = Global.current_project
var ri := ReferenceImage.new()
ri.project = project
@ -605,6 +605,16 @@ func import_reference_image_from_path(path: String):
project.change_project()
# Useful for HTML5
func import_reference_image_from_image(image: Image) -> void:
var project: Project = Global.current_project
var ri := ReferenceImage.new()
ri.project = project
ri.create_from_image(image)
Global.canvas.add_child(ri)
project.change_project()
func set_new_imported_tab(project: Project, path: String) -> void:
var prev_project_empty: bool = Global.current_project.is_empty()
var prev_project_pos: int = Global.current_project_index

View file

@ -13,12 +13,12 @@ func _ready() -> void:
project.reference_images.append(self)
func change_properties():
func change_properties() -> void:
emit_signal("properties_changed")
# Resets the position and scale of the reference image.
func position_reset():
func position_reset() -> void:
position = project.size / 2.0
if texture != null:
scale = (
@ -30,7 +30,7 @@ func position_reset():
# Serialize details of the reference image.
func serialize():
func serialize() -> Dictionary:
return {
"x": position.x,
"y": position.y,
@ -47,16 +47,16 @@ func serialize():
# Load details of the reference image from a dictionary.
# Be aware that new ReferenceImages are created via deserialization.
# This is because deserialization sets up some nice defaults.
func deserialize(d: Dictionary):
func deserialize(d: Dictionary) -> void:
modulate = Color(1, 1, 1, 0.5)
if d.has("image_path"):
# Note that reference images are referred to by path.
# These images may be rather big.
# Also
image_path = d["image_path"]
var img = Image.new()
var img := Image.new()
if img.load(image_path) == OK:
var itex = ImageTexture.new()
var itex := ImageTexture.new()
# don't do FLAG_REPEAT - it could cause visual issues
itex.create_from_image(img, Texture.FLAG_MIPMAPS | Texture.FLAG_FILTER)
texture = itex
@ -79,3 +79,12 @@ func deserialize(d: Dictionary):
if d.has("modulate_a"):
modulate.a = d["modulate_a"]
change_properties()
# Useful for HTML5
func create_from_image(image: Image) -> void:
var itex := ImageTexture.new()
# don't do FLAG_REPEAT - it could cause visual issues
itex.create_from_image(image, Texture.FLAG_MIPMAPS | Texture.FLAG_FILTER)
texture = itex
position_reset()

View file

@ -144,7 +144,10 @@ func _on_PreviewDialog_confirmed() -> void:
OpenSave.open_image_as_new_layer(image, path.get_basename().get_file(), frame_index)
elif current_import_option == ImageImportOptions.NEW_REFERENCE_IMAGE:
OpenSave.import_reference_image_from_path(path)
if OS.get_name() == "HTML5":
OpenSave.import_reference_image_from_image(image)
else:
OpenSave.import_reference_image_from_path(path)
elif current_import_option == ImageImportOptions.PALETTE:
Palettes.import_palette_from_path(path)