mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-31 07:29:49 +00:00
Fixed problem with drawing and filling gaps, created "shift" in Input Map
previous_mouse_pos is now used for regular drawing, while previous_mouse_pos_for_lines is used for straight lines
This commit is contained in:
parent
f3ab5960ba
commit
00ef80e932
|
@ -12,6 +12,7 @@ var frame_texture_rect : TextureRect
|
||||||
|
|
||||||
var current_pixel := Vector2.ZERO #pretty much same as mouse_pos, but can be accessed externally
|
var current_pixel := Vector2.ZERO #pretty much same as mouse_pos, but can be accessed externally
|
||||||
var previous_mouse_pos := Vector2.ZERO
|
var previous_mouse_pos := Vector2.ZERO
|
||||||
|
var previous_mouse_pos_for_lines := Vector2.ZERO
|
||||||
var cursor_inside_canvas := false
|
var cursor_inside_canvas := false
|
||||||
var previous_action := "None"
|
var previous_action := "None"
|
||||||
var mouse_inside_canvas := false #used for undo
|
var mouse_inside_canvas := false #used for undo
|
||||||
|
@ -250,7 +251,7 @@ func _process(delta : float) -> void:
|
||||||
line_2d = Line2D.new()
|
line_2d = Line2D.new()
|
||||||
line_2d.width = 0.5
|
line_2d.width = 0.5
|
||||||
line_2d.default_color = Color.darkgray
|
line_2d.default_color = Color.darkgray
|
||||||
line_2d.add_point(previous_mouse_pos)
|
line_2d.add_point(previous_mouse_pos_for_lines)
|
||||||
line_2d.add_point(mouse_pos)
|
line_2d.add_point(mouse_pos)
|
||||||
add_child(line_2d)
|
add_child(line_2d)
|
||||||
is_making_line = true
|
is_making_line = true
|
||||||
|
@ -288,6 +289,9 @@ func _process(delta : float) -> void:
|
||||||
handle_redo("Rectangle Select")
|
handle_redo("Rectangle Select")
|
||||||
|
|
||||||
previous_action = current_action
|
previous_action = current_action
|
||||||
|
previous_mouse_pos = current_pixel
|
||||||
|
previous_mouse_pos.x = clamp(previous_mouse_pos.x, location.x, location.x + size.x)
|
||||||
|
previous_mouse_pos.y = clamp(previous_mouse_pos.y, location.y, location.y + size.y)
|
||||||
if sprite_changed_this_frame:
|
if sprite_changed_this_frame:
|
||||||
update_texture(current_layer_index, (Input.is_action_just_released("left_mouse") || Input.is_action_just_released("right_mouse")))
|
update_texture(current_layer_index, (Input.is_action_just_released("left_mouse") || Input.is_action_just_released("right_mouse")))
|
||||||
|
|
||||||
|
@ -467,16 +471,16 @@ func generate_layer_panels() -> void:
|
||||||
|
|
||||||
func pencil_and_eraser(mouse_pos : Vector2, color : Color, current_mouse_button : String, current_action := "None") -> void:
|
func pencil_and_eraser(mouse_pos : Vector2, color : Color, current_mouse_button : String, current_action := "None") -> void:
|
||||||
if is_making_line:
|
if is_making_line:
|
||||||
fill_gaps(mouse_pos, color, current_mouse_button, current_action)
|
fill_gaps(mouse_pos, previous_mouse_pos_for_lines, color, current_mouse_button, current_action)
|
||||||
else:
|
else:
|
||||||
if point_in_rectangle(mouse_pos, location, location + size):
|
if point_in_rectangle(mouse_pos, location, location + size):
|
||||||
mouse_inside_canvas = true
|
mouse_inside_canvas = true
|
||||||
#Draw
|
#Draw
|
||||||
draw_pixel(mouse_pos, color, current_mouse_button, current_action)
|
draw_pixel(mouse_pos, color, current_mouse_button, current_action)
|
||||||
fill_gaps(mouse_pos, color, current_mouse_button, current_action) #Fill the gaps
|
fill_gaps(mouse_pos, previous_mouse_pos, color, current_mouse_button, current_action) #Fill the gaps
|
||||||
#If mouse is not inside bounds but it used to be, fill the gaps
|
#If mouse is not inside bounds but it used to be, fill the gaps
|
||||||
elif point_in_rectangle(previous_mouse_pos, location, location + size):
|
elif point_in_rectangle(previous_mouse_pos, location, location + size):
|
||||||
fill_gaps(mouse_pos, color, current_mouse_button, current_action)
|
fill_gaps(mouse_pos, previous_mouse_pos, color, current_mouse_button, current_action)
|
||||||
|
|
||||||
func draw_pixel(pos : Vector2, color : Color, current_mouse_button : String, current_action := "None") -> void:
|
func draw_pixel(pos : Vector2, color : Color, current_mouse_button : String, current_action := "None") -> void:
|
||||||
if Global.can_draw && Global.has_focus && Global.current_frame == frame:
|
if Global.can_draw && Global.has_focus && Global.current_frame == frame:
|
||||||
|
@ -649,16 +653,16 @@ func draw_pixel(pos : Vector2, color : Color, current_mouse_button : String, cur
|
||||||
layers[current_layer_index][0].lock()
|
layers[current_layer_index][0].lock()
|
||||||
sprite_changed_this_frame = true
|
sprite_changed_this_frame = true
|
||||||
|
|
||||||
previous_mouse_pos = current_pixel
|
previous_mouse_pos_for_lines = current_pixel
|
||||||
previous_mouse_pos.x = clamp(previous_mouse_pos.x, location.x, location.x + size.x)
|
previous_mouse_pos_for_lines.x = clamp(previous_mouse_pos_for_lines.x, location.x, location.x + size.x)
|
||||||
previous_mouse_pos.y = clamp(previous_mouse_pos.y, location.y, location.y + size.y)
|
previous_mouse_pos_for_lines.y = clamp(previous_mouse_pos_for_lines.y, location.y, location.y + size.y)
|
||||||
if is_making_line:
|
if is_making_line:
|
||||||
line_2d.set_point_position(0, previous_mouse_pos)
|
line_2d.set_point_position(0, previous_mouse_pos_for_lines)
|
||||||
|
|
||||||
#Bresenham's Algorithm
|
#Bresenham's Algorithm
|
||||||
#Thanks to https://godotengine.org/qa/35276/tile-based-line-drawing-algorithm-efficiency
|
#Thanks to https://godotengine.org/qa/35276/tile-based-line-drawing-algorithm-efficiency
|
||||||
func fill_gaps(mouse_pos : Vector2, color : Color, current_mouse_button : String, current_action := "None") -> void:
|
func fill_gaps(mouse_pos : Vector2, prev_mouse_pos : Vector2, color : Color, current_mouse_button : String, current_action := "None") -> void:
|
||||||
var previous_mouse_pos_floored = previous_mouse_pos.floor()
|
var previous_mouse_pos_floored = prev_mouse_pos.floor()
|
||||||
var mouse_pos_floored = mouse_pos.floor()
|
var mouse_pos_floored = mouse_pos.floor()
|
||||||
mouse_pos_floored.x = clamp(mouse_pos_floored.x, location.x - 1, location.x + size.x)
|
mouse_pos_floored.x = clamp(mouse_pos_floored.x, location.x - 1, location.x + size.x)
|
||||||
mouse_pos_floored.y = clamp(mouse_pos_floored.y, location.y - 1, location.y + size.y)
|
mouse_pos_floored.y = clamp(mouse_pos_floored.y, location.y - 1, location.y + size.y)
|
||||||
|
|
|
@ -179,6 +179,11 @@ right_colorpicker_tool={
|
||||||
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":true,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":79,"unicode":0,"echo":false,"script":null)
|
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":true,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":79,"unicode":0,"echo":false,"script":null)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
shift={
|
||||||
|
"deadzone": 0.5,
|
||||||
|
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777237,"unicode":0,"echo":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
[locale]
|
[locale]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue