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

Optimize the previews of the lasso, paint and polygon select tools

Continuation from the previous commit
This commit is contained in:
Emmanouil Papadeas 2024-07-31 18:19:10 +03:00
parent 9c7effdba3
commit 7063af098f
3 changed files with 98 additions and 96 deletions

View file

@ -33,43 +33,44 @@ func draw_end(pos: Vector2i) -> void:
func draw_preview() -> void: func draw_preview() -> void:
var canvas := Global.canvas.previews_sprite
if _last_position != Vector2.INF and !_move: if _last_position != Vector2.INF and !_move:
var canvas: Node2D = Global.canvas.previews var image := Image.create(
var pos := canvas.position Global.current_project.size.x, Global.current_project.size.y, false, Image.FORMAT_LA8
var canvas_scale := canvas.scale )
if Global.mirror_view: for point in _draw_points:
pos.x = pos.x + Global.current_project.size.x var draw_point := point
canvas_scale.x = -1 if Global.mirror_view: # This fixes previewing in mirror mode
canvas.draw_set_transform(pos, canvas.rotation, canvas_scale) draw_point.x = image.get_width() - draw_point.x - 1
var indicator := _fill_bitmap_with_points(_draw_points, Global.current_project.size) if Rect2i(Vector2i.ZERO, image.get_size()).has_point(draw_point):
image.set_pixelv(draw_point, Color.WHITE)
for line in _create_polylines(indicator):
canvas.draw_polyline(PackedVector2Array(line), Color.BLACK)
# Handle mirroring # Handle mirroring
if Tools.horizontal_mirror: if Tools.horizontal_mirror:
for line in _create_polylines( for point in mirror_array(_draw_points, true, false):
_fill_bitmap_with_points( var draw_point := point
mirror_array(_draw_points, true, false), Global.current_project.size if Global.mirror_view: # This fixes previewing in mirror mode
) draw_point.x = image.get_width() - draw_point.x - 1
): if Rect2i(Vector2i.ZERO, image.get_size()).has_point(draw_point):
canvas.draw_polyline(PackedVector2Array(line), Color.BLACK) image.set_pixelv(draw_point, Color.WHITE)
if Tools.vertical_mirror: if Tools.vertical_mirror:
for line in _create_polylines( for point in mirror_array(_draw_points, true, true):
_fill_bitmap_with_points( var draw_point := point
mirror_array(_draw_points, true, true), Global.current_project.size if Global.mirror_view: # This fixes previewing in mirror mode
) draw_point.x = image.get_width() - draw_point.x - 1
): if Rect2i(Vector2i.ZERO, image.get_size()).has_point(draw_point):
canvas.draw_polyline(PackedVector2Array(line), Color.BLACK) image.set_pixelv(draw_point, Color.WHITE)
if Tools.vertical_mirror: if Tools.vertical_mirror:
for line in _create_polylines( for point in mirror_array(_draw_points, false, true):
_fill_bitmap_with_points( var draw_point := point
mirror_array(_draw_points, false, true), Global.current_project.size if Global.mirror_view: # This fixes previewing in mirror mode
) draw_point.x = image.get_width() - draw_point.x - 1
): if Rect2i(Vector2i.ZERO, image.get_size()).has_point(draw_point):
canvas.draw_polyline(PackedVector2Array(line), Color.BLACK) image.set_pixelv(draw_point, Color.WHITE)
var texture := ImageTexture.create_from_image(image)
canvas.draw_set_transform(canvas.position, canvas.rotation, canvas.scale) canvas.texture = texture
else:
canvas.texture = null
func apply_selection(_position) -> void: func apply_selection(_position) -> void:

View file

@ -61,43 +61,44 @@ func draw_end(pos: Vector2i) -> void:
func draw_preview() -> void: func draw_preview() -> void:
var canvas := Global.canvas.previews_sprite
if _last_position != Vector2.INF and !_move: if _last_position != Vector2.INF and !_move:
var canvas: Node2D = Global.canvas.previews var image := Image.create(
var pos := canvas.position Global.current_project.size.x, Global.current_project.size.y, false, Image.FORMAT_LA8
var canvas_scale := canvas.scale )
if Global.mirror_view: for point in _draw_points:
pos.x = pos.x + Global.current_project.size.x var draw_point := point
canvas_scale.x = -1 if Global.mirror_view: # This fixes previewing in mirror mode
canvas.draw_set_transform(pos, canvas.rotation, canvas_scale) draw_point.x = image.get_width() - draw_point.x - 1
var indicator := _fill_bitmap_with_points(_draw_points, Global.current_project.size) if Rect2i(Vector2i.ZERO, image.get_size()).has_point(draw_point):
image.set_pixelv(draw_point, Color.WHITE)
for line in _create_polylines(indicator):
canvas.draw_polyline(PackedVector2Array(line), Color.BLACK)
# Handle mirroring # Handle mirroring
if Tools.horizontal_mirror: if Tools.horizontal_mirror:
for line in _create_polylines( for point in mirror_array(_draw_points, true, false):
_fill_bitmap_with_points( var draw_point := point
mirror_array(_draw_points, true, false), Global.current_project.size if Global.mirror_view: # This fixes previewing in mirror mode
) draw_point.x = image.get_width() - draw_point.x - 1
): if Rect2i(Vector2i.ZERO, image.get_size()).has_point(draw_point):
canvas.draw_polyline(PackedVector2Array(line), Color.BLACK) image.set_pixelv(draw_point, Color.WHITE)
if Tools.vertical_mirror: if Tools.vertical_mirror:
for line in _create_polylines( for point in mirror_array(_draw_points, true, true):
_fill_bitmap_with_points( var draw_point := point
mirror_array(_draw_points, true, true), Global.current_project.size if Global.mirror_view: # This fixes previewing in mirror mode
) draw_point.x = image.get_width() - draw_point.x - 1
): if Rect2i(Vector2i.ZERO, image.get_size()).has_point(draw_point):
canvas.draw_polyline(PackedVector2Array(line), Color.BLACK) image.set_pixelv(draw_point, Color.WHITE)
if Tools.vertical_mirror: if Tools.vertical_mirror:
for line in _create_polylines( for point in mirror_array(_draw_points, false, true):
_fill_bitmap_with_points( var draw_point := point
mirror_array(_draw_points, false, true), Global.current_project.size if Global.mirror_view: # This fixes previewing in mirror mode
) draw_point.x = image.get_width() - draw_point.x - 1
): if Rect2i(Vector2i.ZERO, image.get_size()).has_point(draw_point):
canvas.draw_polyline(PackedVector2Array(line), Color.BLACK) image.set_pixelv(draw_point, Color.WHITE)
var texture := ImageTexture.create_from_image(image)
canvas.draw_set_transform(canvas.position, canvas.rotation, canvas.scale) canvas.texture = texture
else:
canvas.texture = null
func apply_selection(pos: Vector2i) -> void: func apply_selection(pos: Vector2i) -> void:

