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

Merge pull request #43 from SbNanduri/line-tool

Changed line tool so it activates by pressing shift after last draw
This commit is contained in:
Overloaded 2019-12-15 13:33:48 +02:00 committed by GitHub
commit d6acda8e87
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 26 deletions

View file

@ -246,13 +246,22 @@ func _process(delta : float) -> void:
Global.right_color_picker.color = pixel_color
Global.update_right_custom_brush()
if !is_making_line:
previous_mouse_pos = mouse_pos
previous_mouse_pos.x = clamp(previous_mouse_pos.x, location.x, location.x + size.x)
previous_mouse_pos.y = clamp(previous_mouse_pos.y, location.y, location.y + size.y)
else:
if Input.is_action_just_pressed("shift") and (["Pencil", "Eraser"].has(Global.current_left_tool) or ["Pencil", "Eraser"].has(Global.current_right_tool)):
line_2d = Line2D.new()
line_2d.width = 0.5
line_2d.default_color = Color.darkgray
line_2d.add_point(previous_mouse_pos)
line_2d.add_point(mouse_pos)
add_child(line_2d)
is_making_line = true
elif Input.is_action_just_released("shift"):
is_making_line = false
line_2d.queue_free()
if is_making_line:
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]
@ -457,20 +466,8 @@ func generate_layer_panels() -> void:
Global.vbox_layer_container.add_child(layer_container)
func pencil_and_eraser(mouse_pos : Vector2, color : Color, current_mouse_button : String, current_action := "None") -> void:
if Input.is_key_pressed(KEY_SHIFT):
if !is_making_line:
line_2d = Line2D.new()
line_2d.width = 0.5
line_2d.default_color = Color.darkgray
line_2d.add_point(previous_mouse_pos)
line_2d.add_point(mouse_pos)
add_child(line_2d)
is_making_line = true
else:
if is_making_line:
fill_gaps(mouse_pos, color, current_mouse_button, current_action)
is_making_line = false
line_2d.queue_free()
else:
if point_in_rectangle(mouse_pos, location, location + size):
mouse_inside_canvas = true
@ -652,6 +649,12 @@ func draw_pixel(pos : Vector2, color : Color, current_mouse_button : String, cur
layers[current_layer_index][0].lock()
sprite_changed_this_frame = true
previous_mouse_pos = current_pixel
previous_mouse_pos.x = clamp(previous_mouse_pos.x, location.x, location.x + size.x)
previous_mouse_pos.y = clamp(previous_mouse_pos.y, location.y, location.y + size.y)
if is_making_line:
line_2d.set_point_position(0, previous_mouse_pos)
#Bresenham's Algorithm
#Thanks to https://godotengine.org/qa/35276/tile-based-line-drawing-algorithm-efficiency
func fill_gaps(mouse_pos : Vector2, color : Color, current_mouse_button : String, current_action := "None") -> void:

View file

@ -61,6 +61,10 @@ func _process(delta : float) -> void:
Global.canvas.update_texture(Global.canvas.current_layer_index)
tex.create_from_image(img, 0)
update()
# Makes line2d invisible
if weakref(Global.canvas.line_2d).get_ref(): # 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
@ -99,6 +103,10 @@ func _process(delta : float) -> void:
Global.canvas.handle_redo("Rectangle Select") #Redo
# Makes line2d visible
if weakref(Global.canvas.line_2d).get_ref(): # 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