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

UndoRedo - Unstable with bugs

Started working on UndoRedo. Currently works with basic drawing/erasing/bucket filling as well as the rectangle selection tool, custom brushes and copying/pasting.

May not work with multiple layers and frames and it does not work with the rest of the tools and buttons. Also does not work when pressing both mouse buttons at the same time, or when the cursor is outside the canvas when drawing.
This commit is contained in:
OverloadedOrama 2019-10-29 23:22:38 +02:00
parent 6350995385
commit 7b8c6bbf00
9 changed files with 227 additions and 186 deletions

101
Main.tscn
View file

@ -16,13 +16,13 @@ anchor_bottom = 1.0
script = ExtResource( 1 )
[node name="UI" type="HBoxContainer" parent="."]
editor/display_folded = true
anchor_right = 1.0
anchor_bottom = 1.0
size_flags_horizontal = 3
custom_constants/separation = 0
[node name="ToolPanel" type="Panel" parent="UI"]
editor/display_folded = true
margin_right = 230.0
margin_bottom = 600.0
rect_min_size = Vector2( 230, 0 )
@ -35,13 +35,13 @@ size_flags_horizontal = 3
size_flags_vertical = 3
[node name="MenusAndTools" type="VBoxContainer" parent="UI/ToolPanel/Tools"]
margin_right = 242.0
margin_right = 230.0
margin_bottom = 266.0
size_flags_vertical = 3
[node name="MenuItems" type="HBoxContainer" parent="UI/ToolPanel/Tools/MenusAndTools"]
editor/display_folded = true
margin_right = 242.0
margin_right = 230.0
margin_bottom = 20.0
[node name="FileMenu" type="MenuButton" parent="UI/ToolPanel/Tools/MenusAndTools/MenuItems"]
@ -72,13 +72,11 @@ mouse_default_cursor_shape = 2
text = "Help"
[node name="PaintToolsContainer" type="HBoxContainer" parent="UI/ToolPanel/Tools/MenusAndTools"]
editor/display_folded = true
margin_top = 24.0
margin_right = 242.0
margin_right = 230.0
margin_bottom = 44.0
[node name="Pencil" type="Button" parent="UI/ToolPanel/Tools/MenusAndTools/PaintToolsContainer"]
editor/display_folded = true
margin_right = 51.0
margin_bottom = 20.0
hint_tooltip = "P for left mouse button
@ -94,7 +92,6 @@ centered = false
offset = Vector2( 0, -10 )
[node name="Eraser" type="Button" parent="UI/ToolPanel/Tools/MenusAndTools/PaintToolsContainer"]
editor/display_folded = true
margin_left = 55.0
margin_right = 106.0
margin_bottom = 20.0
@ -121,9 +118,8 @@ button_mask = 3
text = "Bucket"
[node name="ColorToolsContainer" type="HBoxContainer" parent="UI/ToolPanel/Tools/MenusAndTools"]
editor/display_folded = true
margin_top = 48.0
margin_right = 242.0
margin_right = 230.0
margin_bottom = 68.0
[node name="PaintAllPixelsSameColor" type="Button" parent="UI/ToolPanel/Tools/MenusAndTools/ColorToolsContainer"]
@ -148,9 +144,8 @@ button_mask = 3
text = "Lighten/Darken"
[node name="SelectionToolsContainer2" type="HBoxContainer" parent="UI/ToolPanel/Tools/MenusAndTools"]
editor/display_folded = true
margin_top = 72.0
margin_right = 242.0
margin_right = 230.0
margin_bottom = 92.0
[node name="RectSelect" type="Button" parent="UI/ToolPanel/Tools/MenusAndTools/SelectionToolsContainer2"]
@ -165,30 +160,29 @@ text = "RectSelect"
[node name="HSeparator" type="HSeparator" parent="UI/ToolPanel/Tools"]
margin_top = 270.0
margin_right = 242.0
margin_right = 230.0
margin_bottom = 274.0
[node name="ToolOptions" type="HBoxContainer" parent="UI/ToolPanel/Tools"]
editor/display_folded = true
margin_top = 278.0
margin_right = 242.0
margin_right = 230.0
margin_bottom = 544.0
size_flags_vertical = 3
custom_constants/separation = 0
[node name="LeftToolOptions" type="VBoxContainer" parent="UI/ToolPanel/Tools/ToolOptions"]
margin_right = 119.0
margin_right = 113.0
margin_bottom = 266.0
size_flags_horizontal = 3
[node name="LeftLabel" type="Label" parent="UI/ToolPanel/Tools/ToolOptions/LeftToolOptions"]
margin_right = 119.0
margin_right = 113.0
margin_bottom = 14.0
text = "Left tool options"
[node name="LeftIndicatorCheckbox" type="CheckBox" parent="UI/ToolPanel/Tools/ToolOptions/LeftToolOptions"]
margin_top = 18.0
margin_right = 119.0
margin_right = 113.0
margin_bottom = 42.0
hint_tooltip = "Show left mouse indicator when drawing"
mouse_default_cursor_shape = 2
@ -207,13 +201,13 @@ size_flags_vertical = 0
[node name="BrushSizeLabel" type="Label" parent="UI/ToolPanel/Tools/ToolOptions/LeftToolOptions"]
margin_top = 82.0
margin_right = 119.0
margin_right = 113.0
margin_bottom = 96.0
text = "Brush size: "
[node name="LeftBrushSizeEdit" type="SpinBox" parent="UI/ToolPanel/Tools/ToolOptions/LeftToolOptions"]
margin_top = 100.0
margin_right = 119.0
margin_right = 113.0
margin_bottom = 124.0
mouse_default_cursor_shape = 2
min_value = 1.0
@ -222,14 +216,14 @@ suffix = "px"
[node name="ColorComesFrom" type="Label" parent="UI/ToolPanel/Tools/ToolOptions/LeftToolOptions"]
margin_top = 128.0
margin_right = 119.0
margin_right = 113.0
margin_bottom = 142.0
text = "Brush color from"
[node name="InterpolateColor" type="HBoxContainer" parent="UI/ToolPanel/Tools/ToolOptions/LeftToolOptions"]
editor/display_folded = true
margin_top = 146.0
margin_right = 119.0
margin_right = 113.0
margin_bottom = 162.0
[node name="BrushColorLabel" type="Label" parent="UI/ToolPanel/Tools/ToolOptions/LeftToolOptions/InterpolateColor"]
@ -241,7 +235,7 @@ text = "B"
[node name="LeftInterpolateFactor" type="HSlider" parent="UI/ToolPanel/Tools/ToolOptions/LeftToolOptions/InterpolateColor"]
margin_left = 13.0
margin_right = 107.0
margin_right = 101.0
margin_bottom = 16.0
hint_tooltip = "Choose if the brush's color should come from the brush itself (left), or the currently selected color (right)"
size_flags_horizontal = 3
@ -251,44 +245,44 @@ value = 0.5
ticks_on_borders = true
[node name="SelectedColorLabel" type="Label" parent="UI/ToolPanel/Tools/ToolOptions/LeftToolOptions/InterpolateColor"]
margin_left = 111.0
margin_left = 105.0
margin_top = 1.0
margin_right = 119.0
margin_right = 113.0
margin_bottom = 15.0
rect_pivot_offset = Vector2( -90, -47 )
text = "C"
[node name="LeftHorizontalMirroring" type="CheckBox" parent="UI/ToolPanel/Tools/ToolOptions/LeftToolOptions"]
margin_top = 166.0
margin_right = 119.0
margin_right = 113.0
margin_bottom = 190.0
text = "Horiz. Mirror"
[node name="LeftVerticalMirroring" type="CheckBox" parent="UI/ToolPanel/Tools/ToolOptions/LeftToolOptions"]
margin_top = 194.0
margin_right = 119.0
margin_right = 113.0
margin_bottom = 218.0
text = "Vert. Mirror"
[node name="VSeparator" type="VSeparator" parent="UI/ToolPanel/Tools/ToolOptions"]
margin_left = 119.0
margin_right = 123.0
margin_left = 113.0
margin_right = 117.0
margin_bottom = 266.0
[node name="RightToolOptions" type="VBoxContainer" parent="UI/ToolPanel/Tools/ToolOptions"]
margin_left = 123.0
margin_right = 242.0
margin_left = 117.0
margin_right = 230.0
margin_bottom = 266.0
size_flags_horizontal = 3
[node name="RightLabel" type="Label" parent="UI/ToolPanel/Tools/ToolOptions/RightToolOptions"]
margin_right = 119.0
margin_right = 113.0
margin_bottom = 14.0
text = "Right tool options"
[node name="RightIndicatorCheckbox" type="CheckBox" parent="UI/ToolPanel/Tools/ToolOptions/RightToolOptions"]
margin_top = 18.0
margin_right = 119.0
margin_right = 113.0
margin_bottom = 42.0
hint_tooltip = "Show right mouse indicator when drawing"
mouse_default_cursor_shape = 2
@ -306,13 +300,13 @@ size_flags_vertical = 0
[node name="BrushSizeLabel" type="Label" parent="UI/ToolPanel/Tools/ToolOptions/RightToolOptions"]
margin_top = 82.0
margin_right = 119.0
margin_right = 113.0
margin_bottom = 96.0
text = "Brush size: "
[node name="RightBrushSizeEdit" type="SpinBox" parent="UI/ToolPanel/Tools/ToolOptions/RightToolOptions"]
margin_top = 100.0
margin_right = 119.0
margin_right = 113.0
margin_bottom = 124.0
mouse_default_cursor_shape = 2
min_value = 1.0
@ -321,14 +315,14 @@ suffix = "px"
[node name="ColorComesFrom" type="Label" parent="UI/ToolPanel/Tools/ToolOptions/RightToolOptions"]
margin_top = 128.0
margin_right = 119.0
margin_right = 113.0
margin_bottom = 142.0
text = "Brush color from"
[node name="InterpolateColor" type="HBoxContainer" parent="UI/ToolPanel/Tools/ToolOptions/RightToolOptions"]
editor/display_folded = true
margin_top = 146.0
margin_right = 119.0
margin_right = 113.0
margin_bottom = 162.0
[node name="BrushColorLabel" type="Label" parent="UI/ToolPanel/Tools/ToolOptions/RightToolOptions/InterpolateColor"]
@ -340,7 +334,7 @@ text = "B"
[node name="RightInterpolateFactor" type="HSlider" parent="UI/ToolPanel/Tools/ToolOptions/RightToolOptions/InterpolateColor"]
margin_left = 13.0
margin_right = 107.0
margin_right = 101.0
margin_bottom = 16.0
hint_tooltip = "Choose if the brush's color should come from the brush itself (left), or the currently selected color (right)"
size_flags_horizontal = 3
@ -350,34 +344,33 @@ value = 0.5
ticks_on_borders = true
[node name="SelectedColorLabel" type="Label" parent="UI/ToolPanel/Tools/ToolOptions/RightToolOptions/InterpolateColor"]
margin_left = 111.0
margin_left = 105.0
margin_top = 1.0
margin_right = 119.0
margin_right = 113.0
margin_bottom = 15.0
rect_pivot_offset = Vector2( -90, -47 )
text = "C"
[node name="RightHorizontalMirroring" type="CheckBox" parent="UI/ToolPanel/Tools/ToolOptions/RightToolOptions"]
margin_top = 166.0
margin_right = 119.0
margin_right = 113.0
margin_bottom = 190.0
text = "Horiz. Mirror"
[node name="RightVerticalMirroring" type="CheckBox" parent="UI/ToolPanel/Tools/ToolOptions/RightToolOptions"]
margin_top = 194.0
margin_right = 119.0
margin_right = 113.0
margin_bottom = 218.0
text = "Vert. Mirror"
[node name="HSeparator2" type="HSeparator" parent="UI/ToolPanel/Tools"]
margin_top = 548.0
margin_right = 242.0
margin_right = 230.0
margin_bottom = 552.0
[node name="BrushesContainer" type="ScrollContainer" parent="UI/ToolPanel/Tools"]
editor/display_folded = true
margin_top = 556.0
margin_right = 242.0
margin_right = 230.0
margin_bottom = 592.0
size_flags_horizontal = 3
scroll_vertical_enabled = false
@ -402,7 +395,7 @@ offset = Vector2( 28, 0 )
[node name="HSeparator3" type="HSeparator" parent="UI/ToolPanel/Tools"]
margin_top = 596.0
margin_right = 242.0
margin_right = 230.0
margin_bottom = 600.0
[node name="CanvasAndTimeline" type="VBoxContainer" parent="UI"]
@ -412,6 +405,7 @@ margin_bottom = 600.0
size_flags_horizontal = 3
[node name="HBoxContainer" type="HBoxContainer" parent="UI/CanvasAndTimeline"]
editor/display_folded = true
margin_right = 634.0
margin_bottom = 464.0
size_flags_horizontal = 3
@ -472,7 +466,6 @@ zoom = Vector2( 0.15, 0.15 )
script = ExtResource( 6 )
[node name="AnimationTimeline" type="Panel" parent="UI/CanvasAndTimeline"]
editor/display_folded = true
margin_top = 468.0
margin_right = 634.0
margin_bottom = 600.0
@ -868,8 +861,8 @@ resizable = true
mode = 0
access = 2
filters = PoolStringArray( "*.pxo ; Pixelorama Project" )
current_dir = "/home/danielnaoexiste/Documents/Prog/Pixelorama"
current_path = "/home/danielnaoexiste/Documents/Prog/Pixelorama/"
current_dir = "C:/Users/Overloaded/Dropbox/Orama Founding Members/εταιρικα αρχεια/Godot Projects/Pixelorama"
current_path = "C:/Users/Overloaded/Dropbox/Orama Founding Members/εταιρικα αρχεια/Godot Projects/Pixelorama/"
[node name="SaveSprite" type="FileDialog" parent="."]
anchor_left = 0.5
@ -883,8 +876,8 @@ margin_bottom = 48.0
resizable = true
access = 2
filters = PoolStringArray( "*.pxo ; Pixelorama Project" )
current_dir = "/home/danielnaoexiste/Documents/Prog/Pixelorama"
current_path = "/home/danielnaoexiste/Documents/Prog/Pixelorama/"
current_dir = "C:/Users/Overloaded/Dropbox/Orama Founding Members/εταιρικα αρχεια/Godot Projects/Pixelorama"
current_path = "C:/Users/Overloaded/Dropbox/Orama Founding Members/εταιρικα αρχεια/Godot Projects/Pixelorama/"
[node name="ImportSprites" type="FileDialog" parent="."]
margin_right = 515.0
@ -894,8 +887,8 @@ resizable = true
mode = 1
access = 2
filters = PoolStringArray( "*jpg, *.png ; JPG, PNG Images" )
current_dir = "/home/danielnaoexiste/Documents/Prog/Pixelorama"
current_path = "/home/danielnaoexiste/Documents/Prog/Pixelorama/"
current_dir = "C:/Users/Overloaded/Dropbox/Orama Founding Members/εταιρικα αρχεια/Godot Projects/Pixelorama"
current_path = "C:/Users/Overloaded/Dropbox/Orama Founding Members/εταιρικα αρχεια/Godot Projects/Pixelorama/"
[node name="ExportSprites" type="FileDialog" parent="."]
anchor_left = 0.5
@ -910,8 +903,8 @@ window_title = "Export sprite"
resizable = true
access = 2
filters = PoolStringArray( "*.png ; PNG Image" )
current_dir = "/home/danielnaoexiste/Documents/Prog/Pixelorama"
current_path = "/home/danielnaoexiste/Documents/Prog/Pixelorama/"
current_dir = "C:/Users/Overloaded/Dropbox/Orama Founding Members/εταιρικα αρχεια/Godot Projects/Pixelorama"
current_path = "C:/Users/Overloaded/Dropbox/Orama Founding Members/εταιρικα αρχεια/Godot Projects/Pixelorama/"
[node name="ScaleImage" type="ConfirmationDialog" parent="."]
editor/display_folded = true

