1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-20 10:09:48 +00:00
Pixelorama/src/UI/ToolButtons.gd
DragonOfWar 943a69c0e3
Add Rectangle and Ellipse tools (#456)
* Add Shapes Tool (WIP)

* Add Alt button + Fill shape + Other stuff

* Add blue theme button textures

* Fix tool not previewing on right button

* Add config functions

* Fix ellipse bug

* Correctly added thickness

* Keep preview with CTRL

* Fix weird PoolVector behaviour

* Make preview follow mouse when pressing CTRL

* Moved shapes class to a separate script

* Update tooltip

* Enable mirrors

* Separate tools + jittery preview fix + more

* Add missing translation

* Add missing icons and keybindings

* Changed shape draw function buttons

Co-authored-by: DragonOfWar <47753585+KawanWeege@users.noreply.github.com>
2021-03-30 10:07:13 -07:00

44 lines
1.3 KiB
GDScript

extends VBoxContainer
# Node, shortcut
onready var tools := [
[$RectSelect, "rectangle_select"],
[$Zoom, "zoom"],
[$Pan, "pan"],
[$ColorPicker, "colorpicker"],
[$Pencil, "pencil"],
[$Eraser, "eraser"],
[$Bucket, "fill"],
[$LightenDarken, "lightdark"],
[$RectangleTool, "rectangletool"],
[$EllipseTool, "ellipsetool"],
]
func _ready() -> void:
for t in tools:
t[0].connect("pressed", self, "_on_Tool_pressed", [t[0]])
Global.update_hint_tooltips()
func _input(event : InputEvent) -> void:
if not Global.has_focus:
return
for action in ["undo", "redo", "redo_secondary"]:
if event.is_action_pressed(action):
return
for t in tools: # Handle tool shortcuts
if event.is_action_pressed("right_" + t[1] + "_tool") and !event.control: # Shortcut for right button (with Alt)
Tools.assign_tool(t[0].name, BUTTON_RIGHT)
elif event.is_action_pressed("left_" + t[1] + "_tool") and !event.control: # Shortcut for left button
Tools.assign_tool(t[0].name, BUTTON_LEFT)
func _on_Tool_pressed(tool_pressed : BaseButton) -> void:
var button := -1
button = BUTTON_LEFT if Input.is_action_just_released("left_mouse") else button
button = BUTTON_RIGHT if Input.is_action_just_released("right_mouse") else button
if button != -1:
Tools.assign_tool(tool_pressed.name, button)