Skip to content

Commit 4cdcf64

Browse files
committed
updated
1 parent 62d6a63 commit 4cdcf64

1 file changed

Lines changed: 19 additions & 8 deletions

File tree

dumbdisplay/ddlayer_multilevel.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,26 @@ def moveLevelAnchorBy(self, by_x: float, by_y: float, reach_in_millis: int = 0):
8686
self.dd._sendCommand(self.layer_id, DDC_movelevelanchorby, _DD_FLOAT_ARG(by_x), _DD_FLOAT_ARG(by_y), _DD_INT_ARG(reach_in_millis));
8787
else:
8888
self.dd._sendCommand(self.layer_id, DDC_movelevelanchorby, _DD_FLOAT_ARG(by_x), _DD_FLOAT_ARG(by_y))
89-
def setLevelRotation(self, angle: float, pivotX: float = 0, pivotY: float = 0):
90-
if angle == 0 and pivotX == 0 and pivotY == 0:
91-
self.dd._sendCommand(self.layer_id, DDC_setlevelrotate)
92-
elif pivotX == 0 and pivotY == 0:
93-
self.dd._sendCommand(self.layer_id, DDC_setlevelrotate, _DD_FLOAT_ARG(angle))
94-
elif pivotY == 0:
95-
self.dd._sendCommand(self.layer_id, DDC_setlevelrotate, _DD_FLOAT_ARG(angle), _DD_FLOAT_ARG(pivotX))
89+
def setLevelRotation(self, angle: float, pivot_x: float = 0, pivot_y: float = 0, reach_in_millis: int = 0):
90+
"""
91+
:param angle: rotation angle in degree; positive is clockwise
92+
:param pivot_x: x coordinate of the pivot point (relative to the level anchor)
93+
:param pivot_y: y coordinate of the pivot point (relative to the level anchor)
94+
"""
95+
if reach_in_millis > 0:
96+
self.dd._sendCommand(self.layer_id, DDC_setlevelrotate, _DD_FLOAT_ARG(angle), _DD_FLOAT_ARG(pivot_x), _DD_FLOAT_ARG(pivot_y), _DD_INT_ARG(reach_in_millis))
9697
else:
97-
self.dd._sendCommand(self.layer_id, DDC_setlevelrotate, _DD_FLOAT_ARG(angle), _DD_FLOAT_ARG(pivotX), _DD_FLOAT_ARG(pivotY))
98+
angle_is_zero = _DD_FLOAT_IS_ZERO(angle)
99+
pivot_x_is_zero = _DD_FLOAT_IS_ZERO(pivot_x)
100+
pivot_y_is_zero = _DD_FLOAT_IS_ZERO(pivot_y)
101+
if angle_is_zero:
102+
self.dd._sendCommand(self.layer_id, DDC_setlevelrotate)
103+
elif pivot_x_is_zero and pivot_y_is_zero:
104+
self.dd._sendCommand(self.layer_id, DDC_setlevelrotate, _DD_FLOAT_ARG(angle))
105+
elif pivot_y_is_zero:
106+
self.dd._sendCommand(self.layer_id, DDC_setlevelrotate, _DD_FLOAT_ARG(angle), _DD_FLOAT_ARG(pivot_x))
107+
else:
108+
self.dd._sendCommand(self.layer_id, DDC_setlevelrotate, _DD_FLOAT_ARG(angle), _DD_FLOAT_ARG(pivot_x), _DD_FLOAT_ARG(pivot_y))
98109
def registerLevelBackground(self, background_id: str, background_image_name: str, draw_background_options: str = ""):
99110
"""
100111
register an image for setting as level's background

0 commit comments

Comments
 (0)