Пример #1
0
    def render(self, sprites, x=None, y=None):
        """Draws the passed sprites (or sprite) on the Window's surface.

        x and y are optional arguments that can be used as relative
        drawing location for sprites. If set to None, the location
        information of the sprites are used. If set and sprites is an
        iterable, such as a list of SoftwareSprite objects, x and y are relative
        location values that will be added to each individual sprite's
        position. If sprites is a single SoftwareSprite, x and y denote the
        absolute position of the SoftwareSprite, if set.
        """
        r = SDL_Rect(0, 0, 0, 0)
        if isiterable(sprites):
            blit_surface = sdlsurface.blit_surface
            surface = self.surface
            x = x or 0
            y = y or 0
            for sp in sprites:
                r.x = x + sp.x
                r.y = y + sp.y
                blit_surface(sp.surface, None, surface, r)
        else:
            r.x = x or sprites.x
            r.y = y or sprites.y
            sdlsurface.blit_surface(sprites.surface, None, self.surface, r)
        video.update_window_surface(self.window)
Пример #2
0
 def blit(self, src, dstrect, srcrect = None):
     """ ala pygame """
     if isinstance(src, SDL_Surface):
         src = rgba_surface(surface=src)           
     if len(dstrect) == 2:
         dstrect = SDL_Rect(dstrect[0], dstrect[1], src.w, src.h)
     else:
         dstrect = SDL_Rect(*dstrect)
     if srcrect is not None:
         srcrect = SDL_Rect(*srcrect)
     sdlsurface.blit_surface(src._surf, srcrect, self._surf, dstrect)
Пример #3
0
    def test_blit_surface(self):
        bpp = 32
        w, h = 10, 10
        # no alpha to prevent blending
        masks = (0xFF000000, 0x00FF0000, 0x0000FF00, 0x00000000)
        dest = surface.create_rgb_surface(w, h, bpp, masks[0], masks[1],
                                          masks[2], masks[3])
        pixelsize = h * dest.pitch
        rowlen = dest.pitch // 4

        sources = []
        for width, height in blitsizes:
            src = surface.create_rgb_surface(width, height, bpp, masks[0],
                                             masks[1], masks[2], masks[3])
            surface.fill_rect(src, None, 0xFFFFFFFF)  # fill with white
            sources.append(src)

        for src in sources:
            for pos in blitpositions:
                drect = pos.__copy__()
                surface.fill_rect(dest, None, 0x0)  # fill with black
                surface.blit_surface(src, None, dest, drect)
                buf = ctypes.cast(dest.pixels,
                                  ctypes.POINTER(ctypes.c_ubyte * pixelsize))
                pbuf = pgarray.CTypesView(buf.contents, itemsize=1,
                                          objsize=pixelsize)
                iview = pbuf.to_uint32()
                pw = drect.x + drect.w
                ph = drect.y + drect.h
                for y in range(dest.size[1]):
                    for x in range(dest.size[0]):
                        col = iview[y * rowlen + x]
                        if y >= drect.y and y < ph and \
                                x >= drect.x and x < pw:
                            self.assertEqual(col, 0xFFFFFFFF, msg="""color
mismatch at %d,%d for %s: %d != %d""" % (y, x, pos, col, 0xFFFFFFFF))
                        else:
                            self.assertEqual(col, 0x0, msg="""color mismatch
at %d,%d for %s: %d != %d""" % (y, x, pos, col, 0x0))

        while len(sources) > 0:
            sf = sources.pop()
            surface.free_surface(sf)
        surface.free_surface(dest)