1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-02-23 14:03:13 +00:00
Pixelorama/src/UI/ReferenceImages/ReferenceImage.gd
TheLsbt c8f37943d8
Reference Image Improvements (#961)
* Reference Image Updates

* Fixed static typing

Fixed static typing in "src\UI
\ReferenceImages\ReferenceEditPanel.gd"
Changed "ri == null" to "!ri" in "src\UI\Canvas\ReferenceImages.gd"

* Tried fixing the static typing again

Removed lambda functions for the confirmation dialog.
Removed irrelevant print statement.

* Tried fixing static typing again

I think its fixed now

* Changed Spacing

* Fixed Trailing Whitespaces and tabs

* Fixed Final Trailing Whitespace

* Fixed styling and removed useless enum

* Removed double tabs left over from previous commit

* Fixed remove ConfirmDialog Showing on startusp

* Tried Fixing gdlint issues

* Fixed Linting

* Fixed Spelling issues

* Drag and drop to rearrange reference images

Added the ability to drag and drop Reference Images similar to dragging and dropping layers. These can be dragged or used with buttons (similar to the buttons that move frames). With full undo/redo support.

Added tool buttons these should help people who draw on tablets that cannot use keyboard shortcuts (icons still need to be created)

Renamed ReferenceEditPanel.gd to ReferenceEdit.gd (because it is no longer the script of a panel) and changed the base class of the Reference Panel.

Added some more translations.

Remade ReferenceImageButton.tscn to allow for drag and drop

Added drag highlight

* Added Icons

Added icons for the tools of the Reference Images

* Applied the icons to the UI

* Fix Scripting Issues

* Fixed Linting

* Rename Move.png to move.png

* Update Canvas.gd

* Updated the tooltips

Also added the correct translations

* Rename Select.png to select.png

* Rename Select.png.import to select.png.import

* Rename Move.png.import to move.png.import

* Rename Rotate.png to rotate.png

* Rename Rotate.png.import to rotate.png.import

* Fixed import files

* Rename Scale.png to scale.png

* Rename Scale.png.import to scale.png.import

* Added logic to update the reference panel when the project changes

Also fixed visual bugs related to highlighting the current reference image.

Made it so the reference image that was selected in a project get selected again when the project opens instead of going back to -1 (nothing)

* Update Project.gd
2023-12-31 14:12:37 +02:00

133 lines
3.4 KiB
GDScript

class_name ReferenceImage
extends Sprite2D
## A class describing a reference image
signal properties_changed
var project := Global.current_project
var shader := preload("res://src/Shaders/ReferenceImageShader.gdshader")
var image_path := ""
var filter := false:
set(value):
filter = value
if value:
texture_filter = CanvasItem.TEXTURE_FILTER_LINEAR
else:
texture_filter = CanvasItem.TEXTURE_FILTER_NEAREST
var monochrome := false:
set(value):
monochrome = value
if material:
get_material().set_shader_parameter("monochrome", value)
var overlay_color := Color.WHITE:
set(value):
overlay_color = value
modulate = value
if material:
get_material().set_shader_parameter("monchrome_color", value)
var color_clamping := 0.0:
set(value):
color_clamping = value
if material:
get_material().set_shader_parameter("clamping", value)
func _ready() -> void:
project.reference_images.append(self)
# Make this show behind parent because we want to use _draw() to draw over it
show_behind_parent = true
func change_properties() -> void:
properties_changed.emit()
## Resets the position and scale of the reference image.
func position_reset() -> void:
position = project.size / 2.0
rotation_degrees = 0.0
if texture != null:
scale = (
Vector2.ONE
* minf(
float(project.size.x) / texture.get_width(),
float(project.size.y) / texture.get_height()
)
)
else:
scale = Vector2.ONE
## Serialize details of the reference image.
func serialize() -> Dictionary:
return {
"x": position.x,
"y": position.y,
"scale_x": scale.x,
"scale_y": scale.y,
"rotation_degrees": rotation_degrees,
"overlay_color_r": overlay_color.r,
"overlay_color_g": overlay_color.g,
"overlay_color_b": overlay_color.b,
"overlay_color_a": overlay_color.a,
"filter": filter,
"monochrome": monochrome,
"color_clamping": color_clamping,
"image_path": image_path
}
## 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) -> void:
overlay_color = 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.
image_path = d["image_path"]
var img := Image.new()
if img.load(image_path) == OK:
var itex := ImageTexture.create_from_image(img)
texture = itex
# Apply the silhouette shader
var mat := ShaderMaterial.new()
mat.shader = shader
set_material(mat)
# Now that the image may have been established...
position_reset()
if d.has("x"):
position.x = d["x"]
if d.has("y"):
position.y = d["y"]
if d.has("scale_x"):
scale.x = d["scale_x"]
if d.has("rotation_degrees"):
rotation_degrees = d["rotation_degrees"]
if d.has("scale_y"):
scale.y = d["scale_y"]
if d.has("overlay_color_r"):
overlay_color.r = d["overlay_color_r"]
if d.has("overlay_color_g"):
overlay_color.g = d["overlay_color_g"]
if d.has("overlay_color_b"):
overlay_color.b = d["overlay_color_b"]
if d.has("overlay_color_a"):
overlay_color.a = d["overlay_color_a"]
if d.has("filter"):
filter = d["filter"]
if d.has("monochrome"):
monochrome = d["monochrome"]
if d.has("color_clamping"):
color_clamping = d["color_clamping"]
change_properties()
## Useful for Web
func create_from_image(image: Image) -> void:
var itex := ImageTexture.create_from_image(image)
texture = itex
position_reset()