View file

@ -59,53 +59,53 @@ func draw_end(pos: Vector2i) -> void:
func draw_preview() -> void: func draw_preview() -> void:
var previews := Global.canvas.previews_sprite
if _ongoing_selection and !_move: if _ongoing_selection and !_move:
var canvas: Node2D = Global.canvas.previews var preview_draw_points := _draw_points.duplicate() as Array[Vector2i]
var pos := canvas.position
var canvas_scale := canvas.scale
if Global.mirror_view:
pos.x = pos.x + Global.current_project.size.x
canvas_scale.x = -1
var preview_draw_points := _draw_points.duplicate()
append_gap(_draw_points[-1], _last_position, preview_draw_points) append_gap(_draw_points[-1], _last_position, preview_draw_points)
var image := Image.create(
canvas.draw_set_transform(pos, canvas.rotation, canvas_scale) Global.current_project.size.x, Global.current_project.size.y, false, Image.FORMAT_LA8
var indicator := _fill_bitmap_with_points(preview_draw_points, Global.current_project.size) )
for point in preview_draw_points:
for line in _create_polylines(indicator): var draw_point := point
canvas.draw_polyline(PackedVector2Array(line), Color.BLACK) if Global.mirror_view: # This fixes previewing in mirror mode
draw_point.x = image.get_width() - draw_point.x - 1
if Rect2i(Vector2i.ZERO, image.get_size()).has_point(draw_point):
image.set_pixelv(draw_point, Color.WHITE)
var circle_radius := Vector2.ONE * (10.0 / Global.camera.zoom.x) var circle_radius := Vector2.ONE * (10.0 / Global.camera.zoom.x)
if _last_position == _draw_points[0] and _draw_points.size() > 1: if _last_position == _draw_points[0] and _draw_points.size() > 1:
var canvas := Global.canvas.previews
draw_empty_circle( draw_empty_circle(
canvas, Vector2(_draw_points[0]) + Vector2.ONE * 0.5, circle_radius, Color.BLACK canvas, Vector2(_draw_points[0]) + Vector2.ONE * 0.5, circle_radius, Color.BLACK
) )
# Handle mirroring # Handle mirroring
if Tools.horizontal_mirror: if Tools.horizontal_mirror:
for line in _create_polylines( for point in mirror_array(preview_draw_points, true, false):
_fill_bitmap_with_points( var draw_point := point
mirror_array(preview_draw_points, true, false), Global.current_project.size if Global.mirror_view: # This fixes previewing in mirror mode
) draw_point.x = image.get_width() - draw_point.x - 1
): if Rect2i(Vector2i.ZERO, image.get_size()).has_point(draw_point):
canvas.draw_polyline(PackedVector2Array(line), Color.BLACK) image.set_pixelv(draw_point, Color.WHITE)
if Tools.vertical_mirror: if Tools.vertical_mirror:
for line in _create_polylines( for point in mirror_array(preview_draw_points, true, true):
_fill_bitmap_with_points( var draw_point := point
mirror_array(preview_draw_points, true, true), Global.current_project.size if Global.mirror_view: # This fixes previewing in mirror mode
) draw_point.x = image.get_width() - draw_point.x - 1
): if Rect2i(Vector2i.ZERO, image.get_size()).has_point(draw_point):
canvas.draw_polyline(PackedVector2Array(line), Color.BLACK) image.set_pixelv(draw_point, Color.WHITE)
if Tools.vertical_mirror: if Tools.vertical_mirror:
for line in _create_polylines( for point in mirror_array(preview_draw_points, false, true):
_fill_bitmap_with_points( var draw_point := point
mirror_array(preview_draw_points, false, true), Global.current_project.size if Global.mirror_view: # This fixes previewing in mirror mode
) draw_point.x = image.get_width() - draw_point.x - 1
): if Rect2i(Vector2i.ZERO, image.get_size()).has_point(draw_point):
canvas.draw_polyline(PackedVector2Array(line), Color.BLACK) image.set_pixelv(draw_point, Color.WHITE)
var texture := ImageTexture.create_from_image(image)
canvas.draw_set_transform(canvas.position, canvas.rotation, canvas.scale) previews.texture = texture
else:
previews.texture = null
func apply_selection(pos: Vector2i) -> void: func apply_selection(pos: Vector2i) -> void: