Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ynsta/steamcontroller.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBuildTools <unconfigured@null.spigotmc.org>2015-12-09 00:04:53 +0300
committerBuildTools <unconfigured@null.spigotmc.org>2015-12-09 00:04:53 +0300
commitd2afb558c478d1f4d7ba6176dd1d997419037a5f (patch)
tree999dc4d26d6275471ac7e37d96f29e60026819f3
parentb9219c1e11de02866e4393065062d2b9f8c360ce (diff)
added callback mode and a simple example script
m---------local10
-rw-r--r--scripts/sc-callbacks.py4
-rw-r--r--src/events.py44
3 files changed, 46 insertions, 12 deletions
diff --git a/local b/local
-Subproject 074ccf2642b69173ac2c37767e15c65bff74eaf
+Subproject b9219c1e11de02866e4393065062d2b9f8c360c
diff --git a/scripts/sc-callbacks.py b/scripts/sc-callbacks.py
index bb279e5..4d234e8 100644
--- a/scripts/sc-callbacks.py
+++ b/scripts/sc-callbacks.py
@@ -55,8 +55,8 @@ def evminit():
evm.setButtonCallback(SCButtons.RGRIP, button_pressed_callback)
evm.setButtonCallback(SCButtons.START, button_pressed_callback)
evm.setButtonCallback(SCButtons.BACK, button_pressed_callback)
- evm.setPadButtonCallback(SCButtons.LPAD, touchpad_click_callback)
- evm.setPadButtonCallback(SCButtons.RPAD, touchpad_click_callback)
+ evm.setPadButtonCallback(Pos.LEFT, touchpad_click_callback)
+ evm.setPadButtonCallback(Pos.RIGHT, touchpad_click_callback)
return evm
diff --git a/src/events.py b/src/events.py
index 7b90f95..36f059f 100644
--- a/src/events.py
+++ b/src/events.py
@@ -50,6 +50,7 @@ class Modes(IntEnum):
GAMEPAD = 0
KEYBOARD = 1
MOUSE = 2
+ CALLBACK = 3
class PadModes(IntEnum):
"""Different possible pads modes"""
@@ -189,13 +190,16 @@ class EventMapper(object):
if mode is None:
continue
-
if btn & btn_add:
- _keypressed(mode, ev)
+ if mode is Modes.CALLBACK:
+ ev(self, btn, True)
+ else:
+ _keypressed(mode, ev)
elif btn & btn_rem:
- _keyreleased(mode, ev)
-
-
+ if mode is Modes.CALLBACK:
+ ev(self, btn, False)
+ else:
+ _keyreleased(mode, ev)
# Manage pads
for pos in [Pos.LEFT, Pos.RIGHT]:
@@ -442,6 +446,19 @@ class EventMapper(object):
self._btn_map[btn] = (mode, key_event)
return
+ def setButtonCallback(self, btn, callback):
+ """
+ set callback function to be executed when button is clicked
+ callback is called with parameters self(EventMapper), btn
+ and pushed (boollean True -> Button pressed, False -> Button released)
+
+ @param btn Button
+ @param callback Callback function
+ """
+
+ self._btn_map[btn] = (Modes.CALLBACK, callback)
+
+
def setPadButtons(self, pos, key_events, deadzone=0.6, clicked=False):
"""
Set pad as buttons
@@ -471,6 +488,23 @@ class EventMapper(object):
self._btn_map[SCButtons.LPAD] = (None, 0)
else:
self._btn_map[SCButtons.RPAD] = (None, 0)
+
+ def setPadButtonCallback(self, pos, callback, clicked=True):
+ """
+ set callback function to be executed when Pad clicked or touched
+
+ @param Pos pos designate left or right pad
+ @param callback Callback function
+ @param bool clicked callback on touch or on click event
+ """
+ if not clicked:
+ # FIXME: add touch support
+ raise NotImplementedError('Touch callbacks are not supported yet')
+ else:
+ if pos == Pos.LEFT:
+ self._btn_map[SCButtons.LPAD] = (Modes.CALLBACK, callback)
+ else:
+ self._btn_map[SCButtons.RPAD] = (Modes.CALLBACK, callback)
def setPadAxesAsButtons(self, pos, abs_events, deadzone=0.6, clicked=False, revert=True):
"""