Пример #1
0
    def __init__(self, *args):

        if len(args) == 1:
            arg = args[0]
            if isinstance(arg, Rect):
                object.__setattr__(self, '_r', copy.copy(arg._r))
                return
            elif isinstance(arg, SDL.SDL_Rect):
                object.__setattr__(self, '_r', copy.copy(arg))
                return
            elif hasattr(arg, 'rect'):
                arg = arg.rect
                if callable(arg):
                    arg = arg()
                self.__init__(arg)
                return
            elif hasattr(arg, '__len__'):
                args = arg
            else:
                raise TypeError('Argument must be rect style object')
        if len(args) == 4:
            if args[2] < 0 or args[3] < 0:
                object.__setattr__(
                    self, '_r',
                    _RectProxy((int(args[0]), int(args[1]), int(args[2]),
                                int(args[3]))))
            else:
                object.__setattr__(
                    self, '_r',
                    SDL.SDL_Rect(int(args[0]), int(args[1]), int(args[2]),
                                 int(args[3])))
        elif len(args) == 2:
            if args[1][0] < 0 or args[1][1] < 0:
                object.__setattr__(
                    self, '_r',
                    _RectProxy((int(args[0][0]), int(args[0][1]),
                                int(args[1][0]), int(args[1][1]))))
            else:
                object.__setattr__(
                    self, '_r',
                    SDL.SDL_Rect(int(args[0][0]), int(args[0][1]),
                                 int(args[1][0]), int(args[1][1])))
        else:
            raise TypeError('Argument must be rect style object')
Пример #2
0
 def normalize(self):
     if self._r.w < 0:
         self._r.x += self._r.w
         self._r.w = -self._r.w
     if self._r.h < 0:
         self._r.y += self._r.h
         self._r.h = -self._r.h
     if isinstance(self._r, _RectProxy):
         object.__setattr__(
             self, '_r',
             SDL.SDL_Rect(self._r.x, self._r.y, self._r.w, self._r.h))
Пример #3
0
 def _get_as_parameter_(self):
     return SDL.SDL_Rect(self.x, self.y, self.w, self.h)