mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-31 07:29:49 +00:00
Removed custom blend_rect() method from DrawingAlgos
This commit is contained in:
parent
b15e846f29
commit
6b26bb5b10
|
@ -18,7 +18,7 @@ func draw_pixel_blended(sprite : Image, pos : Vector2, color : Color, pen_pressu
|
||||||
var y_min = Global.current_project.y_min
|
var y_min = Global.current_project.y_min
|
||||||
var y_max = Global.current_project.y_max
|
var y_max = Global.current_project.y_max
|
||||||
|
|
||||||
# #Check if Tiling is enabled and whether mouse is in TilingPreviews
|
# Check if Tiling is enabled and whether mouse is in TilingPreviews
|
||||||
if Global.tile_mode and point_in_rectangle(pos,Vector2( - Global.current_project.size.x - 1 , - Global.current_project.size.y -1 ), Vector2(2 * Global.current_project.size.x, 2 * Global.current_project.size.y)):
|
if Global.tile_mode and point_in_rectangle(pos,Vector2( - Global.current_project.size.x - 1 , - Global.current_project.size.y -1 ), Vector2(2 * Global.current_project.size.x, 2 * Global.current_project.size.y)):
|
||||||
pos = pos.posmodv(Global.current_project.size)
|
pos = pos.posmodv(Global.current_project.size)
|
||||||
|
|
||||||
|
@ -144,13 +144,13 @@ func draw_brush(sprite : Image, pos : Vector2, color : Color, current_mouse_butt
|
||||||
mirror_y -= 1
|
mirror_y -= 1
|
||||||
# Use custom blend function cause of godot's issue #31124
|
# Use custom blend function cause of godot's issue #31124
|
||||||
if color.a > 0: # If it's the pencil
|
if color.a > 0: # If it's the pencil
|
||||||
blend_rect(sprite, custom_brush_image, src_rect, dst)
|
sprite.blend_rect(custom_brush_image, src_rect, dst)
|
||||||
if horizontal_mirror:
|
if horizontal_mirror:
|
||||||
blend_rect(sprite, custom_brush_image, src_rect, Vector2(mirror_x, dst.y))
|
sprite.blend_rect(custom_brush_image, src_rect, Vector2(mirror_x, dst.y))
|
||||||
if vertical_mirror:
|
if vertical_mirror:
|
||||||
blend_rect(sprite, custom_brush_image, src_rect, Vector2(dst.x, mirror_y))
|
sprite.blend_rect(custom_brush_image, src_rect, Vector2(dst.x, mirror_y))
|
||||||
if horizontal_mirror && vertical_mirror:
|
if horizontal_mirror && vertical_mirror:
|
||||||
blend_rect(sprite, custom_brush_image, src_rect, Vector2(mirror_x, mirror_y))
|
sprite.blend_rect(custom_brush_image, src_rect, Vector2(mirror_x, mirror_y))
|
||||||
|
|
||||||
else: # if it's transparent - if it's the eraser
|
else: # if it's transparent - if it's the eraser
|
||||||
var custom_brush := Image.new()
|
var custom_brush := Image.new()
|
||||||
|
@ -331,39 +331,6 @@ func blend_colors(color_1 : Color, color_2 : Color) -> Color:
|
||||||
return color
|
return color
|
||||||
|
|
||||||
|
|
||||||
# Custom blend rect function, needed because Godot's issue #31124
|
|
||||||
# The issue has been solved in Godot 3.2.2 and the method will be removed
|
|
||||||
# once 3.2.2 stable is released
|
|
||||||
func blend_rect(bg : Image, brush : Image, src_rect : Rect2, dst : Vector2) -> void:
|
|
||||||
var godot_version = Engine.get_version_info()
|
|
||||||
if godot_version.major >= 3 and godot_version.minor >= 2 and godot_version.patch >= 2:
|
|
||||||
bg.blend_rect(brush, src_rect, dst)
|
|
||||||
return
|
|
||||||
|
|
||||||
var brush_size := brush.get_size()
|
|
||||||
var clipped_src_rect := Rect2(Vector2.ZERO, brush_size).clip(src_rect)
|
|
||||||
if clipped_src_rect.size.x <= 0 || clipped_src_rect.size.y <= 0:
|
|
||||||
return
|
|
||||||
var src_underscan := Vector2(min(0, src_rect.position.x), min(0, src_rect.position.y))
|
|
||||||
var dest_rect := Rect2(0, 0, bg.get_width(), bg.get_height()).clip(Rect2(dst - src_underscan, clipped_src_rect.size))
|
|
||||||
|
|
||||||
for x in range(0, dest_rect.size.x):
|
|
||||||
for y in range(0, dest_rect.size.y):
|
|
||||||
var src_x := clipped_src_rect.position.x + x;
|
|
||||||
var src_y := clipped_src_rect.position.y + y;
|
|
||||||
|
|
||||||
var dst_x := dest_rect.position.x + x;
|
|
||||||
var dst_y := dest_rect.position.y + y;
|
|
||||||
|
|
||||||
brush.lock()
|
|
||||||
var brush_color := brush.get_pixel(src_x, src_y)
|
|
||||||
var bg_color := bg.get_pixel(dst_x, dst_y)
|
|
||||||
var out_color := blend_colors(brush_color, bg_color)
|
|
||||||
if out_color.a != 0:
|
|
||||||
bg.set_pixel(dst_x, dst_y, out_color)
|
|
||||||
brush.unlock()
|
|
||||||
|
|
||||||
|
|
||||||
func scale3X(sprite : Image, tol : float = 50) -> Image:
|
func scale3X(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)
|
||||||
|
|
|
@ -375,7 +375,7 @@ func blend_layers(image : Image, frame : Frame, origin : Vector2 = Vector2(0, 0)
|
||||||
var pixel_color := cel_image.get_pixel(xx, yy)
|
var pixel_color := cel_image.get_pixel(xx, yy)
|
||||||
var alpha : float = pixel_color.a * cel.opacity
|
var alpha : float = pixel_color.a * cel.opacity
|
||||||
cel_image.set_pixel(xx, yy, Color(pixel_color.r, pixel_color.g, pixel_color.b, alpha))
|
cel_image.set_pixel(xx, yy, Color(pixel_color.r, pixel_color.g, pixel_color.b, alpha))
|
||||||
DrawingAlgos.blend_rect(image, cel_image, Rect2(Global.canvas.location, Global.current_project.size), origin)
|
image.blend_rect(cel_image, Rect2(Global.canvas.location, Global.current_project.size), origin)
|
||||||
layer_i += 1
|
layer_i += 1
|
||||||
image.unlock()
|
image.unlock()
|
||||||
|
|
||||||
|
|
|
@ -441,7 +441,7 @@ func _on_MergeDownLayer_pressed() -> void:
|
||||||
var new_layer := Image.new()
|
var new_layer := Image.new()
|
||||||
new_layer.copy_from(f.cels[Global.current_project.current_layer - 1].image)
|
new_layer.copy_from(f.cels[Global.current_project.current_layer - 1].image)
|
||||||
new_layer.lock()
|
new_layer.lock()
|
||||||
DrawingAlgos.blend_rect(new_layer, selected_layer, Rect2(Global.canvas.location, Global.current_project.size), Vector2.ZERO)
|
new_layer.blend_rect(selected_layer, Rect2(Global.canvas.location, Global.current_project.size), Vector2.ZERO)
|
||||||
new_cels.remove(Global.current_project.current_layer)
|
new_cels.remove(Global.current_project.current_layer)
|
||||||
if !selected_layer.is_invisible() and Global.current_project.layers[Global.current_project.current_layer - 1].linked_cels.size() > 1 and (f in Global.current_project.layers[Global.current_project.current_layer - 1].linked_cels):
|
if !selected_layer.is_invisible() and Global.current_project.layers[Global.current_project.current_layer - 1].linked_cels.size() > 1 and (f in Global.current_project.layers[Global.current_project.current_layer - 1].linked_cels):
|
||||||
new_layers[Global.current_project.current_layer - 1].linked_cels.erase(f)
|
new_layers[Global.current_project.current_layer - 1].linked_cels.erase(f)
|
||||||
|
|
Loading…
Reference in a new issue