View file

@ -11,6 +11,7 @@ var frame_button : VBoxContainer
var frame_texture_rect : TextureRect
var previous_mouse_pos := Vector2.ZERO
var previous_action := "None"
var mouse_inside_canvas := false #used for undo
var sprite_changed_this_frame := false #for optimization purposes
@ -91,8 +92,22 @@ func _process(delta) -> void:
Global.cursor_position_label.text = "[%sx%s]" % [size.x, size.y]
else:
Global.cursor_position_label.text = "[%sx%s] %s, %s" % [size.x, size.y, mouse_pos_floored.x, mouse_pos_floored.y]
#Handle current tool
match current_action:
#Handle Undo/Redo
if point_in_rectangle(mouse_pos, location, location + size) && Global.can_draw && Global.has_focus:
if Input.is_action_just_pressed("left_mouse") || Input.is_action_just_pressed("right_mouse"):
if current_action != "None":
if current_action == "RectSelect":
handle_undo("Rectangle Select")
else:
handle_undo("Draw")
elif Input.is_action_just_released("left_mouse") || Input.is_action_just_released("right_mouse"):
if previous_action != "None" && previous_action != "RectSelect":
handle_redo("Draw")
match current_action: #Handle current tool
"Pencil":
var current_color : Color
if current_mouse_button == "left_mouse":
@ -130,7 +145,7 @@ func _process(delta) -> void:
flood_fill(pos, layers[current_layer_index][0].get_pixelv(pos), current_color)
"PaintAllPixelsSameColor":
if point_in_rectangle(mouse_pos, location, location + size) && Global.current_frame == frame:
if point_in_rectangle(mouse_pos, location, location + size) && Global.can_draw && Global.has_focus && Global.current_frame == frame:
var current_color : Color
if current_mouse_button == "left_mouse":
current_color = Global.left_color_picker.color
@ -145,7 +160,7 @@ func _process(delta) -> void:
layers[current_layer_index][0].set_pixel(xx, yy, current_color)
sprite_changed_this_frame = true
"LightenDarken":
if point_in_rectangle(mouse_pos, location, location + size):
if point_in_rectangle(mouse_pos, location, location + size) && Global.can_draw && Global.has_focus && Global.current_frame == frame:
var pixel_color : Color = layers[current_layer_index][0].get_pixelv(mouse_pos)
var amount := 0.05
var color_changed := pixel_color.lightened(amount)
@ -208,10 +223,34 @@ func _process(delta) -> void:
for yy in range(start_pos.y, end_pos.y):
Global.selected_pixels.append(Vector2(xx, yy))
is_making_selection = "None"
handle_redo("Rectangle Select")
previous_action = current_action
if sprite_changed_this_frame:
update_texture(current_layer_index)
func handle_undo(action : String) -> void:
#I'm not sure why I have to unlock it, but...
#...if I don't, it doesn't work properly
layers[current_layer_index][0].unlock()
var data = layers[current_layer_index][0].data
layers[current_layer_index][0].lock()
Global.undo_redo.create_action(action)
Global.undo_redo.add_undo_property(layers[current_layer_index][0], "data", data)
if action == "Rectangle Select":
var selected_pixels = Global.selected_pixels.duplicate()
Global.undo_redo.add_undo_property(Global.selection_rectangle, "polygon", Global.selection_rectangle.polygon)
Global.undo_redo.add_undo_property(Global, "selected_pixels", selected_pixels)
Global.undo_redo.add_undo_method(Global, "undo", self, current_layer_index)
func handle_redo(action : String) -> void:
Global.undo_redo.add_do_property(layers[current_layer_index][0], "data", layers[current_layer_index][0].data)
if action == "Rectangle Select":
Global.undo_redo.add_do_property(Global.selection_rectangle, "polygon", Global.selection_rectangle.polygon)
Global.undo_redo.add_do_property(Global, "selected_pixels", Global.selected_pixels)
Global.undo_redo.add_do_method(Global, "redo", self, current_layer_index)
Global.undo_redo.commit_action()
print("Do: ", Global.undo_redo.get_current_action_name())
func update_texture(layer_index : int) -> void:
layers[layer_index][1].create_from_image(layers[layer_index][0], 0)
@ -566,4 +605,3 @@ func rectangle_center(pos : Vector2, size : Vector2) -> Vector2:
func _on_Timer_timeout() -> void:
Global.can_draw = true

