1# Copyright 2004-2021 Tom Rothamel <pytom@bishoujo.us>
2#
3# Permission is hereby granted, free of charge, to any person
4# obtaining a copy of this software and associated documentation files
5# (the "Software"), to deal in the Software without restriction,
6# including without limitation the rights to use, copy, modify, merge,
7# publish, distribute, sublicense, and/or sell copies of the Software,
8# and to permit persons to whom the Software is furnished to do so,
9# subject to the following conditions:
10#
11# The above copyright notice and this permission notice shall be
12# included in all copies or substantial portions of the Software.
13#
14# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22# This contains wrappers for the various Transform classes. It uses some
23# of the classes in 00matrixcolor.rpy.
24
25init -1400 python:
26
27
28    class TransformMatrix(_BaseMatrix):
29        """
30        :undocumented:
31        """
32
33        function = None
34        nargs = 0
35
36
37        def __init__(self, *args):
38            if len(args) != self.nargs:
39                raise Exception("{} takes {} arguments, {} given.".format(type(self).__name__, self.nargs, len(args)))
40
41            self.args = args
42
43
44        def __call__(self, other, done):
45
46            if type(other) is not type(self):
47                return self.function(*self.args)
48            else:
49                args = tuple(a + (b - a) * done for a, b in zip(other.args, self.args))
50                return self.function(*args)
51
52        @staticmethod
53        def _document(function):
54            if not function:
55                return ":undocumented:"
56
57            rv = function.__doc__
58
59            rv = rv.replace(":doc: matrix", ":doc: transform_matrix")
60            rv = rv.replace("Returns", "A TransformMatrix that returns")
61
62            return rv
63
64
65    class OffsetMatrix(TransformMatrix):
66        nargs = 3
67        function = Matrix.offset
68        __doc__ = TransformMatrix._document(Matrix.offset)
69
70    class RotateMatrix(TransformMatrix):
71        nargs = 3
72        function = Matrix.rotate
73        __doc__ = TransformMatrix._document(Matrix.rotate)
74
75    class ScaleMatrix(TransformMatrix):
76        nargs = 3
77        function = Matrix.scale
78        __doc__ = TransformMatrix._document(Matrix.scale)
79
80