diff --git a/pygwin/rect.py b/pygwin/rect.py index 875f5a9..a5a2503 100644 --- a/pygwin/rect.py +++ b/pygwin/rect.py @@ -24,11 +24,7 @@ class rect: pass return locals() height = property(**height()) - def contains(self, xorect, y=None): - if type(xorect) == rect and y == None: - return pg.Rect(self.x,self.y, - self.w,self.h).contains(pg.Rect( - xorect.x,xorect.y,xorect.w,xorect.h)) - elif type(xorect) != rect and y != None: - return pg.Rect(self.x,self.y,self.w, - self.h).collidepoint((xorect,y)) + def collide(self, x): + return pg.Rect(self.x,self.y,self.w,self.h).colliderect(pg.Rect(x.x,x.y,x.w,x.h)) + def contains(self, x, y): + return pg.Rect(self.x,self.y,self.w,self.h).collidepoint(x,y) diff --git a/pygwin/surface.py b/pygwin/surface.py index b91083e..8605ab3 100644 --- a/pygwin/surface.py +++ b/pygwin/surface.py @@ -1,3 +1,4 @@ +from pygwin.rect import rect as _r from pygwin._pg import pg as _pg class surface: @@ -69,6 +70,13 @@ class surface: self._orig = _pg.transform.smoothscale(self._orig,scale) self._orig = _pg.transform.smoothscale(self._orig,self._orig.get_size()) return self.copy() + def rect(self, x=0, y=0, center=None): + if center == None: + return _r(x, y, self.size[0], self.size[1]) + else: + return _r(center[0]-(self.size[0]/2), + center[1]-(self.size[1]/2), + self.size[0], self.size[1]) class _draw: def __init__(self,surface): self._surf = surface