From bac3fdcad695999f8c8aa1fae6fa3abfd1ff325d Mon Sep 17 00:00:00 2001 From: OverloadedOrama <35376950+OverloadedOrama@users.noreply.github.com> Date: Wed, 15 Jan 2020 22:31:02 +0200 Subject: [PATCH] Canvas Line2D doesn't get freed and re-created Make Line2D have the same position for both of its points so it's invisible when the user is not making a straight line --- Scripts/Canvas.gd | 21 ++++++++++----------- Scripts/SelectionRectangle.gd | 6 ++---- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/Scripts/Canvas.gd b/Scripts/Canvas.gd index 37fa9c0aa..93b59dbdd 100644 --- a/Scripts/Canvas.gd +++ b/Scripts/Canvas.gd @@ -69,6 +69,13 @@ func _ready() -> void: if Global.canvases[0] == self: camera_zoom() + line_2d = Line2D.new() + line_2d.width = 0.5 + line_2d.default_color = Color.darkgray + line_2d.add_point(previous_mouse_pos_for_lines) + line_2d.add_point(previous_mouse_pos_for_lines) + add_child(line_2d) + func camera_zoom() -> void: # Set camera zoom based on the sprite size var bigger = max(size.x, size.y) @@ -278,21 +285,13 @@ func _input(event : InputEvent) -> void: Global.update_right_custom_brush() if Global.can_draw && Global.has_focus && Input.is_action_just_pressed("shift") && (["Pencil", "Eraser", "LightenDarken"].has(Global.current_left_tool) || ["Pencil", "Eraser", "LightenDarken"].has(Global.current_right_tool)): - if is_instance_valid(line_2d): - line_2d.queue_free() - line_2d = Line2D.new() - line_2d.width = 0.5 - line_2d.default_color = Color.darkgray - line_2d.add_point(previous_mouse_pos_for_lines) - line_2d.add_point(mouse_pos) - add_child(line_2d) is_making_line = true + line_2d.set_point_position(0, previous_mouse_pos_for_lines) elif Input.is_action_just_released("shift"): is_making_line = false - if is_instance_valid(line_2d): - line_2d.queue_free() + line_2d.set_point_position(1, line_2d.points[0]) - if is_making_line && is_instance_valid(line_2d): + if is_making_line: var point0 : Vector2 = line_2d.points[0] var angle := stepify(rad2deg(mouse_pos.angle_to_point(point0)), 0.01) if Input.is_action_pressed("ctrl"): diff --git a/Scripts/SelectionRectangle.gd b/Scripts/SelectionRectangle.gd index 63dff97cf..ae9cf4d61 100644 --- a/Scripts/SelectionRectangle.gd +++ b/Scripts/SelectionRectangle.gd @@ -63,8 +63,7 @@ func _process(delta : float) -> void: update() # Makes line2d invisible - 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) + Global.canvas.line_2d.default_color = Color(0, 0, 0, 0) else: get_parent().get_parent().mouse_default_cursor_shape = Input.CURSOR_ARROW @@ -104,8 +103,7 @@ func _process(delta : float) -> void: 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 - Global.canvas.line_2d.default_color = Color.darkgray + Global.canvas.line_2d.default_color = Color.darkgray if Global.selected_pixels.size() > 0: # Handle copy