mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-19 01:29:49 +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:
parent
8cfdcb5ebc
commit
c3eaddd9ca
|
@ -4,7 +4,6 @@ enum SelectionOperation { ADD, SUBTRACT, INTERSECT }
|
||||||
|
|
||||||
const KEY_MOVE_ACTION_NAMES := ["ui_up", "ui_down", "ui_left", "ui_right"]
|
const KEY_MOVE_ACTION_NAMES := ["ui_up", "ui_down", "ui_left", "ui_right"]
|
||||||
|
|
||||||
var clipboard := Clipboard.new()
|
|
||||||
var is_moving_content := false
|
var is_moving_content := false
|
||||||
var arrow_key_move := false
|
var arrow_key_move := false
|
||||||
var is_pasting := false
|
var is_pasting := false
|
||||||
|
@ -33,13 +32,6 @@ var clear_in_selected_cels := true
|
||||||
onready var marching_ants_outline: Sprite = $MarchingAntsOutline
|
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:
|
class Gizmo:
|
||||||
enum Type { SCALE, ROTATE }
|
enum Type { SCALE, ROTATE }
|
||||||
|
|
||||||
|
@ -658,6 +650,11 @@ func cut() -> void:
|
||||||
|
|
||||||
func copy() -> void:
|
func copy() -> void:
|
||||||
var project: Project = Global.current_project
|
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:
|
if !project.has_selection:
|
||||||
return
|
return
|
||||||
var image: Image = project.frames[project.current_frame].cels[project.current_layer].image
|
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)
|
to_copy.copy_from(preview_image)
|
||||||
var selected_bitmap_copy := project.selection_bitmap.duplicate()
|
var selected_bitmap_copy := project.selection_bitmap.duplicate()
|
||||||
project.move_bitmap_values(selected_bitmap_copy, false)
|
project.move_bitmap_values(selected_bitmap_copy, false)
|
||||||
clipboard.selection_bitmap = selected_bitmap_copy
|
cl_selection_bitmap = selected_bitmap_copy
|
||||||
else:
|
else:
|
||||||
to_copy = image.get_rect(big_bounding_rectangle)
|
to_copy = image.get_rect(big_bounding_rectangle)
|
||||||
to_copy.lock()
|
to_copy.lock()
|
||||||
|
@ -682,10 +679,22 @@ func copy() -> void:
|
||||||
if not project.selection_bitmap.get_bit(pos + offset_pos):
|
if not project.selection_bitmap.get_bit(pos + offset_pos):
|
||||||
to_copy.set_pixelv(pos, Color(0))
|
to_copy.set_pixelv(pos, Color(0))
|
||||||
to_copy.unlock()
|
to_copy.unlock()
|
||||||
clipboard.selection_bitmap = project.selection_bitmap.duplicate()
|
cl_selection_bitmap = project.selection_bitmap.duplicate()
|
||||||
clipboard.image = to_copy
|
cl_image = to_copy
|
||||||
clipboard.big_bounding_rectangle = big_bounding_rectangle
|
cl_big_bounding_rectangle = big_bounding_rectangle
|
||||||
clipboard.selection_offset = project.selection_offset
|
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():
|
if !to_copy.is_empty():
|
||||||
var pattern: Patterns.Pattern = Global.patterns_popup.get_pattern(0)
|
var pattern: Patterns.Pattern = Global.patterns_popup.get_pattern(0)
|
||||||
|
@ -697,6 +706,21 @@ func copy() -> void:
|
||||||
|
|
||||||
|
|
||||||
func paste() -> void:
|
func paste() -> void:
|
||||||
|
# Read from the ".clipboard.txt" file
|
||||||
|
var clipboard_file = File.new()
|
||||||
|
if !clipboard_file.file_exists("user://clipboard.txt"):
|
||||||
|
return
|
||||||
|
clipboard_file.open("user://clipboard.txt", File.READ)
|
||||||
|
var clipboard = clipboard_file.get_var(true)
|
||||||
|
clipboard_file.close()
|
||||||
|
|
||||||
|
if typeof(clipboard) == TYPE_DICTIONARY:
|
||||||
|
# A sanity check
|
||||||
|
if not clipboard.has_all(
|
||||||
|
["image", "selection_bitmap", "big_bounding_rectangle", "selection_offset"]
|
||||||
|
):
|
||||||
|
return
|
||||||
|
|
||||||
if clipboard.image.is_empty():
|
if clipboard.image.is_empty():
|
||||||
return
|
return
|
||||||
clear_selection()
|
clear_selection()
|
||||||
|
@ -771,6 +795,13 @@ func new_brush() -> void:
|
||||||
brush.copy_from(preview_image)
|
brush.copy_from(preview_image)
|
||||||
var selected_bitmap_copy := project.selection_bitmap.duplicate()
|
var selected_bitmap_copy := project.selection_bitmap.duplicate()
|
||||||
project.move_bitmap_values(selected_bitmap_copy, false)
|
project.move_bitmap_values(selected_bitmap_copy, false)
|
||||||
|
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
|
clipboard.selection_bitmap = selected_bitmap_copy
|
||||||
else:
|
else:
|
||||||
brush = image.get_rect(big_bounding_rectangle)
|
brush = image.get_rect(big_bounding_rectangle)
|
||||||
|
|
Loading…
Reference in a new issue