mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-30 23:19:49 +00:00
Renamed the _limit variables
See https://github.com/Orama-Interactive/Pixelorama/issues/232#issuecomment-638718662
This commit is contained in:
parent
2f5354ae4d
commit
2e5ff236d7
|
@ -13,11 +13,11 @@ func reset() -> void:
|
||||||
|
|
||||||
|
|
||||||
func draw_pixel_blended(sprite : Image, pos : Vector2, color : Color, pen_pressure : float, current_mouse_button := -1, current_action := -1) -> void:
|
func draw_pixel_blended(sprite : Image, pos : Vector2, color : Color, pen_pressure : float, current_mouse_button := -1, current_action := -1) -> void:
|
||||||
var west_limit = Global.canvas.west_limit
|
var x_min = Global.canvas.x_min
|
||||||
var east_limit = Global.canvas.east_limit
|
var x_max = Global.canvas.x_max
|
||||||
var north_limit = Global.canvas.north_limit
|
var y_min = Global.canvas.y_min
|
||||||
var south_limit = Global.canvas.south_limit
|
var y_max = Global.canvas.y_max
|
||||||
if !point_in_rectangle(pos, Vector2(west_limit - 1, north_limit - 1), Vector2(east_limit, south_limit)):
|
if !point_in_rectangle(pos, Vector2(x_min - 1, y_min - 1), Vector2(x_max, y_max)):
|
||||||
return
|
return
|
||||||
|
|
||||||
var pos_floored := pos.floor()
|
var pos_floored := pos.floor()
|
||||||
|
@ -45,10 +45,10 @@ func draw_pixel_blended(sprite : Image, pos : Vector2, color : Color, pen_pressu
|
||||||
|
|
||||||
func draw_brush(sprite : Image, pos : Vector2, color : Color, current_mouse_button : int, pen_pressure : float, current_action := -1) -> void:
|
func draw_brush(sprite : Image, pos : Vector2, color : Color, current_mouse_button : int, pen_pressure : float, current_action := -1) -> void:
|
||||||
if Global.can_draw && Global.has_focus:
|
if Global.can_draw && Global.has_focus:
|
||||||
var west_limit = Global.canvas.west_limit
|
var x_min = Global.canvas.x_min
|
||||||
var east_limit = Global.canvas.east_limit
|
var x_max = Global.canvas.x_max
|
||||||
var north_limit = Global.canvas.north_limit
|
var y_min = Global.canvas.y_min
|
||||||
var south_limit = Global.canvas.south_limit
|
var y_max = Global.canvas.y_max
|
||||||
|
|
||||||
if Global.pressure_sensitivity_mode == Global.Pressure_Sensitivity.ALPHA:
|
if Global.pressure_sensitivity_mode == Global.Pressure_Sensitivity.ALPHA:
|
||||||
if current_action == Global.Tools.PENCIL:
|
if current_action == Global.Tools.PENCIL:
|
||||||
|
@ -62,11 +62,11 @@ func draw_brush(sprite : Image, pos : Vector2, color : Color, current_mouse_butt
|
||||||
var horizontal_mirror : bool = Global.horizontal_mirror[current_mouse_button]
|
var horizontal_mirror : bool = Global.horizontal_mirror[current_mouse_button]
|
||||||
var vertical_mirror : bool = Global.vertical_mirror[current_mouse_button]
|
var vertical_mirror : bool = Global.vertical_mirror[current_mouse_button]
|
||||||
var pixel_perfect : bool = Global.pixel_perfect[current_mouse_button]
|
var pixel_perfect : bool = Global.pixel_perfect[current_mouse_button]
|
||||||
|
|
||||||
drawer.pixel_perfect = pixel_perfect if brush_size == 1 else false
|
drawer.pixel_perfect = pixel_perfect if brush_size == 1 else false
|
||||||
drawer.h_mirror = horizontal_mirror
|
drawer.h_mirror = horizontal_mirror
|
||||||
drawer.v_mirror = vertical_mirror
|
drawer.v_mirror = vertical_mirror
|
||||||
|
|
||||||
if brush_type == Global.Brush_Types.PIXEL || current_action == Global.Tools.LIGHTENDARKEN:
|
if brush_type == Global.Brush_Types.PIXEL || current_action == Global.Tools.LIGHTENDARKEN:
|
||||||
var start_pos_x = pos.x - (brush_size >> 1)
|
var start_pos_x = pos.x - (brush_size >> 1)
|
||||||
var start_pos_y = pos.y - (brush_size >> 1)
|
var start_pos_y = pos.y - (brush_size >> 1)
|
||||||
|
@ -74,7 +74,7 @@ func draw_brush(sprite : Image, pos : Vector2, color : Color, current_mouse_butt
|
||||||
var end_pos_y = start_pos_y + brush_size
|
var end_pos_y = start_pos_y + brush_size
|
||||||
|
|
||||||
for cur_pos_x in range(start_pos_x, end_pos_x):
|
for cur_pos_x in range(start_pos_x, end_pos_x):
|
||||||
for cur_pos_y in range(start_pos_y, end_pos_y):
|
for cur_pos_y in range(start_pos_y, end_pos_y):
|
||||||
draw_pixel_blended(sprite, Vector2(cur_pos_x, cur_pos_y), color, pen_pressure, current_mouse_button, current_action)
|
draw_pixel_blended(sprite, Vector2(cur_pos_x, cur_pos_y), color, pen_pressure, current_mouse_button, current_action)
|
||||||
Global.canvas.sprite_changed_this_frame = true
|
Global.canvas.sprite_changed_this_frame = true
|
||||||
|
|
||||||
|
@ -107,8 +107,8 @@ func draw_brush(sprite : Image, pos : Vector2, color : Color, current_mouse_butt
|
||||||
# The selection rectangle
|
# The selection rectangle
|
||||||
# If there's no rectangle, the whole canvas is considered a selection
|
# If there's no rectangle, the whole canvas is considered a selection
|
||||||
var selection_rect := Rect2()
|
var selection_rect := Rect2()
|
||||||
selection_rect.position = Vector2(west_limit, north_limit)
|
selection_rect.position = Vector2(x_min, y_min)
|
||||||
selection_rect.end = Vector2(east_limit, south_limit)
|
selection_rect.end = Vector2(x_max, y_max)
|
||||||
# Intersection of the position rectangle and selection
|
# Intersection of the position rectangle and selection
|
||||||
var pos_rect_clipped := pos_rect.clip(selection_rect)
|
var pos_rect_clipped := pos_rect.clip(selection_rect)
|
||||||
# If the size is 0, that means that the brush wasn't positioned inside the selection
|
# If the size is 0, that means that the brush wasn't positioned inside the selection
|
||||||
|
@ -127,8 +127,8 @@ func draw_brush(sprite : Image, pos : Vector2, color : Color, current_mouse_butt
|
||||||
src_rect.size.y = min(src_rect.size.y, selection_rect.size.y)
|
src_rect.size.y = min(src_rect.size.y, selection_rect.size.y)
|
||||||
|
|
||||||
# Handle mirroring
|
# Handle mirroring
|
||||||
var mirror_x = east_limit + west_limit - pos.x - (pos.x - dst.x)
|
var mirror_x = x_max + x_min - pos.x - (pos.x - dst.x)
|
||||||
var mirror_y = south_limit + north_limit - pos.y - (pos.y - dst.y)
|
var mirror_y = y_max + y_min - pos.y - (pos.y - dst.y)
|
||||||
if int(pos_rect_clipped.size.x) % 2 != 0:
|
if int(pos_rect_clipped.size.x) % 2 != 0:
|
||||||
mirror_x -= 1
|
mirror_x -= 1
|
||||||
if int(pos_rect_clipped.size.y) % 2 != 0:
|
if int(pos_rect_clipped.size.y) % 2 != 0:
|
||||||
|
@ -226,10 +226,10 @@ func plot_circle(sprite : Image, xm : int, ym : int, r : int, color : Color, fil
|
||||||
|
|
||||||
# Thanks to https://en.wikipedia.org/wiki/Flood_fill
|
# Thanks to https://en.wikipedia.org/wiki/Flood_fill
|
||||||
func flood_fill(sprite : Image, pos : Vector2, target_color : Color, replace_color : Color) -> void:
|
func flood_fill(sprite : Image, pos : Vector2, target_color : Color, replace_color : Color) -> void:
|
||||||
var west_limit = Global.canvas.west_limit
|
var x_min = Global.canvas.x_min
|
||||||
var east_limit = Global.canvas.east_limit
|
var x_max = Global.canvas.x_max
|
||||||
var north_limit = Global.canvas.north_limit
|
var y_min = Global.canvas.y_min
|
||||||
var south_limit = Global.canvas.south_limit
|
var y_max = Global.canvas.y_max
|
||||||
pos = pos.floor()
|
pos = pos.floor()
|
||||||
var pixel = sprite.get_pixelv(pos)
|
var pixel = sprite.get_pixelv(pos)
|
||||||
if target_color == replace_color:
|
if target_color == replace_color:
|
||||||
|
@ -238,7 +238,7 @@ func flood_fill(sprite : Image, pos : Vector2, target_color : Color, replace_col
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
|
|
||||||
if !point_in_rectangle(pos, Vector2(west_limit - 1, north_limit - 1), Vector2(east_limit, south_limit)):
|
if !point_in_rectangle(pos, Vector2(x_min - 1, y_min - 1), Vector2(x_max, y_max)):
|
||||||
return
|
return
|
||||||
|
|
||||||
var q = [pos]
|
var q = [pos]
|
||||||
|
@ -248,9 +248,9 @@ func flood_fill(sprite : Image, pos : Vector2, target_color : Color, replace_col
|
||||||
break
|
break
|
||||||
var west : Vector2 = n
|
var west : Vector2 = n
|
||||||
var east : Vector2 = n
|
var east : Vector2 = n
|
||||||
while west.x >= west_limit && sprite.get_pixelv(west) == target_color:
|
while west.x >= x_min && sprite.get_pixelv(west) == target_color:
|
||||||
west += Vector2.LEFT
|
west += Vector2.LEFT
|
||||||
while east.x < east_limit && sprite.get_pixelv(east) == target_color:
|
while east.x < x_max && sprite.get_pixelv(east) == target_color:
|
||||||
east += Vector2.RIGHT
|
east += Vector2.RIGHT
|
||||||
for px in range(west.x + 1, east.x):
|
for px in range(west.x + 1, east.x):
|
||||||
var p := Vector2(px, n.y)
|
var p := Vector2(px, n.y)
|
||||||
|
@ -259,21 +259,21 @@ func flood_fill(sprite : Image, pos : Vector2, target_color : Color, replace_col
|
||||||
replace_color = sprite.get_pixelv(p)
|
replace_color = sprite.get_pixelv(p)
|
||||||
var north := p + Vector2.UP
|
var north := p + Vector2.UP
|
||||||
var south := p + Vector2.DOWN
|
var south := p + Vector2.DOWN
|
||||||
if north.y >= north_limit && sprite.get_pixelv(north) == target_color:
|
if north.y >= y_min && sprite.get_pixelv(north) == target_color:
|
||||||
q.append(north)
|
q.append(north)
|
||||||
if south.y < south_limit && sprite.get_pixelv(south) == target_color:
|
if south.y < y_max && sprite.get_pixelv(south) == target_color:
|
||||||
q.append(south)
|
q.append(south)
|
||||||
|
|
||||||
Global.canvas.sprite_changed_this_frame = true
|
Global.canvas.sprite_changed_this_frame = true
|
||||||
|
|
||||||
|
|
||||||
func pattern_fill(sprite : Image, pos : Vector2, pattern : Image, target_color : Color, var offset : Vector2) -> void:
|
func pattern_fill(sprite : Image, pos : Vector2, pattern : Image, target_color : Color, var offset : Vector2) -> void:
|
||||||
var west_limit = Global.canvas.west_limit
|
var x_min = Global.canvas.x_min
|
||||||
var east_limit = Global.canvas.east_limit
|
var x_max = Global.canvas.x_max
|
||||||
var north_limit = Global.canvas.north_limit
|
var y_min = Global.canvas.y_min
|
||||||
var south_limit = Global.canvas.south_limit
|
var y_max = Global.canvas.y_max
|
||||||
pos = pos.floor()
|
pos = pos.floor()
|
||||||
if !point_in_rectangle(pos, Vector2(west_limit - 1, north_limit - 1), Vector2(east_limit, south_limit)):
|
if !point_in_rectangle(pos, Vector2(x_min - 1, y_min - 1), Vector2(x_max, y_max)):
|
||||||
return
|
return
|
||||||
|
|
||||||
pattern.lock()
|
pattern.lock()
|
||||||
|
@ -283,9 +283,9 @@ func pattern_fill(sprite : Image, pos : Vector2, pattern : Image, target_color :
|
||||||
for n in q:
|
for n in q:
|
||||||
var west : Vector2 = n
|
var west : Vector2 = n
|
||||||
var east : Vector2 = n
|
var east : Vector2 = n
|
||||||
while west.x >= west_limit && sprite.get_pixelv(west) == target_color:
|
while west.x >= x_min && sprite.get_pixelv(west) == target_color:
|
||||||
west += Vector2.LEFT
|
west += Vector2.LEFT
|
||||||
while east.x < east_limit && sprite.get_pixelv(east) == target_color:
|
while east.x < x_max && sprite.get_pixelv(east) == target_color:
|
||||||
east += Vector2.RIGHT
|
east += Vector2.RIGHT
|
||||||
|
|
||||||
for px in range(west.x + 1, east.x):
|
for px in range(west.x + 1, east.x):
|
||||||
|
@ -299,9 +299,9 @@ func pattern_fill(sprite : Image, pos : Vector2, pattern : Image, target_color :
|
||||||
|
|
||||||
var north := p + Vector2.UP
|
var north := p + Vector2.UP
|
||||||
var south := p + Vector2.DOWN
|
var south := p + Vector2.DOWN
|
||||||
if north.y >= north_limit && sprite.get_pixelv(north) == target_color:
|
if north.y >= y_min && sprite.get_pixelv(north) == target_color:
|
||||||
q.append(north)
|
q.append(north)
|
||||||
if south.y < south_limit && sprite.get_pixelv(south) == target_color:
|
if south.y < y_max && sprite.get_pixelv(south) == target_color:
|
||||||
q.append(south)
|
q.append(south)
|
||||||
|
|
||||||
pattern.unlock()
|
pattern.unlock()
|
||||||
|
@ -558,16 +558,16 @@ func colorDistance(c1 : Color, c2 : Color) -> float:
|
||||||
|
|
||||||
|
|
||||||
func adjust_hsv(img: Image, id : int, delta : float) -> void:
|
func adjust_hsv(img: Image, id : int, delta : float) -> void:
|
||||||
var west_limit = Global.canvas.west_limit
|
var x_min = Global.canvas.x_min
|
||||||
var east_limit = Global.canvas.east_limit
|
var x_max = Global.canvas.x_max
|
||||||
var north_limit = Global.canvas.north_limit
|
var y_min = Global.canvas.y_min
|
||||||
var south_limit = Global.canvas.south_limit
|
var y_max = Global.canvas.y_max
|
||||||
img.lock()
|
img.lock()
|
||||||
|
|
||||||
match id:
|
match id:
|
||||||
0: # Hue
|
0: # Hue
|
||||||
for i in range(west_limit, east_limit):
|
for i in range(x_min, x_max):
|
||||||
for j in range(north_limit, south_limit):
|
for j in range(y_min, y_max):
|
||||||
var c : Color = img.get_pixel(i,j)
|
var c : Color = img.get_pixel(i,j)
|
||||||
var hue = range_lerp(c.h,0,1,-180,180)
|
var hue = range_lerp(c.h,0,1,-180,180)
|
||||||
hue = hue + delta
|
hue = hue + delta
|
||||||
|
@ -580,8 +580,8 @@ func adjust_hsv(img: Image, id : int, delta : float) -> void:
|
||||||
img.set_pixel(i,j,c)
|
img.set_pixel(i,j,c)
|
||||||
|
|
||||||
1: # Saturation
|
1: # Saturation
|
||||||
for i in range(west_limit, east_limit):
|
for i in range(x_min, x_max):
|
||||||
for j in range(north_limit, south_limit):
|
for j in range(y_min, y_max):
|
||||||
var c : Color = img.get_pixel(i,j)
|
var c : Color = img.get_pixel(i,j)
|
||||||
var sat = c.s
|
var sat = c.s
|
||||||
if delta > 0:
|
if delta > 0:
|
||||||
|
@ -592,8 +592,8 @@ func adjust_hsv(img: Image, id : int, delta : float) -> void:
|
||||||
img.set_pixel(i,j,c)
|
img.set_pixel(i,j,c)
|
||||||
|
|
||||||
2: # Value
|
2: # Value
|
||||||
for i in range(west_limit, east_limit):
|
for i in range(x_min, x_max):
|
||||||
for j in range(north_limit, south_limit):
|
for j in range(y_min, y_max):
|
||||||
var c : Color = img.get_pixel(i,j)
|
var c : Color = img.get_pixel(i,j)
|
||||||
var val = c.v
|
var val = c.v
|
||||||
if delta > 0:
|
if delta > 0:
|
||||||
|
|
|
@ -11,10 +11,10 @@ var previous_mouse_pos_for_lines := Vector2.ZERO
|
||||||
var can_undo := true
|
var can_undo := true
|
||||||
var cursor_image_has_changed := false
|
var cursor_image_has_changed := false
|
||||||
var previous_action := -1
|
var previous_action := -1
|
||||||
var west_limit := location.x
|
var x_min := location.x
|
||||||
var east_limit := location.x + size.x
|
var x_max := location.x + size.x
|
||||||
var north_limit := location.y
|
var y_min := location.y
|
||||||
var south_limit := location.y + size.y
|
var y_max := location.y + size.y
|
||||||
var sprite_changed_this_frame := false # for optimization purposes
|
var sprite_changed_this_frame := false # for optimization purposes
|
||||||
var is_making_line := false
|
var is_making_line := false
|
||||||
var made_line := false
|
var made_line := false
|
||||||
|
@ -121,15 +121,15 @@ func _input(event : InputEvent) -> void:
|
||||||
var mouse_pos_floored := mouse_pos.floor()
|
var mouse_pos_floored := mouse_pos.floor()
|
||||||
var current_mouse_button := -1
|
var current_mouse_button := -1
|
||||||
|
|
||||||
west_limit = location.x
|
x_min = location.x
|
||||||
east_limit = location.x + size.x
|
x_max = location.x + size.x
|
||||||
north_limit = location.y
|
y_min = location.y
|
||||||
south_limit = location.y + size.y
|
y_max = location.y + size.y
|
||||||
if Global.selected_pixels.size() != 0:
|
if Global.selected_pixels.size() != 0:
|
||||||
west_limit = max(west_limit, Global.selection_rectangle.polygon[0].x)
|
x_min = max(x_min, Global.selection_rectangle.polygon[0].x)
|
||||||
east_limit = min(east_limit, Global.selection_rectangle.polygon[2].x)
|
x_max = min(x_max, Global.selection_rectangle.polygon[2].x)
|
||||||
north_limit = max(north_limit, Global.selection_rectangle.polygon[0].y)
|
y_min = max(y_min, Global.selection_rectangle.polygon[0].y)
|
||||||
south_limit = min(south_limit, Global.selection_rectangle.polygon[2].y)
|
y_max = min(y_max, Global.selection_rectangle.polygon[2].y)
|
||||||
|
|
||||||
if Input.is_mouse_button_pressed(BUTTON_LEFT):
|
if Input.is_mouse_button_pressed(BUTTON_LEFT):
|
||||||
current_mouse_button = Global.Mouse_Button.LEFT
|
current_mouse_button = Global.Mouse_Button.LEFT
|
||||||
|
@ -295,8 +295,8 @@ func handle_tools(current_mouse_button : int, current_action : int, mouse_pos :
|
||||||
var pattern_offset : Vector2 = Global.fill_pattern_offsets[current_mouse_button]
|
var pattern_offset : Vector2 = Global.fill_pattern_offsets[current_mouse_button]
|
||||||
|
|
||||||
if fill_area == Global.Fill_Area.SAME_COLOR_AREA: # Paint the specific area of the same color
|
if fill_area == Global.Fill_Area.SAME_COLOR_AREA: # Paint the specific area of the same color
|
||||||
var mirror_x := east_limit + west_limit - mouse_pos_floored.x - 1
|
var mirror_x := x_max + x_min - mouse_pos_floored.x - 1
|
||||||
var mirror_y := south_limit + north_limit - mouse_pos_floored.y - 1
|
var mirror_y := y_max + y_min - mouse_pos_floored.y - 1
|
||||||
var horizontal_mirror : bool = Global.horizontal_mirror[current_mouse_button]
|
var horizontal_mirror : bool = Global.horizontal_mirror[current_mouse_button]
|
||||||
var vertical_mirror : bool = Global.vertical_mirror[current_mouse_button]
|
var vertical_mirror : bool = Global.vertical_mirror[current_mouse_button]
|
||||||
|
|
||||||
|
@ -326,8 +326,8 @@ func handle_tools(current_mouse_button : int, current_action : int, mouse_pos :
|
||||||
|
|
||||||
else: # Paint all pixels of the same color
|
else: # Paint all pixels of the same color
|
||||||
var pixel_color : Color = sprite.get_pixelv(mouse_pos)
|
var pixel_color : Color = sprite.get_pixelv(mouse_pos)
|
||||||
for xx in range(west_limit, east_limit):
|
for xx in range(x_min, x_max):
|
||||||
for yy in range(north_limit, south_limit):
|
for yy in range(y_min, y_max):
|
||||||
var c : Color = sprite.get_pixel(xx, yy)
|
var c : Color = sprite.get_pixel(xx, yy)
|
||||||
if c == pixel_color:
|
if c == pixel_color:
|
||||||
if fill_with == Global.Fill_With.PATTERN && pattern_image: # Pattern fill
|
if fill_with == Global.Fill_With.PATTERN && pattern_image: # Pattern fill
|
||||||
|
|
|
@ -53,8 +53,8 @@ func set_pixel_perfect(value: bool) -> void:
|
||||||
|
|
||||||
|
|
||||||
func set_pixel(_sprite: Image, _pos: Vector2, _new_color: Color) -> void:
|
func set_pixel(_sprite: Image, _pos: Vector2, _new_color: Color) -> void:
|
||||||
var mirror_x = Global.canvas.east_limit + Global.canvas.west_limit - _pos.x - 1
|
var mirror_x = Global.canvas.x_max + Global.canvas.x_min - _pos.x - 1
|
||||||
var mirror_y = Global.canvas.south_limit + Global.canvas.north_limit - _pos.y - 1
|
var mirror_y = Global.canvas.y_max + Global.canvas.y_min - _pos.y - 1
|
||||||
|
|
||||||
drawers[0].set_pixel(_sprite, _pos, _new_color)
|
drawers[0].set_pixel(_sprite, _pos, _new_color)
|
||||||
if h_mirror:
|
if h_mirror:
|
||||||
|
|
Loading…
Reference in a new issue