mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-18 09:09:47 +00:00
Added a preview to the Resize Canvas dialog
This commit is contained in:
parent
9362b3486b
commit
89b6e3a989
|
@ -37,7 +37,7 @@ Darshan Phaldesai (luiq54), Igor Santarek (jegor377), rob-a-bolton, Kinwailo
|
|||
- Fixed a rare issue with Undo/Redo not working while motion-drawing and making lines.
|
||||
- Grid and guides are now longer being displayed on previews. ([#205](https://github.com/Orama-Interactive/Pixelorama/issues/205))
|
||||
- Fixed a rare problem where the custom mouse cursor's image was failing to load.
|
||||
- Importing a non-palette json file no longer crashes the app.
|
||||
- Importing corrupted image files and non-palette json files no longer crash the app.
|
||||
<br><br>
|
||||
|
||||
## [v0.7] - 2020-05-16
|
||||
|
|
|
@ -5,9 +5,35 @@ var width := 64
|
|||
var height := 64
|
||||
var offset_x := 0
|
||||
var offset_y := 0
|
||||
var image : Image
|
||||
|
||||
onready var x_spinbox : SpinBox = $VBoxContainer/OptionsContainer/XSpinBox
|
||||
onready var y_spinbox : SpinBox = $VBoxContainer/OptionsContainer/YSpinBox
|
||||
onready var preview_rect : TextureRect = $VBoxContainer/Preview
|
||||
|
||||
|
||||
func _on_ResizeCanvas_about_to_show() -> void:
|
||||
image = Image.new()
|
||||
image.create(Global.current_project.size.x, Global.current_project.size.y, false, Image.FORMAT_RGBA8)
|
||||
image.lock()
|
||||
var layer_i := 0
|
||||
for cel in Global.current_project.frames[Global.current_project.current_frame].cels:
|
||||
if Global.current_project.layers[layer_i].visible:
|
||||
var cel_image := Image.new()
|
||||
cel_image.copy_from(cel.image)
|
||||
cel_image.lock()
|
||||
if cel.opacity < 1: # If we have cel transparency
|
||||
for xx in cel_image.get_size().x:
|
||||
for yy in cel_image.get_size().y:
|
||||
var pixel_color := cel_image.get_pixel(xx, yy)
|
||||
var alpha : float = pixel_color.a * cel.opacity
|
||||
cel_image.set_pixel(xx, yy, Color(pixel_color.r, pixel_color.g, pixel_color.b, alpha))
|
||||
image.blend_rect(cel_image, Rect2(Global.canvas.location, Global.current_project.size), Vector2.ZERO)
|
||||
layer_i += 1
|
||||
image.unlock()
|
||||
|
||||
update_preview()
|
||||
preview_rect.get_node("TransparentChecker").rect_size = preview_rect.rect_size
|
||||
|
||||
|
||||
func _on_ResizeCanvas_confirmed() -> void:
|
||||
|
@ -19,6 +45,7 @@ func _on_WidthValue_value_changed(value : int) -> void:
|
|||
x_spinbox.min_value = min(width - Global.current_project.size.x, 0)
|
||||
x_spinbox.max_value = max(width - Global.current_project.size.x, 0)
|
||||
x_spinbox.value = clamp(x_spinbox.value, x_spinbox.min_value, x_spinbox.max_value)
|
||||
update_preview()
|
||||
|
||||
|
||||
func _on_HeightValue_value_changed(value : int) -> void:
|
||||
|
@ -26,16 +53,28 @@ func _on_HeightValue_value_changed(value : int) -> void:
|
|||
y_spinbox.min_value = min(height - Global.current_project.size.y, 0)
|
||||
y_spinbox.max_value = max(height - Global.current_project.size.y, 0)
|
||||
y_spinbox.value = clamp(y_spinbox.value, y_spinbox.min_value, y_spinbox.max_value)
|
||||
update_preview()
|
||||
|
||||
|
||||
func _on_XSpinBox_value_changed(value : int) -> void:
|
||||
offset_x = value
|
||||
update_preview()
|
||||
|
||||
|
||||
func _on_YSpinBox_value_changed(value : int) -> void:
|
||||
offset_y = value
|
||||
update_preview()
|
||||
|
||||
|
||||
func _on_CenterButton_pressed() -> void:
|
||||
x_spinbox.value = (x_spinbox.min_value + x_spinbox.max_value) / 2
|
||||
y_spinbox.value = (y_spinbox.min_value + y_spinbox.max_value) / 2
|
||||
|
||||
|
||||
func update_preview() -> void:
|
||||
var preview_image := Image.new()
|
||||
preview_image.create(width, height, false, Image.FORMAT_RGBA8)
|
||||
preview_image.blend_rect(image, Rect2(Vector2.ZERO, Global.current_project.size), Vector2(offset_x, offset_y))
|
||||
var preview_texture := ImageTexture.new()
|
||||
preview_texture.create_from_image(preview_image, 0)
|
||||
preview_rect.texture = preview_texture
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
[gd_scene load_steps=2 format=2]
|
||||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://src/UI/Dialogs/ResizeCanvas.gd" type="Script" id=1]
|
||||
[ext_resource path="res://src/UI/TransparentChecker.tscn" type="PackedScene" id=2]
|
||||
|
||||
[node name="ResizeCanvas" type="ConfirmationDialog"]
|
||||
margin_right = 200.0
|
||||
|
@ -10,20 +11,20 @@ script = ExtResource( 1 )
|
|||
[node name="VBoxContainer" type="VBoxContainer" parent="."]
|
||||
margin_left = 8.0
|
||||
margin_top = 8.0
|
||||
margin_right = 192.0
|
||||
margin_bottom = 176.0
|
||||
margin_right = 208.0
|
||||
margin_bottom = 380.0
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="ImageSize" type="Label" parent="VBoxContainer"]
|
||||
margin_right = 184.0
|
||||
margin_right = 200.0
|
||||
margin_bottom = 14.0
|
||||
text = "Canvas Size"
|
||||
|
||||
[node name="OptionsContainer" type="GridContainer" parent="VBoxContainer"]
|
||||
margin_top = 18.0
|
||||
margin_right = 184.0
|
||||
margin_right = 200.0
|
||||
margin_bottom = 168.0
|
||||
custom_constants/vseparation = 4
|
||||
custom_constants/hseparation = 2
|
||||
|
@ -109,6 +110,18 @@ margin_top = 130.0
|
|||
margin_right = 54.0
|
||||
margin_bottom = 150.0
|
||||
text = "Center"
|
||||
|
||||
[node name="Preview" type="TextureRect" parent="VBoxContainer"]
|
||||
margin_top = 172.0
|
||||
margin_right = 200.0
|
||||
margin_bottom = 372.0
|
||||
rect_min_size = Vector2( 200, 200 )
|
||||
expand = true
|
||||
stretch_mode = 6
|
||||
|
||||
[node name="TransparentChecker" parent="VBoxContainer/Preview" instance=ExtResource( 2 )]
|
||||
show_behind_parent = true
|
||||
[connection signal="about_to_show" from="." to="." method="_on_ResizeCanvas_about_to_show"]
|
||||
[connection signal="confirmed" from="." to="." method="_on_ResizeCanvas_confirmed"]
|
||||
[connection signal="value_changed" from="VBoxContainer/OptionsContainer/WidthValue" to="." method="_on_WidthValue_value_changed"]
|
||||
[connection signal="value_changed" from="VBoxContainer/OptionsContainer/HeightValue" to="." method="_on_HeightValue_value_changed"]
|
||||
|
|
Loading…
Reference in a new issue