def test_fill_rects(self): rectlist = (rect.SDL_Rect(0, 0, 0, 0), rect.SDL_Rect(0, 0, 10, 10), rect.SDL_Rect(0, 0, -10, 10), rect.SDL_Rect(0, 0, -10, -10), rect.SDL_Rect(-10, -10, 10, 10), rect.SDL_Rect(10, -10, 10, 10), rect.SDL_Rect(10, 10, 10, 10), ) for fmt in pixels.ALL_PIXELFORMATS: if pixels.SDL_ISPIXELFORMAT_FOURCC(fmt): continue if pixels.SDL_BITSPERPIXEL(fmt) < 8: continue # Skip < 8bpp, SDL_FillRect does not work on those for w in range(1, 100, 5): for h in range(1, 100, 5): bpp, rmask, gmask, bmask, amask = \ pixels.pixelformat_enum_to_masks(fmt) sf = surface.create_rgb_surface(w, h, bpp, rmask, gmask, bmask, amask) self.assertIsInstance(sf, surface.SDL_Surface) # TODO: check for changed pixels surface.fill_rects(sf, rectlist, 0xff00ff00) surface.free_surface(sf)
def fill(target, color, area=None): """Fills a certain rectangular area on the passed target with a color. If no area is provided, the entire target will be filled with the passed color. If an iterable item is provided as area (such as a list or tuple), it will be first checked, if the item denotes a single rectangular area (4 integer values) before assuming it to be a sequence of rectangular areas. """ color = prepare_color(color, target) rtarget = _get_target_surface(target) varea = None if area is not None and isiterable(area): # can be either a single rect or a list of rects) if len(area) == 4: # is it a rect? try: varea = rect.SDL_Rect(int(area[0]), int(area[1]), int(area[2]), int(area[3])) except: # No, not a rect, assume a seq of rects. pass if not varea: # len(area) == 4 AND varea set. varea = [] for r in area: varea.append(rect.SDL_Rect(r[0], r[1], r[2], r[3])) if varea is None or isinstance(varea, rect.SDL_Rect): sdlsurface.fill_rect(rtarget, varea, color) else: sdlsurface.fill_rects(rtarget, varea, color)