mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-31 07:29:49 +00:00
Make circle brushes scale properly, with support for even-numebered diameters
Also reverts commit 488cf0cc93
This commit is contained in:
parent
dee49b61bf
commit
d34e69579f
|
@ -42,7 +42,6 @@ func get_ellipse_points(pos: Vector2, size: Vector2) -> Array:
|
||||||
array.append(v4)
|
array.append(v4)
|
||||||
|
|
||||||
e2 = 2 * err
|
e2 = 2 * err
|
||||||
|
|
||||||
if e2 <= dy:
|
if e2 <= dy:
|
||||||
y0 += 1
|
y0 += 1
|
||||||
y1 -= 1
|
y1 -= 1
|
||||||
|
@ -70,6 +69,37 @@ func get_ellipse_points(pos: Vector2, size: Vector2) -> Array:
|
||||||
return array
|
return array
|
||||||
|
|
||||||
|
|
||||||
|
func get_ellipse_points_filled(pos: Vector2, size: Vector2, thickness := 1) -> PoolVector2Array:
|
||||||
|
var offsetted_size := size + Vector2.ONE * (thickness - 1)
|
||||||
|
var border := get_ellipse_points(pos, offsetted_size)
|
||||||
|
var filling := []
|
||||||
|
|
||||||
|
for x in range(1, ceil(offsetted_size.x / 2)):
|
||||||
|
var fill := false
|
||||||
|
var prev_is_true := false
|
||||||
|
for y in range(0, ceil(offsetted_size.y / 2)):
|
||||||
|
var top_l_p := Vector2(x, y)
|
||||||
|
var bit := border.has(pos + top_l_p)
|
||||||
|
|
||||||
|
if bit and not fill:
|
||||||
|
prev_is_true = true
|
||||||
|
continue
|
||||||
|
|
||||||
|
if not bit and (fill or prev_is_true):
|
||||||
|
filling.append(pos + top_l_p)
|
||||||
|
filling.append(pos + Vector2(x, offsetted_size.y - y - 1))
|
||||||
|
filling.append(pos + Vector2(offsetted_size.x - x - 1, y))
|
||||||
|
filling.append(pos + Vector2(offsetted_size.x - x - 1, offsetted_size.y - y - 1))
|
||||||
|
|
||||||
|
if prev_is_true:
|
||||||
|
fill = true
|
||||||
|
prev_is_true = false
|
||||||
|
elif bit and fill:
|
||||||
|
break
|
||||||
|
|
||||||
|
return PoolVector2Array(border + filling)
|
||||||
|
|
||||||
|
|
||||||
func scale_3x(sprite: Image, tol: float = 50) -> Image:
|
func scale_3x(sprite: Image, tol: float = 50) -> Image:
|
||||||
var scaled := Image.new()
|
var scaled := Image.new()
|
||||||
scaled.create(sprite.get_width() * 3, sprite.get_height() * 3, false, Image.FORMAT_RGBA8)
|
scaled.create(sprite.get_width() * 3, sprite.get_height() * 3, false, Image.FORMAT_RGBA8)
|
||||||
|
|
|
@ -214,9 +214,7 @@ func _prepare_tool() -> void:
|
||||||
var strength := _strength
|
var strength := _strength
|
||||||
if Global.pressure_sensitivity_mode == Global.PressureSensitivity.ALPHA:
|
if Global.pressure_sensitivity_mode == Global.PressureSensitivity.ALPHA:
|
||||||
strength *= Tools.pen_pressure
|
strength *= Tools.pen_pressure
|
||||||
_drawer.pixel_perfect = false
|
_drawer.pixel_perfect = Tools.pixel_perfect if _brush_size == 1 else false
|
||||||
if _brush_size == 1 and _brush.type == Brushes.PIXEL:
|
|
||||||
_drawer.pixel_perfect = Tools.pixel_perfect
|
|
||||||
_drawer.horizontal_mirror = Tools.horizontal_mirror
|
_drawer.horizontal_mirror = Tools.horizontal_mirror
|
||||||
_drawer.vertical_mirror = Tools.vertical_mirror
|
_drawer.vertical_mirror = Tools.vertical_mirror
|
||||||
_drawer.color_op.strength = strength
|
_drawer.color_op.strength = strength
|
||||||
|
@ -300,36 +298,18 @@ func _compute_draw_tool_pixel(position: Vector2) -> PoolVector2Array:
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
# Algorithm based on http://members.chello.at/easyfilter/bresenham.html
|
|
||||||
# Compute the array of coordinates that should be drawn
|
# Compute the array of coordinates that should be drawn
|
||||||
func _compute_draw_tool_circle(position: Vector2, fill := false) -> PoolVector2Array:
|
func _compute_draw_tool_circle(position: Vector2, fill := false) -> PoolVector2Array:
|
||||||
|
var size := Vector2(_brush_size, _brush_size)
|
||||||
|
var pos = position - (size / 2).floor()
|
||||||
if _circle_tool_shortcut:
|
if _circle_tool_shortcut:
|
||||||
return _draw_tool_circle_from_map(position)
|
return _draw_tool_circle_from_map(position)
|
||||||
|
|
||||||
var result := PoolVector2Array()
|
var result := PoolVector2Array()
|
||||||
var r := _brush_size
|
|
||||||
var x := -r
|
|
||||||
var y := 0
|
|
||||||
var err := 2 - r * 2
|
|
||||||
var draw := true
|
|
||||||
if fill:
|
if fill:
|
||||||
result.append(position)
|
result = DrawingAlgos.get_ellipse_points_filled(pos, size)
|
||||||
while x < 0:
|
else:
|
||||||
if draw:
|
result = DrawingAlgos.get_ellipse_points(pos, size)
|
||||||
for i in range(1 if fill else -x, -x + 1):
|
|
||||||
result.append(position + Vector2(-i, y))
|
|
||||||
result.append(position + Vector2(-y, -i))
|
|
||||||
result.append(position + Vector2(i, -y))
|
|
||||||
result.append(position + Vector2(y, i))
|
|
||||||
draw = not fill
|
|
||||||
r = err
|
|
||||||
if r <= y:
|
|
||||||
y += 1
|
|
||||||
err += y * 2 + 1
|
|
||||||
draw = true
|
|
||||||
if r > x || err > y:
|
|
||||||
x += 1
|
|
||||||
err += x * 2 + 1
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,35 +2,7 @@ extends "res://src/Tools/ShapeDrawer.gd"
|
||||||
|
|
||||||
|
|
||||||
func _get_shape_points_filled(size: Vector2) -> PoolVector2Array:
|
func _get_shape_points_filled(size: Vector2) -> PoolVector2Array:
|
||||||
var offsetted_size := size + Vector2.ONE * (_thickness - 1)
|
return DrawingAlgos.get_ellipse_points_filled(Vector2.ZERO, size, _thickness)
|
||||||
var border := DrawingAlgos.get_ellipse_points(Vector2.ZERO, offsetted_size)
|
|
||||||
var filling := []
|
|
||||||
var bitmap := _fill_bitmap_with_points(border, offsetted_size)
|
|
||||||
|
|
||||||
for x in range(1, ceil(offsetted_size.x / 2)):
|
|
||||||
var fill := false
|
|
||||||
var prev_is_true := false
|
|
||||||
for y in range(0, ceil(offsetted_size.y / 2)):
|
|
||||||
var top_l_p := Vector2(x, y)
|
|
||||||
var bit := bitmap.get_bit(top_l_p)
|
|
||||||
|
|
||||||
if bit and not fill:
|
|
||||||
prev_is_true = true
|
|
||||||
continue
|
|
||||||
|
|
||||||
if not bit and (fill or prev_is_true):
|
|
||||||
filling.append(top_l_p)
|
|
||||||
filling.append(Vector2(x, offsetted_size.y - y - 1))
|
|
||||||
filling.append(Vector2(offsetted_size.x - x - 1, y))
|
|
||||||
filling.append(Vector2(offsetted_size.x - x - 1, offsetted_size.y - y - 1))
|
|
||||||
|
|
||||||
if prev_is_true:
|
|
||||||
fill = true
|
|
||||||
prev_is_true = false
|
|
||||||
elif bit and fill:
|
|
||||||
break
|
|
||||||
|
|
||||||
return PoolVector2Array(border + filling)
|
|
||||||
|
|
||||||
|
|
||||||
func _get_shape_points(size: Vector2) -> PoolVector2Array:
|
func _get_shape_points(size: Vector2) -> PoolVector2Array:
|
||||||
|
|
Loading…
Reference in a new issue