|
| 1 | +from ._ddlayer import DDLayer |
| 2 | +from ._ddlayer import _DD_COLOR_ARG, _DD_BOOL_ARG, _DD_INT_ARG, _DD_FLOAT_ARG |
| 3 | + |
| 4 | +class DDLayerJoystick(DDLayer): |
| 5 | + '''Virtual joystick''' |
| 6 | + def __init__(self, dd, maxStickValue: int = 1023, directions: str = "", stickLookScaleFactor: float = 1.0): |
| 7 | + ''' |
| 8 | + :param dd: DumbDisplay object |
| 9 | + :param maxStickValue: the max value of the stick; e.g. 255 or 1023 (the default); min is 15 |
| 10 | + :param directions: "lr" or "hori": left-to-right; "tb" or "vert": top-to-bottom; "rl": right-to-left; "bt": bottom-to-top; |
| 11 | + use "+" combines the above like "lr+tb" to mean both directions; "" the same as "lr+tb" |
| 12 | + :param stickLookScaleFactor: the scaling factor of the stick (UI); 1 by default |
| 13 | + ''' |
| 14 | + layer_id = dd._createLayer("joystick", _DD_INT_ARG(maxStickValue), directions, _DD_FLOAT_ARG(stickLookScaleFactor)) |
| 15 | + super().__init__(dd, layer_id) |
| 16 | + def autoRecenter(self, auto_recenter: bool = True): |
| 17 | + self.dd._sendCommand(self.layer_id, "autorecenter", _DD_BOOL_ARG(auto_recenter)) |
| 18 | + def colors(self, stick_color: str, stick_outline_color: str, socket_color: str, socket_outline_color): |
| 19 | + self.dd._sendCommand(self.layer_id, "colors", _DD_COLOR_ARG(stick_color), _DD_COLOR_ARG(stick_outline_color), _DD_COLOR_ARG(socket_color), _DD_COLOR_ARG(socket_outline_color)) |
| 20 | + def moveToPos(self, x: int, y: int, send_feedback: bool = False): |
| 21 | + ''' |
| 22 | + move joystick position (if joystick is single directional, will only move in the movable direction) |
| 23 | + :param bg_color: "" means default |
| 24 | + :param x: x to move to |
| 25 | + :param y: y to move to |
| 26 | + :param send_feedback: if true, will send "feedback" for the move (regardless of the current position) |
| 27 | + ''' |
| 28 | + self.dd._sendCommand(self.layer_id, "movetopos", str(x), str(y), _DD_BOOL_ARG(send_feedback)) |
| 29 | + def moveToCenter(self, send_feedback: bool = False): |
| 30 | + ''' |
| 31 | + move joystick to the center |
| 32 | + :param send_feedback: if true, will send "feedback" for the move (regardless of the current position) |
| 33 | + ''' |
| 34 | + self.dd._sendCommand(self.layer_id, "movetocenter", _DD_BOOL_ARG(send_feedback)) |
| 35 | + |
| 36 | + |
0 commit comments