mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-31 07:29:49 +00:00
Alt to pick colors with draw tools - Closes #125
This commit is contained in:
parent
a9039cccd5
commit
4f02ea1b97
|
@ -108,6 +108,10 @@ func update_pattern() -> void:
|
|||
|
||||
|
||||
func draw_start(position : Vector2) -> void:
|
||||
if Input.is_action_pressed("alt"):
|
||||
_pick_color(position)
|
||||
return
|
||||
|
||||
Global.canvas.selection.transform_content_confirm()
|
||||
if !Global.current_project.layers[Global.current_project.current_layer].can_layer_get_drawn() or !Global.current_project.tile_mode_rects[Global.TileMode.NONE].has_point(position):
|
||||
return
|
||||
|
@ -247,3 +251,23 @@ func _get_undo_data() -> Dictionary:
|
|||
data[image] = image.data
|
||||
image.lock()
|
||||
return data
|
||||
|
||||
|
||||
func _pick_color(position : Vector2) -> void:
|
||||
var project : Project = Global.current_project
|
||||
if project.tile_mode and project.get_tile_mode_rect().has_point(position):
|
||||
position = position.posmodv(project.size)
|
||||
|
||||
if position.x < 0 or position.y < 0:
|
||||
return
|
||||
|
||||
var image := Image.new()
|
||||
image.copy_from(_get_draw_image())
|
||||
if position.x > image.get_width() - 1 or position.y > image.get_height() - 1:
|
||||
return
|
||||
|
||||
image.lock()
|
||||
var color := image.get_pixelv(position)
|
||||
image.unlock()
|
||||
var button := BUTTON_LEFT if Tools._slots[BUTTON_LEFT].tool_node == self else BUTTON_RIGHT
|
||||
Tools.assign_color(color, button, false)
|
||||
|
|
|
@ -7,6 +7,7 @@ var _brush_interpolate := 0
|
|||
var _brush_image := Image.new()
|
||||
var _brush_texture := ImageTexture.new()
|
||||
var _strength := 1.0
|
||||
var _picking_color := false
|
||||
|
||||
var _undo_data := {}
|
||||
var _drawer := Drawer.new()
|
||||
|
@ -526,3 +527,23 @@ func _get_undo_data() -> Dictionary:
|
|||
data[image] = image.data
|
||||
image.lock()
|
||||
return data
|
||||
|
||||
|
||||
func _pick_color(position : Vector2) -> void:
|
||||
var project : Project = Global.current_project
|
||||
if project.tile_mode and project.get_tile_mode_rect().has_point(position):
|
||||
position = position.posmodv(project.size)
|
||||
|
||||
if position.x < 0 or position.y < 0:
|
||||
return
|
||||
|
||||
var image := Image.new()
|
||||
image.copy_from(_get_draw_image())
|
||||
if position.x > image.get_width() - 1 or position.y > image.get_height() - 1:
|
||||
return
|
||||
|
||||
image.lock()
|
||||
var color := image.get_pixelv(position)
|
||||
image.unlock()
|
||||
var button := BUTTON_LEFT if Tools._slots[BUTTON_LEFT].tool_node == self else BUTTON_RIGHT
|
||||
Tools.assign_color(color, button, false)
|
||||
|
|
|
@ -35,6 +35,12 @@ func set_config(config : Dictionary) -> void:
|
|||
|
||||
|
||||
func draw_start(position : Vector2) -> void:
|
||||
if Input.is_action_pressed("alt"):
|
||||
_picking_color = true
|
||||
_pick_color(position)
|
||||
return
|
||||
_picking_color = false
|
||||
|
||||
Global.canvas.selection.transform_content_confirm()
|
||||
update_mask(_strength == 1)
|
||||
_changed = false
|
||||
|
@ -56,6 +62,11 @@ func draw_start(position : Vector2) -> void:
|
|||
|
||||
|
||||
func draw_move(position : Vector2) -> void:
|
||||
if _picking_color: # Still return even if we released Alt
|
||||
if Input.is_action_pressed("alt"):
|
||||
_pick_color(position)
|
||||
return
|
||||
|
||||
if _draw_line:
|
||||
var d = _line_angle_constraint(_line_start, position)
|
||||
_line_end = d.position
|
||||
|
@ -69,6 +80,9 @@ func draw_move(position : Vector2) -> void:
|
|||
|
||||
|
||||
func draw_end(_position : Vector2) -> void:
|
||||
if _picking_color:
|
||||
return
|
||||
|
||||
if _draw_line:
|
||||
draw_tool(_line_start)
|
||||
draw_fill_gap(_line_start, _line_end)
|
||||
|
|
|
@ -69,6 +69,12 @@ func _input(event : InputEvent) -> void:
|
|||
|
||||
|
||||
func draw_start(position : Vector2) -> void:
|
||||
if Input.is_action_pressed("alt"):
|
||||
_picking_color = true
|
||||
_pick_color(position)
|
||||
return
|
||||
_picking_color = false
|
||||
|
||||
Global.canvas.selection.transform_content_confirm()
|
||||
update_mask()
|
||||
|
||||
|
@ -80,6 +86,11 @@ func draw_start(position : Vector2) -> void:
|
|||
|
||||
|
||||
func draw_move(position : Vector2) -> void:
|
||||
if _picking_color: # Still return even if we released Alt
|
||||
if Input.is_action_pressed("alt"):
|
||||
_pick_color(position)
|
||||
return
|
||||
|
||||
if _drawing:
|
||||
if _displace_origin:
|
||||
_original_pos += position - _offset
|
||||
|
@ -94,6 +105,9 @@ func draw_move(position : Vector2) -> void:
|
|||
|
||||
|
||||
func draw_end(_position : Vector2) -> void:
|
||||
if _picking_color:
|
||||
return
|
||||
|
||||
if _drawing:
|
||||
_draw_shape()
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ var _overwrite := false
|
|||
var _fill_inside := false
|
||||
var _draw_points := Array()
|
||||
|
||||
|
||||
class PencilOp extends Drawer.ColorOp:
|
||||
var changed := false
|
||||
var overwrite := false
|
||||
|
@ -69,6 +70,12 @@ func update_config() -> void:
|
|||
|
||||
|
||||
func draw_start(position : Vector2) -> void:
|
||||
if Input.is_action_pressed("alt"):
|
||||
_picking_color = true
|
||||
_pick_color(position)
|
||||
return
|
||||
_picking_color = false
|
||||
|
||||
Global.canvas.selection.transform_content_confirm()
|
||||
update_mask()
|
||||
_changed = false
|
||||
|
@ -94,6 +101,11 @@ func draw_start(position : Vector2) -> void:
|
|||
|
||||
|
||||
func draw_move(position : Vector2) -> void:
|
||||
if _picking_color: # Still return even if we released Alt
|
||||
if Input.is_action_pressed("alt"):
|
||||
_pick_color(position)
|
||||
return
|
||||
|
||||
if _draw_line:
|
||||
var d = _line_angle_constraint(_line_start, position)
|
||||
_line_end = d.position
|
||||
|
@ -109,6 +121,9 @@ func draw_move(position : Vector2) -> void:
|
|||
|
||||
|
||||
func draw_end(_position : Vector2) -> void:
|
||||
if _picking_color:
|
||||
return
|
||||
|
||||
if _draw_line:
|
||||
draw_tool(_line_start)
|
||||
draw_fill_gap(_line_start, _line_end)
|
||||
|
|
|
@ -215,6 +215,12 @@ func update_strength() -> void:
|
|||
|
||||
|
||||
func draw_start(position : Vector2) -> void:
|
||||
if Input.is_action_pressed("alt"):
|
||||
_picking_color = true
|
||||
_pick_color(position)
|
||||
return
|
||||
_picking_color = false
|
||||
|
||||
Global.canvas.selection.transform_content_confirm()
|
||||
update_mask(false)
|
||||
_changed = false
|
||||
|
@ -236,6 +242,11 @@ func draw_start(position : Vector2) -> void:
|
|||
|
||||
|
||||
func draw_move(position : Vector2) -> void:
|
||||
if _picking_color: # Still return even if we released Alt
|
||||
if Input.is_action_pressed("alt"):
|
||||
_pick_color(position)
|
||||
return
|
||||
|
||||
if _draw_line:
|
||||
var d = _line_angle_constraint(_line_start, position)
|
||||
_line_end = d.position
|
||||
|
@ -249,6 +260,9 @@ func draw_move(position : Vector2) -> void:
|
|||
|
||||
|
||||
func draw_end(_position : Vector2) -> void:
|
||||
if _picking_color:
|
||||
return
|
||||
|
||||
if _draw_line:
|
||||
draw_tool(_line_start)
|
||||
draw_fill_gap(_line_start, _line_end)
|
||||
|
|
|
@ -84,6 +84,12 @@ func _input(event : InputEvent) -> void:
|
|||
|
||||
|
||||
func draw_start(position : Vector2) -> void:
|
||||
if Input.is_action_pressed("alt"):
|
||||
_picking_color = true
|
||||
_pick_color(position)
|
||||
return
|
||||
_picking_color = false
|
||||
|
||||
Global.canvas.selection.transform_content_confirm()
|
||||
update_mask()
|
||||
|
||||
|
@ -94,6 +100,11 @@ func draw_start(position : Vector2) -> void:
|
|||
|
||||
|
||||
func draw_move(position : Vector2) -> void:
|
||||
if _picking_color: # Still return even if we released Alt
|
||||
if Input.is_action_pressed("alt"):
|
||||
_pick_color(position)
|
||||
return
|
||||
|
||||
if _drawing:
|
||||
if _displace_origin:
|
||||
_start += position - _offset
|
||||
|
@ -103,6 +114,9 @@ func draw_move(position : Vector2) -> void:
|
|||
|
||||
|
||||
func draw_end(position : Vector2) -> void:
|
||||
if _picking_color:
|
||||
return
|
||||
|
||||
if _drawing:
|
||||
_draw_shape(_start, position)
|
||||
|
||||
|
|
Loading…
Reference in a new issue