mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-18 17:19:50 +00:00
Rotation improvements (#676)
* add limit change with brush * Delete Draw.gd * Delete BaseTool.gd * Pivot correction in case of even size * fix the Scale3x it should not remove the edges now * formatting * more formatting
This commit is contained in:
parent
16a2abf9b4
commit
b9a841a360
|
@ -18,20 +18,26 @@ func scale_3x(sprite: Image, tol: float = 50) -> Image:
|
|||
var h: Color
|
||||
var i: Color
|
||||
|
||||
for x in range(1, sprite.get_width() - 1):
|
||||
for y in range(1, sprite.get_height() - 1):
|
||||
for x in range(0, sprite.get_width()):
|
||||
for y in range(0, sprite.get_height()):
|
||||
var xs: float = 3 * x
|
||||
var ys: float = 3 * y
|
||||
|
||||
a = sprite.get_pixel(x - 1, y - 1)
|
||||
b = sprite.get_pixel(x, y - 1)
|
||||
c = sprite.get_pixel(x + 1, y - 1)
|
||||
d = sprite.get_pixel(x - 1, y)
|
||||
e = sprite.get_pixel(x, y)
|
||||
f = sprite.get_pixel(x + 1, y)
|
||||
g = sprite.get_pixel(x - 1, y + 1)
|
||||
h = sprite.get_pixel(x, y + 1)
|
||||
i = sprite.get_pixel(x + 1, y + 1)
|
||||
a = sprite.get_pixel(max(x - 1, 0), max(y - 1, 0))
|
||||
b = sprite.get_pixel(min(x, sprite.get_width() - 1), max(y - 1, 0))
|
||||
c = sprite.get_pixel(min(x + 1, sprite.get_width() - 1), max(y - 1, 0))
|
||||
d = sprite.get_pixel(max(x - 1, 0), min(y, sprite.get_height() - 1))
|
||||
e = sprite.get_pixel(min(x, sprite.get_width() - 1), min(y, sprite.get_height() - 1))
|
||||
f = sprite.get_pixel(
|
||||
min(x + 1, sprite.get_width() - 1), min(y, sprite.get_height() - 1)
|
||||
)
|
||||
g = sprite.get_pixel(max(x - 1, 0), min(y + 1, sprite.get_height() - 1))
|
||||
h = sprite.get_pixel(
|
||||
min(x, sprite.get_width() - 1), min(y + 1, sprite.get_height() - 1)
|
||||
)
|
||||
i = sprite.get_pixel(
|
||||
min(x + 1, sprite.get_width() - 1), min(y + 1, sprite.get_height() - 1)
|
||||
)
|
||||
|
||||
var db: bool = similar_colors(d, b, tol)
|
||||
var dh: bool = similar_colors(d, h, tol)
|
||||
|
@ -42,19 +48,23 @@ func scale_3x(sprite: Image, tol: float = 50) -> Image:
|
|||
var eg: bool = similar_colors(e, g, tol)
|
||||
var ei: bool = similar_colors(e, i, tol)
|
||||
|
||||
scaled.set_pixel(xs - 1, ys - 1, d if (db and !dh and !bf) else e)
|
||||
scaled.set_pixel(max(xs - 1, 0), max(ys - 1, 0), d if (db and !dh and !bf) else e)
|
||||
scaled.set_pixel(
|
||||
xs, ys - 1, b if (db and !dh and !bf and !ec) or (bf and !db and !fh and !ea) else e
|
||||
xs,
|
||||
max(ys - 1, 0),
|
||||
b if (db and !dh and !bf and !ec) or (bf and !db and !fh and !ea) else e
|
||||
)
|
||||
scaled.set_pixel(xs + 1, ys - 1, f if (bf and !db and !fh) else e)
|
||||
scaled.set_pixel(xs + 1, max(ys - 1, 0), f if (bf and !db and !fh) else e)
|
||||
scaled.set_pixel(
|
||||
xs - 1, ys, d if (dh and !fh and !db and !ea) or (db and !dh and !bf and !eg) else e
|
||||
max(xs - 1, 0),
|
||||
ys,
|
||||
d if (dh and !fh and !db and !ea) or (db and !dh and !bf and !eg) else e
|
||||
)
|
||||
scaled.set_pixel(xs, ys, e)
|
||||
scaled.set_pixel(
|
||||
xs + 1, ys, f if (bf and !db and !fh and !ei) or (fh and !bf and !dh and !ec) else e
|
||||
)
|
||||
scaled.set_pixel(xs - 1, ys + 1, d if (dh and !fh and !db) else e)
|
||||
scaled.set_pixel(max(xs - 1, 0), ys + 1, d if (dh and !fh and !db) else e)
|
||||
scaled.set_pixel(
|
||||
xs, ys + 1, h if (fh and !bf and !dh and !eg) or (dh and !fh and !db and !ei) else e
|
||||
)
|
||||
|
|
|
@ -28,9 +28,15 @@ func _about_to_show() -> void:
|
|||
|
||||
func commit_action(_cel: Image, _project: Project = Global.current_project) -> void:
|
||||
var angle: float = deg2rad(angle_hslider.value)
|
||||
# warning-ignore:integer_division
|
||||
# warning-ignore:integer_division
|
||||
# warning-ignore:integer_division
|
||||
# warning-ignore:integer_division
|
||||
var pivot = Vector2(_cel.get_width() / 2, _cel.get_height() / 2)
|
||||
# Pivot correction in case of even size
|
||||
if _cel.get_width() % 2 == 0:
|
||||
pivot.x -= 0.5
|
||||
if _cel.get_height() % 2 == 0:
|
||||
pivot.y -= 0.5
|
||||
|
||||
var image := Image.new()
|
||||
image.copy_from(_cel)
|
||||
if _project.has_selection and selection_checkbox.pressed:
|
||||
|
@ -39,6 +45,11 @@ func commit_action(_cel: Image, _project: Project = Global.current_project) -> v
|
|||
selection_rectangle.position
|
||||
+ ((selection_rectangle.end - selection_rectangle.position) / 2)
|
||||
)
|
||||
# Pivot correction in case of even size
|
||||
if int(selection_rectangle.end.x - selection_rectangle.position.x) % 2 == 0:
|
||||
pivot.x -= 0.5
|
||||
if int(selection_rectangle.end.y - selection_rectangle.position.y) % 2 == 0:
|
||||
pivot.y -= 0.5
|
||||
image.lock()
|
||||
_cel.lock()
|
||||
for x in _project.size.x:
|
||||
|
|
Loading…
Reference in a new issue