From 46157b2030c75112ee8cf70eba6a03c3fe21bbc0 Mon Sep 17 00:00:00 2001 From: Florian Festi Date: Sat, 11 May 2019 17:17:11 +0200 Subject: [PATCH] Add .mirrorX() and .mirrorY() wrappers These are especially useful for warpping callbacks. --- boxes/__init__.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/boxes/__init__.py b/boxes/__init__.py index e372f4a..a9744db 100755 --- a/boxes/__init__.py +++ b/boxes/__init__.py @@ -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