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

Delete the contents of a selection when pressing "Delete"

This commit is contained in:
OverloadedOrama 2019-12-27 16:10:05 +02:00
parent f81ef37e92
commit fa3b2f649b
3 changed files with 76 additions and 59 deletions

View file

@ -119,8 +119,9 @@ text = "繁體中文 [zh_TW]"
[node name="Themes" type="VBoxContainer" parent="HSplitContainer/ScrollContainer/VBoxContainer"]
editor/display_folded = true
margin_right = 40.0
margin_bottom = 40.0
margin_top = 286.0
margin_right = 205.0
margin_bottom = 454.0
[node name="Theme Options" type="Label" parent="HSplitContainer/ScrollContainer/VBoxContainer/Themes"]
margin_right = 205.0
@ -136,62 +137,63 @@ mouse_default_cursor_shape = 2
text = "Dark"
[node name="Gray Theme" type="CheckBox" parent="HSplitContainer/ScrollContainer/VBoxContainer/Themes"]
margin_top = 32.0
margin_top = 60.0
margin_right = 205.0
margin_bottom = 56.0
margin_bottom = 84.0
mouse_default_cursor_shape = 2
text = "Gray"
[node name="Godot\'s Theme" type="CheckBox" parent="HSplitContainer/ScrollContainer/VBoxContainer/Themes"]
margin_top = 32.0
margin_top = 88.0
margin_right = 205.0
margin_bottom = 56.0
margin_bottom = 112.0
mouse_default_cursor_shape = 2
text = "Godot"
[node name="Gold Theme" type="CheckBox" parent="HSplitContainer/ScrollContainer/VBoxContainer/Themes"]
margin_top = 32.0
margin_top = 116.0
margin_right = 205.0
margin_bottom = 56.0
margin_bottom = 140.0
mouse_default_cursor_shape = 2
text = "Gold"
[node name="Light Theme" type="CheckBox" parent="HSplitContainer/ScrollContainer/VBoxContainer/Themes"]
margin_top = 32.0
margin_top = 144.0
margin_right = 205.0
margin_bottom = 56.0
margin_bottom = 168.0
mouse_default_cursor_shape = 2
text = "Light"
[node name="Grid&Guides" type="VBoxContainer" parent="HSplitContainer/ScrollContainer/VBoxContainer"]
editor/display_folded = true
visible = false
margin_top = 24.0
margin_right = 151.0
margin_bottom = 118.0
margin_top = 458.0
margin_right = 205.0
margin_bottom = 576.0
[node name="GridOptionsLabel" type="Label" parent="HSplitContainer/ScrollContainer/VBoxContainer/Grid&Guides"]
margin_right = 151.0
margin_right = 205.0
margin_bottom = 14.0
text = "Grid options"
rect_min_size = Vector2( 0, 28 )
text = "Grid Οptions:"
[node name="GridOptions" type="GridContainer" parent="HSplitContainer/ScrollContainer/VBoxContainer/Grid&Guides"]
margin_top = 18.0
margin_right = 151.0
margin_bottom = 94.0
margin_right = 205.0
margin_bottom = 118.0
custom_constants/vseparation = 4
custom_constants/hseparation = 4
columns = 2
[node name="WidthLabel" type="Label" parent="HSplitContainer/ScrollContainer/VBoxContainer/Grid&Guides/GridOptions"]
margin_top = 5.0
margin_right = 46.0
margin_right = 78.0
margin_bottom = 19.0
text = "Width:"
[node name="GridWidthValue" type="SpinBox" parent="HSplitContainer/ScrollContainer/VBoxContainer/Grid&Guides/GridOptions"]
margin_left = 50.0
margin_right = 124.0
margin_left = 82.0
margin_right = 156.0
margin_bottom = 24.0
min_value = 1.0
max_value = 16384.0
@ -200,14 +202,14 @@ suffix = "px"
[node name="Height" type="Label" parent="HSplitContainer/ScrollContainer/VBoxContainer/Grid&Guides/GridOptions"]
margin_top = 33.0
margin_right = 46.0
margin_right = 78.0
margin_bottom = 47.0
text = "Height:"
[node name="GridHeightValue" type="SpinBox" parent="HSplitContainer/ScrollContainer/VBoxContainer/Grid&Guides/GridOptions"]
margin_left = 50.0
margin_left = 82.0
margin_top = 28.0
margin_right = 124.0
margin_right = 156.0
margin_bottom = 52.0
min_value = 1.0
max_value = 16384.0
@ -216,28 +218,28 @@ suffix = "px"
[node name="GridColorLabel" type="Label" parent="HSplitContainer/ScrollContainer/VBoxContainer/Grid&Guides/GridOptions"]
margin_top = 59.0
margin_right = 46.0
margin_right = 78.0
margin_bottom = 73.0
text = "Color:"
[node name="GridColor" type="ColorPickerButton" parent="HSplitContainer/ScrollContainer/VBoxContainer/Grid&Guides/GridOptions"]
margin_left = 50.0
margin_left = 82.0
margin_top = 56.0
margin_right = 124.0
margin_right = 156.0
margin_bottom = 76.0
rect_min_size = Vector2( 64, 20 )
[node name="GuideColorLabel" type="Label" parent="HSplitContainer/ScrollContainer/VBoxContainer/Grid&Guides/GridOptions"]
margin_top = 59.0
margin_right = 46.0
margin_bottom = 73.0
margin_top = 83.0
margin_right = 78.0
margin_bottom = 97.0
text = "Guide color:"
[node name="GuideColor" type="ColorPickerButton" parent="HSplitContainer/ScrollContainer/VBoxContainer/Grid&Guides/GridOptions"]
margin_left = 50.0
margin_top = 56.0
margin_right = 124.0
margin_bottom = 76.0
margin_left = 82.0
margin_top = 80.0
margin_right = 156.0
margin_bottom = 100.0
rect_min_size = Vector2( 64, 20 )
color = Color( 0.63, 0.13, 0.94, 1 )
[connection signal="item_selected" from="HSplitContainer/Tree" to="." method="_on_Tree_item_selected"]

