From bb63d1031066f55982fa32a588837fc29015db5d Mon Sep 17 00:00:00 2001 From: NIyue <100502009+NIyueeE@users.noreply.github.com> Date: Thu, 21 Nov 2024 19:08:25 +0800 Subject: [PATCH 1/7] Add files via upload --- SelectionMap.gd | 259 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 259 insertions(+) create mode 100644 SelectionMap.gd diff --git a/SelectionMap.gd b/SelectionMap.gd new file mode 100644 index 000000000..fd924a82e --- /dev/null +++ b/SelectionMap.gd @@ -0,0 +1,259 @@ +class_name SelectionMap +extends Image + +const INVERT_SHADER := preload("res://src/Shaders/Effects/Invert.gdshader") +const OUTLINE_INLINE_SHADER := preload("res://src/Shaders/Effects/OutlineInline.gdshader") + + +func is_pixel_selected(pixel: Vector2i, calculate_offset := true) -> bool: + var selection_position: Vector2i = Global.canvas.selection.big_bounding_rectangle.position + if calculate_offset: + if selection_position.x < 0: + pixel.x -= selection_position.x + if selection_position.y < 0: + pixel.y -= selection_position.y + if pixel.x < 0 or pixel.y < 0 or pixel.x >= get_width() or pixel.y >= get_height(): + return false + var selected: bool = get_pixelv(pixel).a > 0 + return selected + + +func get_nearest_position(pixel: Vector2i) -> Vector2i: + if Global.canvas.selection.flag_tilemode: + # functions more or less the same way as the tilemode + var size := Global.current_project.size + var selection_rect := get_used_rect() + var start_x := selection_rect.position.x - selection_rect.size.x + var end_x := selection_rect.position.x + 2 * selection_rect.size.x + var start_y := selection_rect.position.y - selection_rect.size.y + var end_y := selection_rect.position.y + 2 * selection_rect.size.y + for x in range(start_x, end_x, selection_rect.size.x): + for y in range(start_y, end_y, selection_rect.size.y): + var test_image := Image.create(size.x, size.y, false, Image.FORMAT_LA8) + test_image.blit_rect(self, selection_rect, Vector2(x, y)) + if ( + pixel.x < 0 + or pixel.y < 0 + or pixel.x >= test_image.get_width() + or pixel.y >= test_image.get_height() + ): + continue + var selected: bool = test_image.get_pixelv(pixel).a > 0 + if selected: + var offset := Vector2i(x, y) - selection_rect.position + return offset + return Vector2i.ZERO + else: + return Vector2i.ZERO + + +func get_point_in_tile_mode(pixel: Vector2i) -> Array[Vector2i]: + var result: Array[Vector2i] = [] + if Global.canvas.selection.flag_tilemode: + var selection_rect := get_used_rect() + var start_x := selection_rect.position.x - selection_rect.size.x + var end_x := selection_rect.position.x + 2 * selection_rect.size.x + var start_y := selection_rect.position.y - selection_rect.size.y + var end_y := selection_rect.position.y + 2 * selection_rect.size.y + for x in range(start_x, end_x, selection_rect.size.x): + for y in range(start_y, end_y, selection_rect.size.y): + result.append(Vector2i(x, y) + pixel - selection_rect.position) + else: + result.append(pixel) + return result + + +func get_canon_position(position: Vector2i) -> Vector2i: + if Global.canvas.selection.flag_tilemode: + return position - get_nearest_position(position) + else: + return position + + +func select_pixel(pixel: Vector2i, select := true) -> void: + if select: + set_pixelv(pixel, Color(1, 1, 1, 1)) + else: + set_pixelv(pixel, Color(0)) + + +func select_all() -> void: + fill(Color(1, 1, 1, 1)) + + +func clear() -> void: + fill(Color(0)) + + +func invert() -> void: + var params := {"red": true, "green": true, "blue": true, "alpha": true} + var gen := ShaderImageEffect.new() + gen.generate_image(self, INVERT_SHADER, params, get_size()) + + +## Returns a copy of itself that is cropped to [param size]. +## Used for when the selection map is bigger than the [Project] size. +func return_cropped_copy(size: Vector2i) -> SelectionMap: + var selection_map_copy := SelectionMap.new() + selection_map_copy.copy_from(self) + var diff := Vector2i.ZERO + var selection_position: Vector2i = Global.canvas.selection.big_bounding_rectangle.position + if selection_position.x < 0: + diff.x += selection_position.x + if selection_position.y < 0: + diff.y += selection_position.y + if diff != Vector2i.ZERO: + # If there are pixels out of bounds on the negative side (left & up), + # move them before resizing + selection_map_copy.fill(Color(0)) + selection_map_copy.blit_rect(self, Rect2i(Vector2i.ZERO, get_size()), diff) + selection_map_copy.crop(size.x, size.y) + return selection_map_copy + + +func move_bitmap_values(project: Project, move_offset := true) -> void: + var size := project.size + var selection_node = Global.canvas.selection + var selection_position: Vector2i = selection_node.big_bounding_rectangle.position + var selection_end: Vector2i = selection_node.big_bounding_rectangle.end + + var selection_rect := get_used_rect() + var smaller_image := get_region(selection_rect) + clear() + var dst := selection_position + var x_diff := selection_end.x - size.x + var y_diff := selection_end.y - size.y + var nw := maxi(size.x, size.x + x_diff) + var nh := maxi(size.y, size.y + y_diff) + + if selection_position.x < 0: + nw -= selection_position.x + if move_offset: + project.selection_offset.x = selection_position.x + dst.x = 0 + else: + if move_offset: + project.selection_offset.x = 0 + if selection_position.y < 0: + nh -= selection_position.y + if move_offset: + project.selection_offset.y = selection_position.y + dst.y = 0 + else: + if move_offset: + project.selection_offset.y = 0 + + if nw <= size.x: + nw = size.x + if nh <= size.y: + nh = size.y + + crop(nw, nh) + blit_rect(smaller_image, Rect2i(Vector2i.ZERO, Vector2i(nw, nh)), dst) + + +func resize_bitmap_values( + project: Project, new_size: Vector2i, flip_hor: bool, flip_ver: bool +) -> void: + var size := project.size + var selection_node: Node2D = Global.canvas.selection + var selection_position: Vector2i = selection_node.big_bounding_rectangle.position + var dst := selection_position + var new_bitmap_size := size + new_bitmap_size.x = maxi(size.x, absi(selection_position.x) + new_size.x) + new_bitmap_size.y = maxi(size.y, absi(selection_position.y) + new_size.y) + var selection_rect := get_used_rect() + var smaller_image := get_region(selection_rect) + if selection_position.x <= 0: + project.selection_offset.x = selection_position.x + dst.x = 0 + else: + project.selection_offset.x = 0 + if selection_position.y <= 0: + project.selection_offset.y = selection_position.y + dst.y = 0 + else: + project.selection_offset.y = 0 + clear() + + var is_ellipse_select := true + var w := smaller_image.get_width() + var h := smaller_image.get_height() + var ellipse_select := DrawingAlgos.get_ellipse_points(Vector2.ZERO, Vector2i(w,h)) + var x_min := [] + var x_max := [] + x_min.resize(h) + x_max.resize(h) + # Determine x_min and x_max of y + for i in ellipse_select.size()/2: + i*=2 + var y := ellipse_select[i].y + var xmin := ellipse_select[i].x if ellipse_select[i].x < ellipse_select[i+1].x else ellipse_select[i+1].x + var xmax := ellipse_select[i].x if ellipse_select[i].x >= ellipse_select[i+1].x else ellipse_select[i+1].x + + if x_min[y] == null && x_max[y] == null: + x_min[y] = xmin + x_max[y] = xmax + else: + if x_min[y] != null && x_min[y] > xmin: + x_min[y] = xmin + if x_max[y] != null && x_max[y] < xmax: + x_max[y] = xmax + # Determine whether the selection is an ellipse selection + for y in range(h): + if !is_ellipse_select: + break + for x in range(w): + if smaller_image.get_pixel(x,y) == Color(1,1,1,1) && (x < x_min[y] || x > x_max[y]): + is_ellipse_select = false + break + # if selection is an ellipse selection, resized as standard ellipse + if !is_ellipse_select: + smaller_image.resize(new_size.x, new_size.y, Image.INTERPOLATE_BILINEAR) + else: + var resized_img := Image.create(new_size.x, new_size.y, false, smaller_image.get_format()) + var new_ellipse_select := DrawingAlgos.get_ellipse_points_filled(Vector2.ZERO, Vector2i(new_size.x,new_size.y)) + for p in new_ellipse_select: + resized_img.set_pixel(p.x, p.y, Color(1, 1, 1, 1)) + smaller_image = resized_img + + if flip_hor: + smaller_image.flip_x() + if flip_ver: + smaller_image.flip_y() + if new_bitmap_size != size: + crop(new_bitmap_size.x, new_bitmap_size.y) + blit_rect(smaller_image, Rect2i(Vector2i.ZERO, new_bitmap_size), dst) + + +func expand(width: int, brush: int) -> void: + var params := { + "color": Color(1, 1, 1, 1), + "width": width, + "brush": brush, + } + var gen := ShaderImageEffect.new() + gen.generate_image(self, OUTLINE_INLINE_SHADER, params, get_size()) + + +func shrink(width: int, brush: int) -> void: + var params := { + "color": Color(0), + "width": width, + "brush": brush, + "inside": true, + } + var gen := ShaderImageEffect.new() + gen.generate_image(self, OUTLINE_INLINE_SHADER, params, get_size()) + + +func border(width: int, brush: int) -> void: + var params := { + "color": Color(1, 1, 1, 1), + "width": width, + "brush": brush, + "inside": true, + "keep_border_only": true, + } + var gen := ShaderImageEffect.new() + gen.generate_image(self, OUTLINE_INLINE_SHADER, params, get_size()) From 9c3e84a41a9f9c5bec6f003faf375074d6cb33af Mon Sep 17 00:00:00 2001 From: NIyue <100502009+NIyueeE@users.noreply.github.com> Date: Thu, 21 Nov 2024 19:08:53 +0800 Subject: [PATCH 2/7] Delete SelectionMap.gd --- SelectionMap.gd | 259 ------------------------------------------------ 1 file changed, 259 deletions(-) delete mode 100644 SelectionMap.gd diff --git a/SelectionMap.gd b/SelectionMap.gd deleted file mode 100644 index fd924a82e..000000000 --- a/SelectionMap.gd +++ /dev/null @@ -1,259 +0,0 @@ -class_name SelectionMap -extends Image - -const INVERT_SHADER := preload("res://src/Shaders/Effects/Invert.gdshader") -const OUTLINE_INLINE_SHADER := preload("res://src/Shaders/Effects/OutlineInline.gdshader") - - -func is_pixel_selected(pixel: Vector2i, calculate_offset := true) -> bool: - var selection_position: Vector2i = Global.canvas.selection.big_bounding_rectangle.position - if calculate_offset: - if selection_position.x < 0: - pixel.x -= selection_position.x - if selection_position.y < 0: - pixel.y -= selection_position.y - if pixel.x < 0 or pixel.y < 0 or pixel.x >= get_width() or pixel.y >= get_height(): - return false - var selected: bool = get_pixelv(pixel).a > 0 - return selected - - -func get_nearest_position(pixel: Vector2i) -> Vector2i: - if Global.canvas.selection.flag_tilemode: - # functions more or less the same way as the tilemode - var size := Global.current_project.size - var selection_rect := get_used_rect() - var start_x := selection_rect.position.x - selection_rect.size.x - var end_x := selection_rect.position.x + 2 * selection_rect.size.x - var start_y := selection_rect.position.y - selection_rect.size.y - var end_y := selection_rect.position.y + 2 * selection_rect.size.y - for x in range(start_x, end_x, selection_rect.size.x): - for y in range(start_y, end_y, selection_rect.size.y): - var test_image := Image.create(size.x, size.y, false, Image.FORMAT_LA8) - test_image.blit_rect(self, selection_rect, Vector2(x, y)) - if ( - pixel.x < 0 - or pixel.y < 0 - or pixel.x >= test_image.get_width() - or pixel.y >= test_image.get_height() - ): - continue - var selected: bool = test_image.get_pixelv(pixel).a > 0 - if selected: - var offset := Vector2i(x, y) - selection_rect.position - return offset - return Vector2i.ZERO - else: - return Vector2i.ZERO - - -func get_point_in_tile_mode(pixel: Vector2i) -> Array[Vector2i]: - var result: Array[Vector2i] = [] - if Global.canvas.selection.flag_tilemode: - var selection_rect := get_used_rect() - var start_x := selection_rect.position.x - selection_rect.size.x - var end_x := selection_rect.position.x + 2 * selection_rect.size.x - var start_y := selection_rect.position.y - selection_rect.size.y - var end_y := selection_rect.position.y + 2 * selection_rect.size.y - for x in range(start_x, end_x, selection_rect.size.x): - for y in range(start_y, end_y, selection_rect.size.y): - result.append(Vector2i(x, y) + pixel - selection_rect.position) - else: - result.append(pixel) - return result - - -func get_canon_position(position: Vector2i) -> Vector2i: - if Global.canvas.selection.flag_tilemode: - return position - get_nearest_position(position) - else: - return position - - -func select_pixel(pixel: Vector2i, select := true) -> void: - if select: - set_pixelv(pixel, Color(1, 1, 1, 1)) - else: - set_pixelv(pixel, Color(0)) - - -func select_all() -> void: - fill(Color(1, 1, 1, 1)) - - -func clear() -> void: - fill(Color(0)) - - -func invert() -> void: - var params := {"red": true, "green": true, "blue": true, "alpha": true} - var gen := ShaderImageEffect.new() - gen.generate_image(self, INVERT_SHADER, params, get_size()) - - -## Returns a copy of itself that is cropped to [param size]. -## Used for when the selection map is bigger than the [Project] size. -func return_cropped_copy(size: Vector2i) -> SelectionMap: - var selection_map_copy := SelectionMap.new() - selection_map_copy.copy_from(self) - var diff := Vector2i.ZERO - var selection_position: Vector2i = Global.canvas.selection.big_bounding_rectangle.position - if selection_position.x < 0: - diff.x += selection_position.x - if selection_position.y < 0: - diff.y += selection_position.y - if diff != Vector2i.ZERO: - # If there are pixels out of bounds on the negative side (left & up), - # move them before resizing - selection_map_copy.fill(Color(0)) - selection_map_copy.blit_rect(self, Rect2i(Vector2i.ZERO, get_size()), diff) - selection_map_copy.crop(size.x, size.y) - return selection_map_copy - - -func move_bitmap_values(project: Project, move_offset := true) -> void: - var size := project.size - var selection_node = Global.canvas.selection - var selection_position: Vector2i = selection_node.big_bounding_rectangle.position - var selection_end: Vector2i = selection_node.big_bounding_rectangle.end - - var selection_rect := get_used_rect() - var smaller_image := get_region(selection_rect) - clear() - var dst := selection_position - var x_diff := selection_end.x - size.x - var y_diff := selection_end.y - size.y - var nw := maxi(size.x, size.x + x_diff) - var nh := maxi(size.y, size.y + y_diff) - - if selection_position.x < 0: - nw -= selection_position.x - if move_offset: - project.selection_offset.x = selection_position.x - dst.x = 0 - else: - if move_offset: - project.selection_offset.x = 0 - if selection_position.y < 0: - nh -= selection_position.y - if move_offset: - project.selection_offset.y = selection_position.y - dst.y = 0 - else: - if move_offset: - project.selection_offset.y = 0 - - if nw <= size.x: - nw = size.x - if nh <= size.y: - nh = size.y - - crop(nw, nh) - blit_rect(smaller_image, Rect2i(Vector2i.ZERO, Vector2i(nw, nh)), dst) - - -func resize_bitmap_values( - project: Project, new_size: Vector2i, flip_hor: bool, flip_ver: bool -) -> void: - var size := project.size - var selection_node: Node2D = Global.canvas.selection - var selection_position: Vector2i = selection_node.big_bounding_rectangle.position - var dst := selection_position - var new_bitmap_size := size - new_bitmap_size.x = maxi(size.x, absi(selection_position.x) + new_size.x) - new_bitmap_size.y = maxi(size.y, absi(selection_position.y) + new_size.y) - var selection_rect := get_used_rect() - var smaller_image := get_region(selection_rect) - if selection_position.x <= 0: - project.selection_offset.x = selection_position.x - dst.x = 0 - else: - project.selection_offset.x = 0 - if selection_position.y <= 0: - project.selection_offset.y = selection_position.y - dst.y = 0 - else: - project.selection_offset.y = 0 - clear() - - var is_ellipse_select := true - var w := smaller_image.get_width() - var h := smaller_image.get_height() - var ellipse_select := DrawingAlgos.get_ellipse_points(Vector2.ZERO, Vector2i(w,h)) - var x_min := [] - var x_max := [] - x_min.resize(h) - x_max.resize(h) - # Determine x_min and x_max of y - for i in ellipse_select.size()/2: - i*=2 - var y := ellipse_select[i].y - var xmin := ellipse_select[i].x if ellipse_select[i].x < ellipse_select[i+1].x else ellipse_select[i+1].x - var xmax := ellipse_select[i].x if ellipse_select[i].x >= ellipse_select[i+1].x else ellipse_select[i+1].x - - if x_min[y] == null && x_max[y] == null: - x_min[y] = xmin - x_max[y] = xmax - else: - if x_min[y] != null && x_min[y] > xmin: - x_min[y] = xmin - if x_max[y] != null && x_max[y] < xmax: - x_max[y] = xmax - # Determine whether the selection is an ellipse selection - for y in range(h): - if !is_ellipse_select: - break - for x in range(w): - if smaller_image.get_pixel(x,y) == Color(1,1,1,1) && (x < x_min[y] || x > x_max[y]): - is_ellipse_select = false - break - # if selection is an ellipse selection, resized as standard ellipse - if !is_ellipse_select: - smaller_image.resize(new_size.x, new_size.y, Image.INTERPOLATE_BILINEAR) - else: - var resized_img := Image.create(new_size.x, new_size.y, false, smaller_image.get_format()) - var new_ellipse_select := DrawingAlgos.get_ellipse_points_filled(Vector2.ZERO, Vector2i(new_size.x,new_size.y)) - for p in new_ellipse_select: - resized_img.set_pixel(p.x, p.y, Color(1, 1, 1, 1)) - smaller_image = resized_img - - if flip_hor: - smaller_image.flip_x() - if flip_ver: - smaller_image.flip_y() - if new_bitmap_size != size: - crop(new_bitmap_size.x, new_bitmap_size.y) - blit_rect(smaller_image, Rect2i(Vector2i.ZERO, new_bitmap_size), dst) - - -func expand(width: int, brush: int) -> void: - var params := { - "color": Color(1, 1, 1, 1), - "width": width, - "brush": brush, - } - var gen := ShaderImageEffect.new() - gen.generate_image(self, OUTLINE_INLINE_SHADER, params, get_size()) - - -func shrink(width: int, brush: int) -> void: - var params := { - "color": Color(0), - "width": width, - "brush": brush, - "inside": true, - } - var gen := ShaderImageEffect.new() - gen.generate_image(self, OUTLINE_INLINE_SHADER, params, get_size()) - - -func border(width: int, brush: int) -> void: - var params := { - "color": Color(1, 1, 1, 1), - "width": width, - "brush": brush, - "inside": true, - "keep_border_only": true, - } - var gen := ShaderImageEffect.new() - gen.generate_image(self, OUTLINE_INLINE_SHADER, params, get_size()) From 892e4fd4dcff1df829ef919f4e5572f3811b3a3e Mon Sep 17 00:00:00 2001 From: NIyue <100502009+NIyueeE@users.noreply.github.com> Date: Thu, 21 Nov 2024 19:10:57 +0800 Subject: [PATCH 3/7] Add files via upload --- src/Classes/SelectionMap.gd | 43 ++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/src/Classes/SelectionMap.gd b/src/Classes/SelectionMap.gd index abdc3329c..fd924a82e 100644 --- a/src/Classes/SelectionMap.gd +++ b/src/Classes/SelectionMap.gd @@ -175,7 +175,48 @@ func resize_bitmap_values( else: project.selection_offset.y = 0 clear() - smaller_image.resize(new_size.x, new_size.y, Image.INTERPOLATE_NEAREST) + + var is_ellipse_select := true + var w := smaller_image.get_width() + var h := smaller_image.get_height() + var ellipse_select := DrawingAlgos.get_ellipse_points(Vector2.ZERO, Vector2i(w,h)) + var x_min := [] + var x_max := [] + x_min.resize(h) + x_max.resize(h) + # Determine x_min and x_max of y + for i in ellipse_select.size()/2: + i*=2 + var y := ellipse_select[i].y + var xmin := ellipse_select[i].x if ellipse_select[i].x < ellipse_select[i+1].x else ellipse_select[i+1].x + var xmax := ellipse_select[i].x if ellipse_select[i].x >= ellipse_select[i+1].x else ellipse_select[i+1].x + + if x_min[y] == null && x_max[y] == null: + x_min[y] = xmin + x_max[y] = xmax + else: + if x_min[y] != null && x_min[y] > xmin: + x_min[y] = xmin + if x_max[y] != null && x_max[y] < xmax: + x_max[y] = xmax + # Determine whether the selection is an ellipse selection + for y in range(h): + if !is_ellipse_select: + break + for x in range(w): + if smaller_image.get_pixel(x,y) == Color(1,1,1,1) && (x < x_min[y] || x > x_max[y]): + is_ellipse_select = false + break + # if selection is an ellipse selection, resized as standard ellipse + if !is_ellipse_select: + smaller_image.resize(new_size.x, new_size.y, Image.INTERPOLATE_BILINEAR) + else: + var resized_img := Image.create(new_size.x, new_size.y, false, smaller_image.get_format()) + var new_ellipse_select := DrawingAlgos.get_ellipse_points_filled(Vector2.ZERO, Vector2i(new_size.x,new_size.y)) + for p in new_ellipse_select: + resized_img.set_pixel(p.x, p.y, Color(1, 1, 1, 1)) + smaller_image = resized_img + if flip_hor: smaller_image.flip_x() if flip_ver: From d081ae33dfb7dbe96860301f30b80203e4e6faf4 Mon Sep 17 00:00:00 2001 From: NIyue <100502009+NIyueeE@users.noreply.github.com> Date: Thu, 21 Nov 2024 19:11:55 +0800 Subject: [PATCH 4/7] Update DrawingAlgos.gd --- src/Autoload/DrawingAlgos.gd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Autoload/DrawingAlgos.gd b/src/Autoload/DrawingAlgos.gd index 6a668fea8..3b77da36b 100644 --- a/src/Autoload/DrawingAlgos.gd +++ b/src/Autoload/DrawingAlgos.gd @@ -127,7 +127,7 @@ func get_ellipse_points(pos: Vector2i, size: Vector2i) -> Array[Vector2i]: var y0 := pos.y var y1 := pos.y + (size.y - 1) var a := absi(x1 - x0) - var b := absi(y1 - x0) + var b := absi(y1 - y0) var b1 := b & 1 var dx := 4 * (1 - a) * b * b var dy := 4 * (b1 + 1) * a * a From ccf4d6ffd23ce19439b7477774ad5e274460c139 Mon Sep 17 00:00:00 2001 From: NIyue <100502009+NIyueeE@users.noreply.github.com> Date: Thu, 21 Nov 2024 19:39:14 +0800 Subject: [PATCH 5/7] Add files via upload --- src/Classes/SelectionMap.gd | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Classes/SelectionMap.gd b/src/Classes/SelectionMap.gd index fd924a82e..dbfc0fc05 100644 --- a/src/Classes/SelectionMap.gd +++ b/src/Classes/SelectionMap.gd @@ -199,6 +199,13 @@ func resize_bitmap_values( x_min[y] = xmin if x_max[y] != null && x_max[y] < xmax: x_max[y] = xmax + # too small to be rectangular selection + if x_min[0] == 0 && x_max[0] == w-1: + is_ellipse_select = false + # if ellipse is too small, ellipse_select doesn't quite cover the true elliptical selection + for y in range(h): + if x_min[y] == null: + is_ellipse_select = false # Determine whether the selection is an ellipse selection for y in range(h): if !is_ellipse_select: From 6c37c68acfcc40cedb8ff2f792501b1ca9119abc Mon Sep 17 00:00:00 2001 From: NIyue <100502009+NIyueeE@users.noreply.github.com> Date: Thu, 21 Nov 2024 21:57:06 +0800 Subject: [PATCH 6/7] Update SelectionMap.gd --- src/Classes/SelectionMap.gd | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/src/Classes/SelectionMap.gd b/src/Classes/SelectionMap.gd index dbfc0fc05..a09068308 100644 --- a/src/Classes/SelectionMap.gd +++ b/src/Classes/SelectionMap.gd @@ -175,22 +175,30 @@ func resize_bitmap_values( else: project.selection_offset.y = 0 clear() - + var is_ellipse_select := true var w := smaller_image.get_width() var h := smaller_image.get_height() - var ellipse_select := DrawingAlgos.get_ellipse_points(Vector2.ZERO, Vector2i(w,h)) + var ellipse_select := DrawingAlgos.get_ellipse_points(Vector2.ZERO, Vector2i(w, h)) var x_min := [] var x_max := [] x_min.resize(h) x_max.resize(h) # Determine x_min and x_max of y - for i in ellipse_select.size()/2: - i*=2 + for i in ellipse_select.size() / 2: + i *= 2 var y := ellipse_select[i].y - var xmin := ellipse_select[i].x if ellipse_select[i].x < ellipse_select[i+1].x else ellipse_select[i+1].x - var xmax := ellipse_select[i].x if ellipse_select[i].x >= ellipse_select[i+1].x else ellipse_select[i+1].x - + var xmin := ( + ellipse_select[i].x + if ellipse_select[i].x < ellipse_select[i + 1].x + else ellipse_select[i + 1].x + ) + var xmax := ( + ellipse_select[i].x + if ellipse_select[i].x >= ellipse_select[i + 1].x + else ellipse_select[i + 1].x + ) + if x_min[y] == null && x_max[y] == null: x_min[y] = xmin x_max[y] = xmax @@ -200,7 +208,7 @@ func resize_bitmap_values( if x_max[y] != null && x_max[y] < xmax: x_max[y] = xmax # too small to be rectangular selection - if x_min[0] == 0 && x_max[0] == w-1: + if x_min[0] == 0 && x_max[0] == w - 1: is_ellipse_select = false # if ellipse is too small, ellipse_select doesn't quite cover the true elliptical selection for y in range(h): @@ -211,7 +219,7 @@ func resize_bitmap_values( if !is_ellipse_select: break for x in range(w): - if smaller_image.get_pixel(x,y) == Color(1,1,1,1) && (x < x_min[y] || x > x_max[y]): + if smaller_image.get_pixel(x, y) == Color(1, 1, 1, 1) && (x < x_min[y] || x > x_max[y]): is_ellipse_select = false break # if selection is an ellipse selection, resized as standard ellipse @@ -219,11 +227,13 @@ func resize_bitmap_values( smaller_image.resize(new_size.x, new_size.y, Image.INTERPOLATE_BILINEAR) else: var resized_img := Image.create(new_size.x, new_size.y, false, smaller_image.get_format()) - var new_ellipse_select := DrawingAlgos.get_ellipse_points_filled(Vector2.ZERO, Vector2i(new_size.x,new_size.y)) + var new_ellipse_select := DrawingAlgos.get_ellipse_points_filled( + Vector2.ZERO, Vector2i(new_size.x, new_size.y) + ) for p in new_ellipse_select: resized_img.set_pixel(p.x, p.y, Color(1, 1, 1, 1)) - smaller_image = resized_img - + smaller_image = resized_img + if flip_hor: smaller_image.flip_x() if flip_ver: From 0e53f7ed67ef69bbe90c16433931ce16d89cc273 Mon Sep 17 00:00:00 2001 From: NIyue <100502009+NIyueeE@users.noreply.github.com> Date: Thu, 21 Nov 2024 22:03:27 +0800 Subject: [PATCH 7/7] Update SelectionMap.gd --- src/Classes/SelectionMap.gd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Classes/SelectionMap.gd b/src/Classes/SelectionMap.gd index a09068308..d5a89186a 100644 --- a/src/Classes/SelectionMap.gd +++ b/src/Classes/SelectionMap.gd @@ -199,7 +199,7 @@ func resize_bitmap_values( else ellipse_select[i + 1].x ) - if x_min[y] == null && x_max[y] == null: + if x_min[y] == null && x_max[y] == null: x_min[y] = xmin x_max[y] = xmax else: