1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-31 07:29:49 +00:00

Move cursor with numpad arrow keys, joy d-pad and left stick

Similar to GraphicsGale, you can now draw without moving the mouse. Although you still need the mouse for the left and right buttons, but I'd like to make give more options to the user as well so that they can activate tools using keyboard and joypad buttons, if they like.

The numpad arrow keys did nothing previously, so nothing changes for people who are not interested in this feature. They are also configurable thanks to the Keychain plugin.
This commit is contained in:
Emmanouil Papadeas 2022-05-16 21:49:07 +03:00
parent a98424e474
commit d028582f27
3 changed files with 57 additions and 14 deletions

View file

@ -714,6 +714,34 @@ camera_down={
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":3,"axis_value":1.0,"script":null)
]
}
move_mouse_left={
"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":16777354,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":14,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":-1.0,"script":null)
]
}
move_mouse_right={
"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":16777356,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":15,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":1.0,"script":null)
]
}
move_mouse_up={
"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":16777358,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":12,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":-1.0,"script":null)
]
}
move_mouse_down={
"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":16777352,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":13,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":1.0,"script":null)
]
}
[locale]

View file

@ -281,13 +281,17 @@ func _initialize_keychain() -> void:
Keychain.MenuInputAction.new("", "Select menu", true, "SelectMenu", SelectMenu.INVERT),
"open_docs":
Keychain.MenuInputAction.new("", "Help menu", true, "HelpMenu", HelpMenu.ONLINE_DOCS),
"zoom_in": Keychain.InputAction.new("", "General"),
"zoom_out": Keychain.InputAction.new("", "General"),
"camera_left": Keychain.InputAction.new("", "General"),
"camera_right": Keychain.InputAction.new("", "General"),
"camera_up": Keychain.InputAction.new("", "General"),
"camera_down": Keychain.InputAction.new("", "General"),
"pan": Keychain.InputAction.new("", "General"),
"zoom_in": Keychain.InputAction.new("", "Canvas"),
"zoom_out": Keychain.InputAction.new("", "Canvas"),
"camera_left": Keychain.InputAction.new("", "Canvas"),
"camera_right": Keychain.InputAction.new("", "Canvas"),
"camera_up": Keychain.InputAction.new("", "Canvas"),
"camera_down": Keychain.InputAction.new("", "Canvas"),
"pan": Keychain.InputAction.new("", "Canvas"),
"move_mouse_left": Keychain.InputAction.new("", "Cursor movement"),
"move_mouse_right": Keychain.InputAction.new("", "Cursor movement"),
"move_mouse_up": Keychain.InputAction.new("", "Cursor movement"),
"move_mouse_down": Keychain.InputAction.new("", "Cursor movement"),
"switch_colors": Keychain.InputAction.new("", "Buttons"),
"go_to_first_frame": Keychain.InputAction.new("", "Buttons"),
"go_to_last_frame": Keychain.InputAction.new("", "Buttons"),
@ -316,7 +320,8 @@ func _initialize_keychain() -> void:
}
Keychain.groups = {
"General": Keychain.InputGroup.new("", false),
"Canvas": Keychain.InputGroup.new("", false),
"Cursor movement": Keychain.InputGroup.new("Canvas"),
"Buttons": Keychain.InputGroup.new(),
"Tools": Keychain.InputGroup.new(),
"Left": Keychain.InputGroup.new("Tools"),

View file

@ -1,6 +1,9 @@
class_name Canvas
extends Node2D
const MOVE_ACTIONS := ["move_mouse_left", "move_mouse_right", "move_mouse_up", "move_mouse_down"]
const CURSOR_SPEED_RATE := 6.0
var current_pixel := Vector2.ZERO
var sprite_changed_this_frame := false # For optimization purposes
var move_preview_location := Vector2.ZERO
@ -57,18 +60,25 @@ func _draw() -> void:
func _input(event: InputEvent) -> void:
# Don't process anything below if the input isn't a mouse event, or Shift/Ctrl.
# This decreases CPU/GPU usage slightly.
var get_velocity := false
if not event is InputEventMouse:
if not event is InputEventKey:
for action in MOVE_ACTIONS:
if event.is_action(action):
get_velocity = true
if !get_velocity:
return
elif not event.scancode in [KEY_SHIFT, KEY_CONTROL]:
return
# elif not get_viewport_rect().has_point(event.position):
# return
var tmp_position: Vector2 = Global.main_viewport.get_local_mouse_position()
if get_velocity:
var velocity := Input.get_vector(
"move_mouse_left", "move_mouse_right", "move_mouse_up", "move_mouse_down"
)
if velocity != Vector2.ZERO:
tmp_position += velocity * CURSOR_SPEED_RATE
Global.main_viewport.warp_mouse(tmp_position)
# Do not use self.get_local_mouse_position() because it return unexpected
# value when shrink parameter is not equal to one. At godot version 3.2.3
var tmp_transform = get_canvas_transform().affine_inverse()
var tmp_position = Global.main_viewport.get_local_mouse_position()
current_pixel = tmp_transform.basis_xform(tmp_position) + tmp_transform.origin
if Global.has_focus: