1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-18 17:19:50 +00:00

Implemented text clipboard system instead of the old one (#693)

* add limit change with brush

* Delete Draw.gd

* Delete BaseTool.gd

* added error calculation

* revert last commit

* Implemented OS.clipboard (using var2str())

* some sanity checks

* formatting

* use text system instead of os clibboard
This commit is contained in:
Variable 2022-06-23 22:14:03 +05:00 committed by GitHub
parent 8cfdcb5ebc
commit c3eaddd9ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4,7 +4,6 @@ enum SelectionOperation { ADD, SUBTRACT, INTERSECT }
const KEY_MOVE_ACTION_NAMES := ["ui_up", "ui_down", "ui_left", "ui_right"]
var clipboard := Clipboard.new()
var is_moving_content := false
var arrow_key_move := false
var is_pasting := false
@ -33,13 +32,6 @@ var clear_in_selected_cels := true
onready var marching_ants_outline: Sprite = $MarchingAntsOutline
class Clipboard:
var image := Image.new()
var selection_bitmap := BitMap.new()
var big_bounding_rectangle := Rect2()
var selection_offset := Vector2.ZERO
class Gizmo:
enum Type { SCALE, ROTATE }
@ -658,6 +650,11 @@ func cut() -> void:
func copy() -> void:
var project: Project = Global.current_project
var cl_image := Image.new()
var cl_selection_bitmap = BitMap.new()
var cl_big_bounding_rectangle := Rect2()
var cl_selection_offset := Vector2.ZERO
if !project.has_selection:
return
var image: Image = project.frames[project.current_frame].cels[project.current_layer].image
@ -666,7 +663,7 @@ func copy() -> void:
to_copy.copy_from(preview_image)
var selected_bitmap_copy := project.selection_bitmap.duplicate()
project.move_bitmap_values(selected_bitmap_copy, false)
clipboard.selection_bitmap = selected_bitmap_copy
cl_selection_bitmap = selected_bitmap_copy
else:
to_copy = image.get_rect(big_bounding_rectangle)
to_copy.lock()
@ -682,10 +679,22 @@ func copy() -> void:
if not project.selection_bitmap.get_bit(pos + offset_pos):
to_copy.set_pixelv(pos, Color(0))
to_copy.unlock()
clipboard.selection_bitmap = project.selection_bitmap.duplicate()
clipboard.image = to_copy
clipboard.big_bounding_rectangle = big_bounding_rectangle
clipboard.selection_offset = project.selection_offset
cl_selection_bitmap = project.selection_bitmap.duplicate()
cl_image = to_copy
cl_big_bounding_rectangle = big_bounding_rectangle
cl_selection_offset = project.selection_offset
var transfer_clipboard = {
"image": cl_image,
"selection_bitmap": cl_selection_bitmap,
"big_bounding_rectangle": cl_big_bounding_rectangle,
"selection_offset": cl_selection_offset,
}
# Store to ".clipboard.txt" file
var clipboard_file = File.new()
clipboard_file.open("user://clipboard.txt", File.WRITE)
clipboard_file.store_var(transfer_clipboard, true)
clipboard_file.close()
if !to_copy.is_empty():
var pattern: Patterns.Pattern = Global.patterns_popup.get_pattern(0)
@ -697,35 +706,50 @@ func copy() -> void:
func paste() -> void:
if clipboard.image.is_empty():
# Read from the ".clipboard.txt" file
var clipboard_file = File.new()
if !clipboard_file.file_exists("user://clipboard.txt"):
return
clear_selection()
undo_data = get_undo_data(true)
var project: Project = Global.current_project
clipboard_file.open("user://clipboard.txt", File.READ)
var clipboard = clipboard_file.get_var(true)
clipboard_file.close()
original_bitmap = project.selection_bitmap.duplicate()
original_big_bounding_rectangle = big_bounding_rectangle
original_offset = project.selection_offset
if typeof(clipboard) == TYPE_DICTIONARY:
# A sanity check
if not clipboard.has_all(
["image", "selection_bitmap", "big_bounding_rectangle", "selection_offset"]
):
return
var clip_bitmap: BitMap = clipboard.selection_bitmap.duplicate()
var max_size := Vector2(
max(clip_bitmap.get_size().x, project.selection_bitmap.get_size().x),
max(clip_bitmap.get_size().y, project.selection_bitmap.get_size().y)
)
if clipboard.image.is_empty():
return
clear_selection()
undo_data = get_undo_data(true)
var project: Project = Global.current_project
project.selection_bitmap = Global.current_project.resize_bitmap(clip_bitmap, max_size)
self.big_bounding_rectangle = clipboard.big_bounding_rectangle
project.selection_offset = clipboard.selection_offset
original_bitmap = project.selection_bitmap.duplicate()
original_big_bounding_rectangle = big_bounding_rectangle
original_offset = project.selection_offset
temp_bitmap = project.selection_bitmap
temp_rect = big_bounding_rectangle
is_moving_content = true
is_pasting = true
original_preview_image = clipboard.image
preview_image.copy_from(original_preview_image)
preview_image_texture.create_from_image(preview_image, 0)
var clip_bitmap: BitMap = clipboard.selection_bitmap.duplicate()
var max_size := Vector2(
max(clip_bitmap.get_size().x, project.selection_bitmap.get_size().x),
max(clip_bitmap.get_size().y, project.selection_bitmap.get_size().y)
)
project.selection_bitmap_changed()
project.selection_bitmap = Global.current_project.resize_bitmap(clip_bitmap, max_size)
self.big_bounding_rectangle = clipboard.big_bounding_rectangle
project.selection_offset = clipboard.selection_offset
temp_bitmap = project.selection_bitmap
temp_rect = big_bounding_rectangle
is_moving_content = true
is_pasting = true
original_preview_image = clipboard.image
preview_image.copy_from(original_preview_image)
preview_image_texture.create_from_image(preview_image, 0)
project.selection_bitmap_changed()
func delete(selected_cels := true) -> void:
@ -771,7 +795,14 @@ func new_brush() -> void:
brush.copy_from(preview_image)
var selected_bitmap_copy := project.selection_bitmap.duplicate()
project.move_bitmap_values(selected_bitmap_copy, false)
clipboard.selection_bitmap = selected_bitmap_copy
var clipboard = str2var(OS.get_clipboard())
if typeof(clipboard) == TYPE_DICTIONARY:
# A sanity check
if not clipboard.has_all(
["image", "selection_bitmap", "big_bounding_rectangle", "selection_offset"]
):
return
clipboard.selection_bitmap = selected_bitmap_copy
else:
brush = image.get_rect(big_bounding_rectangle)
brush.lock()