View file

@ -35,7 +35,7 @@ func _process(delta : float) -> void:
get_parent().get_parent().mouse_default_cursor_shape = Input.CURSOR_MOVE
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
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
# Begin dragging
is_dragging = true
if Input.is_key_pressed(KEY_SHIFT):
move_pixels = true
@ -52,25 +52,25 @@ func _process(delta : float) -> 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)) #Color of pixel
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: #If part of selection is outside canvas
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)
update()
# Makes line2d invisible
if is_instance_valid(Global.canvas.line_2d): # Checks to see if line_2d object still exists
if is_instance_valid(Global.canvas.line_2d): # Checks to see if line_2d object still exists
Global.canvas.line_2d.default_color = Color(0, 0, 0, 0)
else:
get_parent().get_parent().mouse_default_cursor_shape = Input.CURSOR_ARROW
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
# Drag
start_pos.x = orig_x + mouse_pos_floored.x
end_pos.x = diff_x + mouse_pos_floored.x
@ -82,7 +82,7 @@ func _process(delta : float) -> void:
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
# Release Drag
is_dragging = false
if move_pixels:
for i in range(orig_colors.size()):
@ -101,32 +101,42 @@ func _process(delta : float) -> 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
Global.canvas.handle_redo("Rectangle Select") # Redo
# Makes line2d visible
if is_instance_valid(Global.canvas.line_2d): # Checks to see if line_2d object still exists
if is_instance_valid(Global.canvas.line_2d): # Checks to see if line_2d object still exists
Global.canvas.line_2d.default_color = Color.darkgray
#Handle copy
if Input.is_action_just_pressed("copy") && Global.selected_pixels.size() > 0:
#Save as custom brush
var brush_img := Image.new()
brush_img = layer.get_rect(Rect2(polygon[0], polygon[2] - polygon[0]))
if brush_img.is_invisible():
return
brush_img = brush_img.get_rect(brush_img.get_used_rect()) #save only the visible pixels
Global.custom_brushes.append(brush_img)
Global.create_brush_button(brush_img)
if Global.selected_pixels.size() > 0:
# Handle copy
if Input.is_action_just_pressed("copy"):
# Save as custom brush
var brush_img := Image.new()
brush_img = layer.get_rect(Rect2(polygon[0], polygon[2] - polygon[0]))
if brush_img.is_invisible():
return
brush_img = brush_img.get_rect(brush_img.get_used_rect()) #save only the visible pixels
Global.custom_brushes.append(brush_img)
Global.create_brush_button(brush_img)
# Have it in the clipboard so it can be pasted later
Global.image_clipboard = layer.get_rect(Rect2(polygon[0], polygon[2] - polygon[0]))
# Handle paste
if Input.is_action_just_pressed("paste") && 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.handle_redo("Draw")
if Input.is_action_just_pressed("delete"):
Global.canvas.handle_undo("Draw")
for xx in range(start_pos.x, end_pos.x):
for yy in range(start_pos.y, end_pos.y):
layer.set_pixel(xx, yy, Color(0, 0, 0, 0))
Global.canvas.handle_redo("Draw")
#Have it in the clipboard so it can be pasted later
Global.image_clipboard = layer.get_rect(Rect2(polygon[0], polygon[2] - polygon[0]))
#Handle paste
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.handle_redo("Draw")
func _draw() -> void:
if img.get_size() == polygon[2] - polygon[0]:

View file

@ -209,6 +209,11 @@ redo_secondary={
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":true,"control":true,"meta":false,"command":true,"pressed":false,"scancode":90,"unicode":0,"echo":false,"script":null)
]
}
delete={
"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":16777224,"unicode":0,"echo":false,"script":null)
]
}
[locale]