View file

@ -1,5 +1,6 @@
extends Node
var undo_redo : UndoRedo
var current_frame := 0 setget set_current_frame_label
# warning-ignore:unused_class_variable
var can_draw := false
@ -102,6 +103,7 @@ var custom_right_brush_texture := ImageTexture.new()
func _ready() -> void:
undo_redo = UndoRedo.new()
var root = get_tree().get_root()
canvas = find_node_by_name(root, "Canvas")
canvases.append(canvas)
@ -159,6 +161,18 @@ func find_node_by_name(root, node_name) -> Node:
return found
return null
func undo(canvas : Canvas, layer_index : int) -> void:
var action_name : String = undo_redo.get_current_action_name()
if action_name == "Draw" || action_name == "Rectangle Select":
canvas.update_texture(layer_index)
print("Undo: ", action_name)
func redo(canvas : Canvas, layer_index : int) -> void:
var action_name : String = undo_redo.get_current_action_name()
if action_name == "Draw" || action_name == "Rectangle Select":
canvas.update_texture(layer_index)
print("Redo: ", action_name)
func change_frame() -> void:
for c in canvases:
c.visible = false

View file

@ -35,9 +35,9 @@ func _ready() -> void:
"Crop Image" : 0,
"Clear Selection" : 0,
"Flip Horizontal": KEY_MASK_SHIFT + KEY_H,
"Flip Vertical": KEY_MASK_SHIFT + KEY_V
#"Undo" : KEY_MASK_CTRL + KEY_Z,
#"Redo" : KEY_MASK_SHIFT + KEY_MASK_CTRL + KEY_Z,
"Flip Vertical": KEY_MASK_SHIFT + KEY_V,
"Undo" : KEY_MASK_CTRL + KEY_Z,
"Redo" : KEY_MASK_SHIFT + KEY_MASK_CTRL + KEY_Z
}
var view_menu_items := {
"Tile Mode" : KEY_MASK_CTRL + KEY_T,
@ -196,6 +196,10 @@ func edit_menu_id_pressed(id : int) -> void:
canvas.layers[canvas.current_layer_index][0].flip_y()
canvas.layers[canvas.current_layer_index][0].lock()
canvas.update_texture(canvas.current_layer_index)
5: #Undo
Global.undo_redo.undo()
6: #Redo
Global.undo_redo.redo()
func view_menu_id_pressed(id : int) -> void:
match id:
@ -213,8 +217,8 @@ func help_menu_id_pressed(id : int) -> void:
Global.can_draw = false
func _on_CreateNewImage_confirmed() -> void:
var width := float($CreateNewImage/VBoxContainer/WidthCont/WidthValue.value)
var height := float($CreateNewImage/VBoxContainer/HeightCont/HeightValue.value)
var width = $CreateNewImage/VBoxContainer/WidthCont/WidthValue.value
var height = $CreateNewImage/VBoxContainer/HeightCont/HeightValue.value
var fill_color : Color = $CreateNewImage/VBoxContainer/FillColor/FillColor.color
clear_canvases()
Global.canvas = load("res://Prefabs/Canvas.tscn").instance()
@ -486,8 +490,8 @@ func _on_Tool_pressed(tool_pressed : BaseButton, mouse_press := true, key_for_le
tool_pressed.add_child(Global.right_indicator)
func _on_ScaleImage_confirmed() -> void:
var width = float($ScaleImage/VBoxContainer/WidthCont/WidthValue.value)
var height = float($ScaleImage/VBoxContainer/HeightCont/HeightValue.value)
var width = $ScaleImage/VBoxContainer/WidthCont/WidthValue.value
var height = $ScaleImage/VBoxContainer/HeightCont/HeightValue.value
for i in range(Global.canvas.layers.size() - 1, -1, -1):
var sprite = Image.new()
sprite = Global.canvas.layers[i][1].get_data()

View file

@ -12,7 +12,6 @@ var orig_colors := []
func _ready() -> void:
img = Image.new()
#img.create(Global.canvas.size.x, Global.canvas.size.y, false, Image.FORMAT_RGBA8)
img.create(1, 1, false, Image.FORMAT_RGBA8)
img.lock()
tex = ImageTexture.new()
@ -24,7 +23,8 @@ func _process(delta) -> void:
var mouse_pos_floored := mouse_pos.floor()
var start_pos := polygon[0]
var end_pos := polygon[2]
var layer : Image = Global.canvas.layers[Global.canvas.current_layer_index][0]
var current_layer_index := Global.canvas.current_layer_index
var layer : Image = Global.canvas.layers[current_layer_index][0]
if point_in_rectangle(mouse_pos, polygon[0], polygon[2]) && Global.selected_pixels.size() > 0 && (Global.current_left_tool == "RectSelect" || Global.current_right_tool == "RectSelect"):
get_parent().get_parent().mouse_default_cursor_shape = Input.CURSOR_MOVE
@ -46,11 +46,11 @@ func _process(delta) -> void:
for i in range(Global.selected_pixels.size()):
var curr_px = Global.selected_pixels[i]
if point_in_rectangle(curr_px, Global.canvas.location - Vector2.ONE, Global.canvas.size):
orig_colors.append(layer.get_pixelv(curr_px))
orig_colors.append(layer.get_pixelv(curr_px)) #Color of pixel
var px = curr_px - Global.selected_pixels[0]
img.set_pixelv(px, orig_colors[i])
layer.set_pixelv(curr_px, Color(0, 0, 0, 0))
else:
else: #If part of selection is outside canvas
orig_colors.append(Color(0, 0, 0, 0))
Global.canvas.update_texture(Global.canvas.current_layer_index)
tex.create_from_image(img, 0)
@ -93,6 +93,8 @@ func _process(delta) -> void:
for yy in range(start_pos.y, end_pos.y):
Global.selected_pixels.append(Vector2(xx, yy))
Global.canvas.handle_redo("Rectangle Select") #Redo
#Handle copy
if Input.is_action_just_pressed("copy") && Global.selected_pixels.size() > 0:
Global.image_clipboard = layer.get_rect(Rect2(polygon[0], polygon[2] - polygon[0]))
@ -105,11 +107,12 @@ func _process(delta) -> void:
Global.create_brush_button(brush_img)
#Handle paste
#if Input.is_action_just_pressed("paste") && Global.selected_pixels.size() > 0 && !is_dragging:
if Input.is_action_just_pressed("paste") && Global.selected_pixels.size() > 0 && Global.image_clipboard.get_size() > Vector2.ZERO:
Global.canvas.handle_undo("Draw")
layer.blend_rect(Global.image_clipboard, Rect2(Vector2.ZERO, polygon[2]-polygon[0]), polygon[0])
layer.lock()
Global.canvas.update_texture(Global.canvas.current_layer_index)
Global.canvas.handle_redo("Draw")
#Global.canvas.update_texture(Global.canvas.current_layer_index)
func _draw() -> void:
if img.get_size() == polygon[2] - polygon[0]:
@ -117,4 +120,3 @@ func _draw() -> void:
func point_in_rectangle(p : Vector2, coord1 : Vector2, coord2 : Vector2) -> bool:
return p.x > coord1.x && p.y > coord1.y && p.x < coord2.x && p.y < coord2.y

View file

@ -7,7 +7,7 @@ custom_features=""
export_filter="all_resources"
include_filter=""
exclude_filter=""
export_path="C:/Users/Overloaded/Dropbox/Orama Interactive/Projects/[Programa Labs]/Pixelorama/Stable/Pixelorama.exe"
export_path="C:/Users/Overloaded/Dropbox/Orama Interactive/Projects/[Programa Labs]/Pixelorama/Full of bugs/Pixelorama.exe"
patch_list=PoolStringArray( )
script_export_mode=1
script_encryption_key=""

View file

@ -131,16 +131,6 @@ right_lightdark_tool={
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":true,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":85,"unicode":0,"echo":false,"script":null)
]
}
flip_h={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":true,"control":false,"meta":false,"command":false,"pressed":false,"scancode":72,"unicode":0,"echo":false,"script":null)
]
}
flip_v={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":true,"control":false,"meta":false,"command":false,"pressed":false,"scancode":86,"unicode":0,"echo":false,"script":null)
]
}
[rendering]