Add .mirrorX() and .mirrorY() wrappers

These are especially useful for warpping callbacks.
This commit is contained in:
Florian Festi 2019-05-11 17:17:11 +02:00
parent 159db08c1c
commit 46157b2030
1 changed files with 26 additions and 0 deletions

View File

@ -2032,3 +2032,29 @@ class Boxes:
kw["move"] = "right only"
for i in range(width):
part(*l, **kw)
def mirrorX(self, f, offset=0.0):
"""Wrap a function to draw mirrored at the y axis
:param f: function to wrap
:param offset: (default value = 0.0) axis to mirror at
"""
def r():
self.moveTo(offset, 0)
with self.saved_context():
self.ctx.scale(-1, 1)
f()
return r
def mirrorY(self, f, offset=0.0):
"""Wrap a function to draw mirrored at the x axis
:param f: function to wrap
:param offset: (default value = 0.0) axis to mirror at
"""
def r():
self.moveTo(0, offset)
with self.saved_context():
self.ctx.scale(1, -1)
f()
return r