From 2b710afd3b176d04516404ad415aa5d977bb5909 Mon Sep 17 00:00:00 2001 From: OverloadedOrama <35376950+OverloadedOrama@users.noreply.github.com> Date: Wed, 18 Sep 2019 17:47:28 +0300 Subject: [PATCH] Added rectangle selection tool, copy & paste selection and Tile Mode - New rectangle selection tool. Hold mouse button to create selection, release to finish it. You cannot draw outside of the selection. - The selection can be moved around, and if Shift is pressed, selected content gets moved too. Currently cannot be moved outside the canvas. - You can copy the selection with Ctrl + C, and paste it on a new selection with Ctrl + V. - Added tile mode. Basically draws the canvas 8 more times in all directions. --- Main.tscn | 31 +++++++-- Scripts/Canvas.gd | 123 +++++++++++++++++++++++++++++----- Scripts/Global.gd | 8 +++ Scripts/Main.gd | 22 +++++- Scripts/SelectionRectangle.gd | 107 +++++++++++++++++++++++++++++ export_presets.cfg | 2 +- project.godot | 20 ++++++ 7 files changed, 285 insertions(+), 28 deletions(-) create mode 100644 Scripts/SelectionRectangle.gd diff --git a/Main.tscn b/Main.tscn index f8935e88e..b928d122f 100644 --- a/Main.tscn +++ b/Main.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=7 format=2] +[gd_scene load_steps=8 format=2] [ext_resource path="res://Scripts/Main.gd" type="Script" id=1] [ext_resource path="res://Main Theme.tres" type="Theme" id=2] @@ -6,6 +6,7 @@ [ext_resource path="res://Assets/Graphics/right.png" type="Texture" id=4] [ext_resource path="res://Canvas.tscn" type="PackedScene" id=5] [ext_resource path="res://Scripts/CameraMovement.gd" type="Script" id=6] +[ext_resource path="res://Scripts/SelectionRectangle.gd" type="Script" id=7] [node name="Control" type="Control"] anchor_right = 1.0 @@ -13,7 +14,6 @@ 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 @@ -31,12 +31,12 @@ size_flags_horizontal = 3 size_flags_vertical = 3 [node name="MenusAndTools" type="VBoxContainer" parent="UI/ToolPanel/Tools"] -editor/display_folded = true margin_right = 320.0 margin_bottom = 294.0 size_flags_vertical = 3 [node name="MenuItems" type="HBoxContainer" parent="UI/ToolPanel/Tools/MenusAndTools"] +editor/display_folded = true margin_right = 320.0 margin_bottom = 20.0 @@ -65,7 +65,8 @@ editor/display_folded = true margin_right = 51.0 margin_bottom = 20.0 hint_tooltip = "P for left mouse button -Alt + P for right mouse button" +Alt + P for right mouse button +Hold Shift to make a line" mouse_default_cursor_shape = 2 button_mask = 3 text = "Pencil" @@ -81,7 +82,8 @@ margin_left = 55.0 margin_right = 106.0 margin_bottom = 20.0 hint_tooltip = "E for left mouse button -Alt + E for right mouse button" +Alt + E for right mouse button +Hold Shift to make a line" mouse_default_cursor_shape = 2 button_mask = 3 text = "Eraser" @@ -101,6 +103,17 @@ mouse_default_cursor_shape = 2 button_mask = 3 text = "Bucket" +[node name="RectSelect" type="Button" parent="UI/ToolPanel/Tools/MenusAndTools/ToolsContainer"] +margin_left = 170.0 +margin_right = 249.0 +margin_bottom = 20.0 +hint_tooltip = "R for left mouse button +Alt + R for right mouse button +Press Shift to move the content" +mouse_default_cursor_shape = 2 +button_mask = 3 +text = "RectSelect" + [node name="HSeparator" type="HSeparator" parent="UI/ToolPanel/Tools"] margin_top = 298.0 margin_right = 320.0 @@ -240,6 +253,12 @@ current = true zoom = Vector2( 0.15, 0.15 ) script = ExtResource( 6 ) +[node name="SelectionRectangle" type="Polygon2D" parent="UI/CanvasAndTimeline/ViewportContainer/Viewport"] +z_index = 1 +color = Color( 0.0823529, 0.694118, 0.623529, 0.592157 ) +polygon = PoolVector2Array( 0, 0, 0, 0, 0, 0, 0, 0 ) +script = ExtResource( 7 ) + [node name="AnimationTimeline" type="Panel" parent="UI/CanvasAndTimeline"] margin_top = 468.0 margin_right = 536.0 @@ -511,7 +530,7 @@ margin_right = 160.0 margin_bottom = 133.0 text = "Blue-Red Mode" -[node name="HSeparator3" type="HSeparator" parent="UI/LayerPanel/LayersAndMisc"] +[node name="HSeparator2" type="HSeparator" parent="UI/LayerPanel/LayersAndMisc"] margin_top = 524.0 margin_right = 160.0 margin_bottom = 528.0 diff --git a/Scripts/Canvas.gd b/Scripts/Canvas.gd index be5787162..b47ba1b55 100644 --- a/Scripts/Canvas.gd +++ b/Scripts/Canvas.gd @@ -15,6 +15,7 @@ var mouse_inside_canvas := false #used for undo var sprite_changed_this_frame := false #for optimization purposes var is_making_line := false +var is_making_selection := "None" var line_2d : Line2D # Called when the node enters the scene tree for the first time. @@ -54,13 +55,15 @@ func _process(delta) -> void: sprite_changed_this_frame = false update() var mouse_pos := get_local_mouse_position() - location + var mouse_pos_floored := mouse_pos.floor() + var mouse_pos_ceiled := mouse_pos.ceil() var current_mouse_button := "None" var current_action := "None" if Input.is_mouse_button_pressed(BUTTON_LEFT): - current_mouse_button = "L" + current_mouse_button = "left_mouse" current_action = Global.current_left_tool elif Input.is_mouse_button_pressed(BUTTON_RIGHT): - current_mouse_button = "R" + current_mouse_button = "right_mouse" current_action = Global.current_right_tool if visible: @@ -70,15 +73,14 @@ func _process(delta) -> void: mouse_inside_canvas = false Global.cursor_position_label.text = "[%sx%s]" % [size.x, size.y] else: - var mouse_pos_floored := mouse_pos.floor() 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: "Pencil": var current_color : Color - if current_mouse_button == "L": + if current_mouse_button == "left_mouse": current_color = Global.left_color_picker.color - elif current_mouse_button == "R": + elif current_mouse_button == "right_mouse": current_color = Global.right_color_picker.color pencil_and_eraser(mouse_pos, current_color, current_mouse_button) "Eraser": @@ -86,11 +88,35 @@ func _process(delta) -> void: "Fill": 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 == "L": + if current_mouse_button == "left_mouse": current_color = Global.left_color_picker.color - elif current_mouse_button == "R": + elif current_mouse_button == "right_mouse": current_color = Global.right_color_picker.color flood_fill(mouse_pos, layers[current_layer_index][0].get_pixelv(mouse_pos), current_color) + "RectSelect": + if point_in_rectangle(mouse_pos_floored, location - Vector2.ONE, location + size) && Global.can_draw && Global.has_focus && Global.current_frame == frame: + #If we're creating a new selection + if Global.selected_pixels.size() == 0 || !point_in_rectangle_equal(mouse_pos_floored, Global.selection_rectangle.polygon[0], Global.selection_rectangle.polygon[2]): + if Input.is_action_just_pressed(current_mouse_button): + Global.selection_rectangle.polygon[0] = mouse_pos_floored + Global.selection_rectangle.polygon[1] = mouse_pos_floored + Global.selection_rectangle.polygon[2] = mouse_pos_floored + Global.selection_rectangle.polygon[3] = mouse_pos_floored + is_making_selection = current_mouse_button + Global.selected_pixels.clear() + else: + if is_making_selection != "None": #If we're making a new selection... + var start_pos = Global.selection_rectangle.polygon[0] + if start_pos != mouse_pos_floored: + var end_pos := Vector2(mouse_pos_ceiled.x, mouse_pos_ceiled.y) + if mouse_pos.x < start_pos.x: + end_pos.x = mouse_pos_ceiled.x - 1 + if mouse_pos.y < start_pos.y: + end_pos.y = mouse_pos_ceiled.y - 1 + Global.selection_rectangle.polygon[1] = Vector2(end_pos.x, start_pos.y) + Global.selection_rectangle.polygon[2] = end_pos + Global.selection_rectangle.polygon[3] = Vector2(start_pos.x, end_pos.y) + if !is_making_line: previous_mouse_pos = mouse_pos @@ -99,6 +125,30 @@ func _process(delta) -> void: else: line_2d.set_point_position(1, mouse_pos) + if is_making_selection != "None": #If we're making a selection + if Input.is_action_just_released(is_making_selection): #Finish selection when button is released + var start_pos = Global.selection_rectangle.polygon[0] + var end_pos = Global.selection_rectangle.polygon[2] + if start_pos.x > end_pos.x: + var temp = end_pos.x + end_pos.x = start_pos.x + start_pos.x = temp + + if start_pos.y > end_pos.y: + var temp = end_pos.y + end_pos.y = start_pos.y + start_pos.y = temp + + Global.selection_rectangle.polygon[0] = start_pos + Global.selection_rectangle.polygon[1] = Vector2(end_pos.x, start_pos.y) + Global.selection_rectangle.polygon[2] = end_pos + Global.selection_rectangle.polygon[3] = Vector2(start_pos.x, end_pos.y) + + for xx in range(start_pos.x, end_pos.x): + for yy in range(start_pos.y, end_pos.y): + Global.selected_pixels.append(Vector2(xx, yy)) + is_making_selection = "None" + if sprite_changed_this_frame: update_texture(current_layer_index) @@ -158,6 +208,16 @@ func _draw() -> void: for texture in layers: if texture[3]: #if it's visible draw_texture(texture[1], location) + + if Global.tile_mode: + draw_texture(texture[1], Vector2(location.x, location.y + size.y)) #Down + draw_texture(texture[1], Vector2(location.x - size.x, location.y + size.y)) #Down Left + draw_texture(texture[1], Vector2(location.x - size.x, location.y)) #Left + draw_texture(texture[1], location - size) #Up left + draw_texture(texture[1], Vector2(location.x, location.y - size.y)) #Up + draw_texture(texture[1], Vector2(location.x + size.x, location.y - size.y)) #Up right + draw_texture(texture[1], Vector2(location.x + size.x, location.y)) #Right + draw_texture(texture[1], location + size) #Down right #Idea taken from flurick (on GitHub) if Global.draw_grid: @@ -228,9 +288,9 @@ func pencil_and_eraser(mouse_pos : Vector2, color : Color, current_mouse_button is_making_line = true else: var brush_size := 1 - if current_mouse_button == "L": + if current_mouse_button == "left_mouse": brush_size = Global.left_brush_size - elif current_mouse_button == "R": + elif current_mouse_button == "right_mouse": brush_size = Global.right_brush_size if is_making_line: @@ -249,18 +309,33 @@ func pencil_and_eraser(mouse_pos : Vector2, color : Color, current_mouse_button func draw_pixel(pos : Vector2, color : Color, brush_size : int) -> void: if Global.can_draw && Global.has_focus && Global.current_frame == frame: + #If there is a selection and current pixel is not in it + var west_limit := location.x + var east_limit := location.x + size.x + var north_limit := location.y + var south_limit := location.y + size.y + if Global.selected_pixels.size() != 0: + west_limit = Global.selection_rectangle.polygon[0].x + east_limit = Global.selection_rectangle.polygon[2].x + north_limit = Global.selection_rectangle.polygon[0].y + south_limit = Global.selection_rectangle.polygon[2].y + var start_pos_x = pos.x - (brush_size >> 1) var start_pos_y = pos.y - (brush_size >> 1) for cur_pos_x in range(start_pos_x, start_pos_x + brush_size): #layers[current_layer_index][0].set_pixel(cur_pos_x, pos.y, color) for cur_pos_y in range(start_pos_y, start_pos_y + brush_size): if layers[current_layer_index][0].get_pixel(cur_pos_x, cur_pos_y) != color: #don't draw the same pixel over and over - layers[current_layer_index][0].set_pixel(cur_pos_x, cur_pos_y, color) - #layers[current_layer_index][0].set_pixelv(pos, color) - sprite_changed_this_frame = true + if point_in_rectangle_equal(Vector2(cur_pos_x, cur_pos_y), Vector2(west_limit, north_limit), Vector2(east_limit - 1, south_limit - 1)): + layers[current_layer_index][0].set_pixel(cur_pos_x, cur_pos_y, color) + #layers[current_layer_index][0].set_pixelv(pos, color) + sprite_changed_this_frame = true 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 + +func point_in_rectangle_equal(p : Vector2, coord1 : Vector2, coord2 : Vector2) -> bool: + return p.x >= coord1.x && p.y >= coord1.y && p.x <= coord2.x && p.y <= coord2.y #Bresenham's Algorithm #Thanks to https://godotengine.org/qa/35276/tile-based-line-drawing-algorithm-efficiency @@ -296,23 +371,35 @@ func flood_fill(pos : Vector2, target_color : Color, replace_color : Color) -> v elif pixel != target_color: return else: + var west_limit := location.x + var east_limit := location.x + size.x + var north_limit := location.y + var south_limit := location.y + size.y + if Global.selected_pixels.size() != 0: + west_limit = Global.selection_rectangle.polygon[0].x + east_limit = Global.selection_rectangle.polygon[2].x + north_limit = Global.selection_rectangle.polygon[0].y + south_limit = Global.selection_rectangle.polygon[2].y + + if !point_in_rectangle_equal(pos, Vector2(west_limit, north_limit), Vector2(east_limit - 1, south_limit - 1)): + return + var q = [pos] for n in q: var west : Vector2 = n var east : Vector2 = n - while west.x >= location.x && layers[current_layer_index][0].get_pixelv(west) == target_color: + while west.x >= west_limit && layers[current_layer_index][0].get_pixelv(west) == target_color: west += Vector2.LEFT - while east.x < location.x + size.x && layers[current_layer_index][0].get_pixelv(east) == target_color: + while east.x < east_limit && layers[current_layer_index][0].get_pixelv(east) == target_color: east += Vector2.RIGHT for px in range(west.x + 1, east.x): var p := Vector2(px, n.y) - #print(point_in_rectangle(p, location, size)) draw_pixel(p, replace_color, 1) var north := p + Vector2.UP var south := p + Vector2.DOWN - if north.y >= location.y && layers[current_layer_index][0].get_pixelv(north) == target_color: + if north.y >= north_limit && layers[current_layer_index][0].get_pixelv(north) == target_color: q.append(north) - if south.y < location.y + size.y && layers[current_layer_index][0].get_pixelv(south) == target_color: + if south.y < south_limit && layers[current_layer_index][0].get_pixelv(south) == target_color: q.append(south) func _on_Timer_timeout() -> void: diff --git a/Scripts/Global.gd b/Scripts/Global.gd index 796d3eefd..34dd155d6 100644 --- a/Scripts/Global.gd +++ b/Scripts/Global.gd @@ -12,6 +12,8 @@ var onion_skinning_future_rate := 0 # warning-ignore:unused_class_variable var onion_skinning_blue_red := false # warning-ignore:unused_class_variable +var tile_mode := false +# warning-ignore:unused_class_variable var draw_grid := false var canvases := [] var canvas : Canvas @@ -25,6 +27,9 @@ var left_brush_size := 1 # warning-ignore:unused_class_variable var right_brush_size := 1 var camera : Camera2D +var selection_rectangle : Polygon2D +var selected_pixels := [] +var image_clipboard : Image var file_menu : MenuButton var edit_menu : MenuButton @@ -61,6 +66,9 @@ func _ready() -> void: canvas_parent = canvas.get_parent() camera = find_node_by_name(canvas_parent, "Camera2D") + selection_rectangle = find_node_by_name(root, "SelectionRectangle") + image_clipboard = Image.new() + file_menu = find_node_by_name(root, "FileMenu") edit_menu = find_node_by_name(root, "EditMenu") left_indicator = find_node_by_name(root, "LeftIndicator") diff --git a/Scripts/Main.gd b/Scripts/Main.gd index d93357aad..b007710ff 100644 --- a/Scripts/Main.gd +++ b/Scripts/Main.gd @@ -6,6 +6,7 @@ var opensprite_file_selected := false var pencil_tool var eraser_tool var fill_tool +var rectselect_tool var import_as_new_frame : CheckBox var export_all_frames : CheckBox var export_as_single_file : CheckBox @@ -20,7 +21,6 @@ func _ready() -> void: # This property is only available in 3.2alpha or later, so use `set()` to fail gracefully if it doesn't exist. OS.set("min_window_size", Vector2(1024, 600)) - var file_menu_items := { "New..." : KEY_MASK_CTRL + KEY_N, "Open..." : KEY_MASK_CTRL + KEY_O, @@ -33,7 +33,9 @@ func _ready() -> void: } var edit_menu_items := { "Scale Image" : 0, - "Show Grid" : KEY_MASK_CTRL + KEY_G + "Tile Mode" : KEY_MASK_CTRL + KEY_T, + "Show Grid" : KEY_MASK_CTRL + KEY_G, + "Clear Selection" : 0 #"Undo" : KEY_MASK_CTRL + KEY_Z, #"Redo" : KEY_MASK_SHIFT + KEY_MASK_CTRL + KEY_Z, } @@ -53,10 +55,12 @@ func _ready() -> void: pencil_tool = $UI/ToolPanel/Tools/MenusAndTools/ToolsContainer/Pencil eraser_tool = $UI/ToolPanel/Tools/MenusAndTools/ToolsContainer/Eraser fill_tool = $UI/ToolPanel/Tools/MenusAndTools/ToolsContainer/Fill + rectselect_tool = $UI/ToolPanel/Tools/MenusAndTools/ToolsContainer/RectSelect pencil_tool.connect("pressed", self, "_on_Tool_pressed", [pencil_tool]) eraser_tool.connect("pressed", self, "_on_Tool_pressed", [eraser_tool]) fill_tool.connect("pressed", self, "_on_Tool_pressed", [fill_tool]) + rectselect_tool.connect("pressed", self, "_on_Tool_pressed", [rectselect_tool]) #Options for Import import_as_new_frame = CheckBox.new() @@ -89,6 +93,10 @@ func _input(event): _on_Tool_pressed(fill_tool, false, false) elif event.is_action_pressed("left_fill_tool"): _on_Tool_pressed(fill_tool, false, true) + elif event.is_action_pressed("right_rectangle_select_tool"): + _on_Tool_pressed(rectselect_tool, false, false) + elif event.is_action_pressed("left_rectangle_select_tool"): + _on_Tool_pressed(rectselect_tool, false, true) func file_menu_id_pressed(id : int) -> void: @@ -130,8 +138,16 @@ func edit_menu_id_pressed(id : int) -> void: 0: #Scale Image $ScaleImage.popup_centered() Global.can_draw = false - 1: #Show grid + 1: #Tile mode + Global.tile_mode = !Global.tile_mode + 2: #Show grid Global.draw_grid = !Global.draw_grid + 3: #Clear selection + Global.selection_rectangle.polygon[0] = Vector2.ZERO + Global.selection_rectangle.polygon[1] = Vector2.ZERO + Global.selection_rectangle.polygon[2] = Vector2.ZERO + Global.selection_rectangle.polygon[3] = Vector2.ZERO + Global.selected_pixels.clear() func _on_CreateNewImage_confirmed() -> void: var width = float($CreateNewImage/VBoxContainer/WidthCont/WidthValue.value) diff --git a/Scripts/SelectionRectangle.gd b/Scripts/SelectionRectangle.gd new file mode 100644 index 000000000..ac5fa6936 --- /dev/null +++ b/Scripts/SelectionRectangle.gd @@ -0,0 +1,107 @@ +extends Polygon2D + +var img : Image +var tex : ImageTexture +var is_dragging := false +var move_pixels := false +var diff_x := 0.0 +var diff_y := 0.0 +var orig_x := 0.0 +var orig_y := 0.0 +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() + tex.create_from_image(img, 0) + +# warning-ignore:unused_argument +func _process(delta) -> void: + var mouse_pos := get_local_mouse_position() - Global.canvas.location + 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] + + 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 + if (Global.current_left_tool == "RectSelect" && Input.is_action_just_pressed("left_mouse")) || (Global.current_right_tool == "RectSelect" && Input.is_action_just_pressed("right_mouse")): + #Begin dragging + is_dragging = true + if Input.is_key_pressed(KEY_SHIFT): + move_pixels = true + else: + move_pixels = false + img.fill(Color(0, 0, 0, 0)) + diff_x = end_pos.x - mouse_pos_floored.x + diff_y = end_pos.y - mouse_pos_floored.y + orig_x = start_pos.x - mouse_pos_floored.x + orig_y = start_pos.y - mouse_pos_floored.y + if move_pixels: + img.resize(polygon[2].x - polygon[0].x, polygon[2].y - polygon[0].y, 0) + img.lock() + for i in range(Global.selected_pixels.size()): + orig_colors.append(layer.get_pixelv(Global.selected_pixels[i])) + var px = Global.selected_pixels[i] - Global.selected_pixels[0] + img.set_pixelv(px, orig_colors[i]) + layer.set_pixelv(Global.selected_pixels[i], Color(0, 0, 0, 0)) + #print(layer.get_pixelv(Global.selected_pixels[i])) + Global.canvas.update_texture(Global.canvas.current_layer_index) + tex.create_from_image(img, 0) + update() + else: + get_parent().get_parent().mouse_default_cursor_shape = Input.CURSOR_CROSS + + if is_dragging: + if (Global.current_left_tool == "RectSelect" && Input.is_action_pressed("left_mouse")) || (Global.current_right_tool == "RectSelect" && Input.is_action_pressed("right_mouse")): + #Drag + if orig_x + mouse_pos_floored.x >= Global.canvas.location.x && diff_x + mouse_pos_floored.x <= Global.canvas.size.x: + start_pos.x = orig_x + mouse_pos_floored.x + end_pos.x = diff_x + mouse_pos_floored.x + + if orig_y + mouse_pos_floored.y >= Global.canvas.location.y && diff_y + mouse_pos_floored.y <= Global.canvas.size.y: + start_pos.y = orig_y + mouse_pos_floored.y + end_pos.y = diff_y + mouse_pos_floored.y + polygon[0] = start_pos + polygon[1] = Vector2(end_pos.x, start_pos.y) + polygon[2] = end_pos + polygon[3] = Vector2(start_pos.x, end_pos.y) + + if (Global.current_left_tool == "RectSelect" && Input.is_action_just_released("left_mouse")) || (Global.current_right_tool == "RectSelect" && Input.is_action_just_released("right_mouse")): + #Release Drag + is_dragging = false + if move_pixels: + for i in range(Global.selected_pixels.size()): + if orig_colors[i].a > 0: + var px = polygon[0] + Global.selected_pixels[i] - Global.selected_pixels[0] + layer.set_pixelv(px, orig_colors[i]) + Global.canvas.update_texture(Global.canvas.current_layer_index) + + orig_colors.clear() + Global.selected_pixels.clear() + for xx in range(start_pos.x, end_pos.x): + for yy in range(start_pos.y, end_pos.y): + Global.selected_pixels.append(Vector2(xx, yy)) + + #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])) + print(Rect2(polygon[0], polygon[2]), Global.image_clipboard.get_size()) + print(Global.image_clipboard.get_data()[0]) + + #Handle paste + if Input.is_action_just_pressed("paste") && Global.selected_pixels.size() > 0 && !is_dragging: + 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) + +func _draw() -> void: + if img.get_size() == polygon[2] - polygon[0]: + draw_texture(tex, polygon[0], Color(1, 1, 1, 0.5)) + +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 + \ No newline at end of file diff --git a/export_presets.cfg b/export_presets.cfg index 355a00f7a..a0440dc6c 100644 --- a/export_presets.cfg +++ b/export_presets.cfg @@ -7,7 +7,7 @@ custom_features="" export_filter="all_resources" include_filter="" exclude_filter="" -export_path="C:/Users/Overloaded/Dropbox/Orama Interactive/Projects/Pixelorama/Pixelorama.exe" +export_path="C:/Users/Overloaded/Dropbox/Orama Interactive/Projects/[Programa] Software/Pixelorama/Full of bugs/Pixelorama.exe" patch_list=PoolStringArray( ) script_export_mode=1 script_encryption_key="" diff --git a/project.godot b/project.godot index e2e134e79..87f54a925 100644 --- a/project.godot +++ b/project.godot @@ -96,6 +96,26 @@ right_fill_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":66,"unicode":0,"echo":false,"script":null) ] } +left_rectangle_select_tool={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":82,"unicode":0,"echo":false,"script":null) + ] +} +right_rectangle_select_tool={ +"deadzone": 0.5, +"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":82,"unicode":0,"echo":false,"script":null) + ] +} +copy={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":true,"meta":false,"command":true,"pressed":false,"scancode":67,"unicode":0,"echo":false,"script":null) + ] +} +paste={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":true,"meta":false,"command":true,"pressed":false,"scancode":86,"unicode":0,"echo":false,"script":null) + ] +} [rendering]