mirror of
https://github.com/tonytins/CozyPixelStudio.git
synced 2025-08-11 22:14:42 -04:00
Replaced the _min and _max Project variables with Project.selected_pixels
This will allow us to create more selection tools in the future, that aren't necessarily rectangular (See #129) and even enhance the current rectangle selection tool (See #56) Current issues spotted so far: Drawing is slower for large images, and bucket filling is also considerably slower even on a 64x64 image. Optimizations are required.
This commit is contained in:
parent
8c965c1858
commit
0f82be765e
10 changed files with 108 additions and 80 deletions
|
@ -77,11 +77,8 @@ func draw_indicator() -> void:
|
|||
|
||||
|
||||
func _get_draw_rect() -> Rect2:
|
||||
var x_min : int = Global.current_project.x_min
|
||||
var x_max : int = Global.current_project.x_max
|
||||
var y_min : int = Global.current_project.y_min
|
||||
var y_max : int = Global.current_project.y_max
|
||||
return Rect2(x_min, y_min, x_max - x_min, y_max - y_min)
|
||||
var selected_pixels = Global.current_project.selected_pixels
|
||||
return Rect2(selected_pixels[0].x, selected_pixels[0].y, selected_pixels[-1].x - selected_pixels[0].x + 1, selected_pixels[-1].y - selected_pixels[0].y + 1)
|
||||
|
||||
|
||||
func _get_tile_mode_rect() -> Rect2:
|
||||
|
|
|
@ -94,7 +94,7 @@ func update_pattern() -> void:
|
|||
|
||||
|
||||
func draw_start(position : Vector2) -> void:
|
||||
if not _get_draw_rect().has_point(position):
|
||||
if not position in Global.current_project.selected_pixels:
|
||||
return
|
||||
var undo_data = _get_undo_data()
|
||||
if _fill_area == 0:
|
||||
|
@ -121,18 +121,23 @@ func fill_in_color(position : Vector2) -> void:
|
|||
return
|
||||
|
||||
image.lock()
|
||||
for y in range(project.y_min, project.y_max):
|
||||
for x in range(project.x_min, project.x_max):
|
||||
if image.get_pixel(x, y).is_equal_approx(color):
|
||||
_set_pixel(image, x, y, tool_slot.color)
|
||||
for i in project.selected_pixels:
|
||||
if image.get_pixelv(i).is_equal_approx(color):
|
||||
_set_pixel(image, i.x, i.y, tool_slot.color)
|
||||
|
||||
|
||||
func fill_in_area(position : Vector2) -> void:
|
||||
var project : Project = Global.current_project
|
||||
var mirror_x = project.x_symmetry_point - position.x
|
||||
var mirror_y = project.y_symmetry_point - position.y
|
||||
var mirror_x_inside : bool = mirror_x >= project.x_min and mirror_x <= project.x_max - 1
|
||||
var mirror_y_inside : bool = mirror_y >= project.y_min and mirror_y <= project.y_max - 1
|
||||
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
|
||||
|
||||
_flood_fill(position)
|
||||
if tool_slot.horizontal_mirror and mirror_x_inside:
|
||||
|
@ -160,9 +165,9 @@ func _flood_fill(position : Vector2) -> void:
|
|||
continue
|
||||
var west : Vector2 = n
|
||||
var east : Vector2 = n
|
||||
while west.x >= project.x_min && image.get_pixelv(west).is_equal_approx(color):
|
||||
while west in project.selected_pixels && image.get_pixelv(west).is_equal_approx(color):
|
||||
west += Vector2.LEFT
|
||||
while east.x < project.x_max && image.get_pixelv(east).is_equal_approx(color):
|
||||
while east in project.selected_pixels && image.get_pixelv(east).is_equal_approx(color):
|
||||
east += Vector2.RIGHT
|
||||
for px in range(west.x + 1, east.x):
|
||||
var p := Vector2(px, n.y)
|
||||
|
@ -170,9 +175,9 @@ func _flood_fill(position : Vector2) -> void:
|
|||
processed.set_bit(p, true)
|
||||
var north := p + Vector2.UP
|
||||
var south := p + Vector2.DOWN
|
||||
if north.y >= project.y_min && image.get_pixelv(north).is_equal_approx(color):
|
||||
if north in project.selected_pixels && image.get_pixelv(north).is_equal_approx(color):
|
||||
q.append(north)
|
||||
if south.y < project.y_max && image.get_pixelv(south).is_equal_approx(color):
|
||||
if south in project.selected_pixels && image.get_pixelv(south).is_equal_approx(color):
|
||||
q.append(south)
|
||||
|
||||
|
||||
|
|
|
@ -271,8 +271,14 @@ func draw_tool_brush(position : Vector2) -> void:
|
|||
var project : Project = Global.current_project
|
||||
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_x_inside : bool = mirror_x >= project.x_min and mirror_x <= project.x_max - 1
|
||||
var mirror_y_inside : bool = mirror_y >= project.y_min and mirror_y <= project.y_max - 1
|
||||
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
|
||||
|
||||
_draw_brush_image(_brush_image, src_rect, dst)
|
||||
if tool_slot.horizontal_mirror and mirror_x_inside:
|
||||
|
@ -287,7 +293,7 @@ func draw_indicator() -> void:
|
|||
draw_indicator_at(_cursor, Vector2.ZERO, Color.blue)
|
||||
if Global.tile_mode and _get_tile_mode_rect().has_point(_cursor):
|
||||
var tile := _line_start if _draw_line else _cursor
|
||||
if not _get_draw_rect().has_point(tile):
|
||||
if not tile in Global.current_project.selected_pixels:
|
||||
var offset := tile - tile.posmodv(Global.current_project.size)
|
||||
draw_indicator_at(_cursor, offset, Color.green)
|
||||
|
||||
|
@ -316,7 +322,7 @@ func _set_pixel(position : Vector2) -> void:
|
|||
if Global.tile_mode and _get_tile_mode_rect().has_point(position):
|
||||
position = position.posmodv(Global.current_project.size)
|
||||
|
||||
if not _get_draw_rect().has_point(position):
|
||||
if not position in Global.current_project.selected_pixels:
|
||||
return
|
||||
|
||||
var image := _get_draw_image()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue