def draw(x0, x1, y0, y1): # Compute the coordinates of the left, right, top, and # bottom sides of the region, for both the source and # destination surfaces. # left side. if x0 >= 0: dx0 = x0 sx0 = x0 else: dx0 = dw + x0 sx0 = sw + x0 # right side. if x1 > 0: dx1 = x1 sx1 = x1 else: dx1 = dw + x1 sx1 = sw + x1 # top side. if y0 >= 0: dy0 = y0 sy0 = y0 else: dy0 = dh + y0 sy0 = sh + y0 # bottom side if y1 > 0: dy1 = y1 sy1 = y1 else: dy1 = dh + y1 sy1 = sh + y1 # Quick exit. if sx0 == sx1 or sy0 == sy1: return # Compute sizes. csw = sx1 - sx0 csh = sy1 - sy0 cdw = dx1 - dx0 cdh = dy1 - dy0 if csw <= 0 or csh <= 0 or cdh <= 0 or cdw <= 0: return # Get a subsurface. cr = crend.subsurface((sx0, sy0, csw, csh)) # Scale or tile if we have to. if csw != cdw or csh != cdh: if self.tile: newcr = Render(cdw, cdh) newcr.clipping = True for x in xrange(0, cdw, csw): for y in xrange(0, cdh, csh): newcr.blit(cr, (x, y)) cr = newcr else: newcr = Render(cdw, cdh) newcr.forward = Matrix2D(1.0 * csw / cdw, 0, 0, 1.0 * csh / cdh) newcr.reverse = Matrix2D(1.0 * cdw / csw, 0, 0, 1.0 * cdh / csh) newcr.blit(cr, (0, 0)) cr = newcr # Blit. rv.blit(cr, (dx0, dy0)) return