1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-03-14 07:15:19 +00:00
Pixelorama/src/Tools/ColorPicker.gd
Grant Moyer aadad462b9
Add options for custom tile mode offest (#707)
* Add preferences for tile mode basis vectors

Each tile is offset according to the x and y basis. For example, a tile (1,1) would be at basis_x + basis_y

* Update tools for custom tile modes

Show the indicator in the correct position, and only draw on the nearest tile.

* Fix style issues

* Move tile functionality to own class to prevent bloating Project

* Fix error in Tiles bounding box logic

* Make tile mode offsets project settings

Since the desired tile mode offsets depends on the tile being drawn, the tile mode offsets should be a project specific setting which is persisted in the project file.

* Update TileMode object immediately after closing dialog

* Don't draw center tile by default in TileMode

* Move tile mode offsets to view menu

* Move tile mode offsets dialog out of ImageEffects
2022-06-20 12:07:20 +03:00

70 lines
1.5 KiB
GDScript

extends BaseTool
var _prev_mode := 0
var _color_slot := 0
func _input(event: InputEvent) -> void:
var options: OptionButton = $ColorPicker/Options
if event.is_action_pressed("change_tool_mode"):
_prev_mode = options.selected
if event.is_action("change_tool_mode"):
options.selected = _prev_mode ^ 1
_color_slot = options.selected
if event.is_action_released("change_tool_mode"):
options.selected = _prev_mode
_color_slot = options.selected
func _on_Options_item_selected(id: int) -> void:
_color_slot = id
update_config()
save_config()
func get_config() -> Dictionary:
return {
"color_slot": _color_slot,
}
func set_config(config: Dictionary) -> void:
_color_slot = config.get("color_slot", _color_slot)
func update_config() -> void:
$ColorPicker/Options.selected = _color_slot
func draw_start(position: Vector2) -> void:
.draw_start(position)
_pick_color(position)
func draw_move(position: Vector2) -> void:
.draw_move(position)
_pick_color(position)
func draw_end(position: Vector2) -> void:
.draw_end(position)
func _pick_color(position: Vector2) -> void:
var project: Project = Global.current_project
position = project.tiles.get_canon_position(position)
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 _color_slot == 0 else BUTTON_RIGHT
Tools.assign_color(color, button, false)