2022-11-16 00:30:49 +01:00
|
|
|
tool
|
|
|
|
extends PaintCanvas
|
|
|
|
|
2022-11-16 14:18:00 +01:00
|
|
|
var _mouse_down : bool = false
|
|
|
|
|
|
|
|
func draw(local_position : Vector2) -> void:
|
2022-11-16 14:22:24 +01:00
|
|
|
var proj : PaintProject = get_paint_project()
|
|
|
|
|
|
|
|
if !proj:
|
|
|
|
print("!proj!")
|
|
|
|
|
|
|
|
set_pixel(local_position.x, local_position.y, proj.current_color)
|
2022-11-16 14:18:00 +01:00
|
|
|
|
|
|
|
func is_local(var pos : Vector2) -> bool:
|
|
|
|
if pos.x < 0 || pos.y < 0 || pos.x > size.x || pos.y > size.y:
|
|
|
|
return false
|
|
|
|
|
|
|
|
return true
|
2022-11-16 00:30:49 +01:00
|
|
|
|
|
|
|
func forward_canvas_gui_input(event: InputEvent) -> bool:
|
2022-11-16 14:18:00 +01:00
|
|
|
if event is InputEventMouseButton:
|
|
|
|
if event.button_index != BUTTON_LEFT:
|
|
|
|
return false
|
|
|
|
|
|
|
|
if _mouse_down:
|
|
|
|
if !event.pressed:
|
|
|
|
_mouse_down = false
|
|
|
|
else:
|
|
|
|
# This seems to be the easiest way to get local mouse position,
|
|
|
|
# even though the event is available
|
|
|
|
var local_position : Vector2 = get_local_mouse_position()
|
|
|
|
|
|
|
|
if is_local(local_position):
|
|
|
|
_mouse_down = true
|
|
|
|
return true
|
|
|
|
|
|
|
|
if _mouse_down && event is InputEventMouseMotion:
|
|
|
|
var local_position : Vector2 = get_local_mouse_position()
|
|
|
|
|
|
|
|
if is_local(local_position):
|
|
|
|
draw(local_position)
|
|
|
|
update_textures()
|
|
|
|
update()
|
|
|
|
return true
|
|
|
|
|
2022-11-16 00:30:49 +01:00
|
|
|
return false
|
2022-11-16 14:18:00 +01:00
|
|
|
|
|
|
|
func _ready() -> void:
|
|
|
|
#temp
|
|
|
|
resize(1, 1)
|
|
|
|
resize(128, 128)
|
|
|
|
|
|
|
|
func _draw() -> void:
|
|
|
|
draw_texture(get_image_texture(), Vector2())
|
|
|
|
draw_texture(get_preview_image_texture(), Vector2())
|