1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-31 07:29:49 +00:00

Improved performance for drawing after the selected_pixels change

It should be as fast as before, if there's not a big selection.
This commit is contained in:
OverloadedOrama 2020-07-20 22:29:58 +03:00
parent 0f82be765e
commit 6c2b7f7067
2 changed files with 42 additions and 19 deletions

View file

@ -68,19 +68,27 @@ func set_pixel_perfect(value: bool) -> void:
func set_pixel(image: Image, position: Vector2, color: Color) -> void: func set_pixel(image: Image, position: Vector2, color: Color) -> void:
var project : Project = Global.current_project 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_x = project.x_symmetry_point - position.x
var mirror_y = project.y_symmetry_point - position.y var mirror_y = project.y_symmetry_point - position.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_x := []
var selected_pixels_y := [] var selected_pixels_y := []
for i in project.selected_pixels: for i in project.selected_pixels:
selected_pixels_x.append(i.x) selected_pixels_x.append(i.x)
selected_pixels_y.append(i.y) selected_pixels_y.append(i.y)
var mirror_x_inside : bool = mirror_x in selected_pixels_x mirror_x_inside = mirror_x in selected_pixels_x
var mirror_y_inside : bool = mirror_y in selected_pixels_y 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: if horizontal_mirror and mirror_x_inside:
drawers[1].set_pixel(image, Vector2(mirror_x, position.y), color, color_op) drawers[1].set_pixel(image, Vector2(mirror_x, position.y), color, color_op)
if vertical_mirror and mirror_y_inside: if vertical_mirror and mirror_y_inside:

View file

@ -269,18 +269,27 @@ func draw_tool_brush(position : Vector2) -> void:
dst = dst_rect.position dst = dst_rect.position
var project : Project = Global.current_project 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_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 mirror_y = (project.y_symmetry_point + 1) - dst.y - src_rect.size.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_x := []
var selected_pixels_y := [] var selected_pixels_y := []
for i in project.selected_pixels: for i in project.selected_pixels:
selected_pixels_x.append(i.x) selected_pixels_x.append(i.x)
selected_pixels_y.append(i.y) selected_pixels_y.append(i.y)
var mirror_x_inside : bool = mirror_x in selected_pixels_x mirror_x_inside = mirror_x in selected_pixels_x
var mirror_y_inside : bool = mirror_y in selected_pixels_y 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: 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)) _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: if tool_slot.vertical_mirror and mirror_y_inside:
@ -319,10 +328,16 @@ func draw_indicator_at(position : Vector2, offset : Vector2, color : Color) -> v
func _set_pixel(position : Vector2) -> void: func _set_pixel(position : Vector2) -> void:
var project : Project = Global.current_project
if Global.tile_mode and _get_tile_mode_rect().has_point(position): 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: 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 return
var image := _get_draw_image() var image := _get_draw_image()