mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-02-22 05:23: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:
parent
99ed933d7f
commit
f46c376056
3 changed files with 30 additions and 8 deletions
|
@ -596,7 +596,7 @@ func open_image_as_new_layer(image: Image, file_name: String, frame_index := 0)
|
||||||
project.undo_redo.commit_action()
|
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 project: Project = Global.current_project
|
||||||
var ri := ReferenceImage.new()
|
var ri := ReferenceImage.new()
|
||||||
ri.project = project
|
ri.project = project
|
||||||
|
@ -605,6 +605,16 @@ func import_reference_image_from_path(path: String):
|
||||||
project.change_project()
|
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:
|
func set_new_imported_tab(project: Project, path: String) -> void:
|
||||||
var prev_project_empty: bool = Global.current_project.is_empty()
|
var prev_project_empty: bool = Global.current_project.is_empty()
|
||||||
var prev_project_pos: int = Global.current_project_index
|
var prev_project_pos: int = Global.current_project_index
|
||||||
|
|
|
@ -13,12 +13,12 @@ func _ready() -> void:
|
||||||
project.reference_images.append(self)
|
project.reference_images.append(self)
|
||||||
|
|
||||||
|
|
||||||
func change_properties():
|
func change_properties() -> void:
|
||||||
emit_signal("properties_changed")
|
emit_signal("properties_changed")
|
||||||
|
|
||||||
|
|
||||||
# Resets the position and scale of the reference image.
|
# Resets the position and scale of the reference image.
|
||||||
func position_reset():
|
func position_reset() -> void:
|
||||||
position = project.size / 2.0
|
position = project.size / 2.0
|
||||||
if texture != null:
|
if texture != null:
|
||||||
scale = (
|
scale = (
|
||||||
|
@ -30,7 +30,7 @@ func position_reset():
|
||||||
|
|
||||||
|
|
||||||
# Serialize details of the reference image.
|
# Serialize details of the reference image.
|
||||||
func serialize():
|
func serialize() -> Dictionary:
|
||||||
return {
|
return {
|
||||||
"x": position.x,
|
"x": position.x,
|
||||||
"y": position.y,
|
"y": position.y,
|
||||||
|
@ -47,16 +47,16 @@ func serialize():
|
||||||
# Load details of the reference image from a dictionary.
|
# Load details of the reference image from a dictionary.
|
||||||
# Be aware that new ReferenceImages are created via deserialization.
|
# Be aware that new ReferenceImages are created via deserialization.
|
||||||
# This is because deserialization sets up some nice defaults.
|
# 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)
|
modulate = Color(1, 1, 1, 0.5)
|
||||||
if d.has("image_path"):
|
if d.has("image_path"):
|
||||||
# Note that reference images are referred to by path.
|
# Note that reference images are referred to by path.
|
||||||
# These images may be rather big.
|
# These images may be rather big.
|
||||||
# Also
|
# Also
|
||||||
image_path = d["image_path"]
|
image_path = d["image_path"]
|
||||||
var img = Image.new()
|
var img := Image.new()
|
||||||
if img.load(image_path) == OK:
|
if img.load(image_path) == OK:
|
||||||
var itex = ImageTexture.new()
|
var itex := ImageTexture.new()
|
||||||
# don't do FLAG_REPEAT - it could cause visual issues
|
# don't do FLAG_REPEAT - it could cause visual issues
|
||||||
itex.create_from_image(img, Texture.FLAG_MIPMAPS | Texture.FLAG_FILTER)
|
itex.create_from_image(img, Texture.FLAG_MIPMAPS | Texture.FLAG_FILTER)
|
||||||
texture = itex
|
texture = itex
|
||||||
|
@ -79,3 +79,12 @@ func deserialize(d: Dictionary):
|
||||||
if d.has("modulate_a"):
|
if d.has("modulate_a"):
|
||||||
modulate.a = d["modulate_a"]
|
modulate.a = d["modulate_a"]
|
||||||
change_properties()
|
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()
|
||||||
|
|
|
@ -144,6 +144,9 @@ func _on_PreviewDialog_confirmed() -> void:
|
||||||
OpenSave.open_image_as_new_layer(image, path.get_basename().get_file(), frame_index)
|
OpenSave.open_image_as_new_layer(image, path.get_basename().get_file(), frame_index)
|
||||||
|
|
||||||
elif current_import_option == ImageImportOptions.NEW_REFERENCE_IMAGE:
|
elif current_import_option == ImageImportOptions.NEW_REFERENCE_IMAGE:
|
||||||
|
if OS.get_name() == "HTML5":
|
||||||
|
OpenSave.import_reference_image_from_image(image)
|
||||||
|
else:
|
||||||
OpenSave.import_reference_image_from_path(path)
|
OpenSave.import_reference_image_from_path(path)
|
||||||
|
|
||||||
elif current_import_option == ImageImportOptions.PALETTE:
|
elif current_import_option == ImageImportOptions.PALETTE:
|
||||||
|
|
Loading…
Add table
Reference in a new issue