From 6c2b7f70679e99ff73aa21e7232482ea8f78da8f Mon Sep 17 00:00:00 2001 From: OverloadedOrama <35376950+OverloadedOrama@users.noreply.github.com> Date: Mon, 20 Jul 2020 22:29:58 +0300 Subject: [PATCH] Improved performance for drawing after the selected_pixels change It should be as fast as before, if there's not a big selection. --- src/Classes/Drawers.gd | 24 ++++++++++++++++-------- src/Tools/Draw.gd | 37 ++++++++++++++++++++++++++----------- 2 files changed, 42 insertions(+), 19 deletions(-) diff --git a/src/Classes/Drawers.gd b/src/Classes/Drawers.gd index a89a4ea2e..951a428c0 100644 --- a/src/Classes/Drawers.gd +++ b/src/Classes/Drawers.gd @@ -68,19 +68,27 @@ func set_pixel_perfect(value: bool) -> void: func set_pixel(image: Image, position: Vector2, color: Color) -> void: var project : Project = Global.current_project + drawers[0].set_pixel(image, position, color, color_op) + # Handle Mirroring var mirror_x = project.x_symmetry_point - position.x var mirror_y = project.y_symmetry_point - position.y - var selected_pixels_x := [] - var selected_pixels_y := [] - for i in project.selected_pixels: - selected_pixels_x.append(i.x) - selected_pixels_y.append(i.y) + var mirror_x_inside : bool + var mirror_y_inside : bool + var entire_image_selected : bool = project.selected_pixels.size() == project.size.x * project.size.y + if entire_image_selected: + mirror_x_inside = mirror_x >= 0 and mirror_x < project.size.x + mirror_y_inside = mirror_y >= 0 and mirror_y < project.size.y + else: + var selected_pixels_x := [] + var selected_pixels_y := [] + for i in project.selected_pixels: + selected_pixels_x.append(i.x) + selected_pixels_y.append(i.y) - var mirror_x_inside : bool = mirror_x in selected_pixels_x - var mirror_y_inside : bool = mirror_y in selected_pixels_y + mirror_x_inside = mirror_x in selected_pixels_x + mirror_y_inside = mirror_y in selected_pixels_y - drawers[0].set_pixel(image, position, color, color_op) if horizontal_mirror and mirror_x_inside: drawers[1].set_pixel(image, Vector2(mirror_x, position.y), color, color_op) if vertical_mirror and mirror_y_inside: diff --git a/src/Tools/Draw.gd b/src/Tools/Draw.gd index 7749e4cae..b11e15f56 100644 --- a/src/Tools/Draw.gd +++ b/src/Tools/Draw.gd @@ -269,18 +269,27 @@ func draw_tool_brush(position : Vector2) -> void: dst = dst_rect.position var project : Project = Global.current_project + _draw_brush_image(_brush_image, src_rect, dst) + + # Handle Mirroring var mirror_x = (project.x_symmetry_point + 1) - dst.x - src_rect.size.x var mirror_y = (project.y_symmetry_point + 1) - dst.y - src_rect.size.y - var selected_pixels_x := [] - var selected_pixels_y := [] - for i in project.selected_pixels: - selected_pixels_x.append(i.x) - selected_pixels_y.append(i.y) + var mirror_x_inside : bool + var mirror_y_inside : bool + var entire_image_selected : bool = project.selected_pixels.size() == project.size.x * project.size.y + if entire_image_selected: + mirror_x_inside = mirror_x >= 0 and mirror_x < project.size.x + mirror_y_inside = mirror_y >= 0 and mirror_y < project.size.y + else: + var selected_pixels_x := [] + var selected_pixels_y := [] + for i in project.selected_pixels: + selected_pixels_x.append(i.x) + selected_pixels_y.append(i.y) - var mirror_x_inside : bool = mirror_x in selected_pixels_x - var mirror_y_inside : bool = mirror_y in selected_pixels_y + mirror_x_inside = mirror_x in selected_pixels_x + mirror_y_inside = mirror_y in selected_pixels_y - _draw_brush_image(_brush_image, src_rect, dst) if tool_slot.horizontal_mirror and mirror_x_inside: _draw_brush_image(_mirror_brushes.x, _flip_rect(src_rect, size, true, false), Vector2(mirror_x, dst.y)) if tool_slot.vertical_mirror and mirror_y_inside: @@ -319,11 +328,17 @@ func draw_indicator_at(position : Vector2, offset : Vector2, color : Color) -> v func _set_pixel(position : Vector2) -> void: + var project : Project = Global.current_project if Global.tile_mode and _get_tile_mode_rect().has_point(position): - position = position.posmodv(Global.current_project.size) + position = position.posmodv(project.size) - if not position in Global.current_project.selected_pixels: - return + var entire_image_selected : bool = project.selected_pixels.size() == project.size.x * project.size.y + if entire_image_selected: + if not _get_draw_rect().has_point(position): + return + else: + if not position in project.selected_pixels: + return var image := _get_draw_image() var i := int(position.x + position.y * image.get_size().x)