Exemplo n.º 1
0
    def render(self, sprites, x=None, y=None):
        """Draws the passed sprites (or sprite).

        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 TextureSprite objects, x and y are
        relative location values that will be added to each individual
        sprite's position. If sprites is a single TextureSprite, x and y
        denote the absolute position of the TextureSprite, if set.
        """
        r = SDL_Rect(0, 0, 0, 0)
        if isiterable(sprites):
            rcopy = render.render_copy
            renderer = self.sdlrenderer
            x = x or 0
            y = y or 0
            for sp in sprites:
                r.x = x + sp.x
                r.y = y + sp.y
                r.w, r.h = sp.size
                rcopy(renderer, sp.texture, None, r)
        else:
            if x is None or y is None:
                r.x = sprites.x
                r.y = sprites.y
                r.w, r.h = sprites.size
            render.render_copy(self.sdlrenderer, sprites.texture, None, r)
        render.render_present(self.sdlrenderer)
Exemplo n.º 2
0
 def test_render_draw_point(self):
     points = ((-4, -3), (-4, 3), (4, -3),
               (0, 0), (1, 1), (10, 10), (99, 99),
               (4, 22), (57, 88), (45, 15),
               (100, 100)
               )
     r, g, b, a = 0xAA, 0xBB, 0xCC, 0xDD
     w, h = 100, 100
     sf = surface.create_rgb_surface(w, h, 32, 0xFF000000, 0x00FF0000,
                                     0x0000FF00, 0x000000FF)
     color = pixels.map_rgba(sf.format, r, g, b, a)
     renderer = render.create_software_renderer(sf)
     render.set_render_draw_color(renderer, r, g, b, a)
     for x, y in points:
         render.render_draw_point(renderer, x, y)
     render.render_present(renderer)
     view = pvid.PixelView(sf)
     for x, y in points:
         npx = max(x + 1, w)
         npy = max(y + 1, h)
         ppx = max(x - 1, 0)
         ppy = max(y - 1, 0)
         if x < 0 or x >= w or y < 0 or y >= h:
             continue
         self.assertEqual(hex(view[y][x]), hex(color))
         if (npx, npy) not in points:
             self.assertNotEqual(hex(view[npy][npx]), hex(color))
         if (ppx, ppy) not in points:
             self.assertNotEqual(hex(view[ppy][ppx]), hex(color))
     render.destroy_renderer(renderer)
     del view
     surface.free_surface(sf)
Exemplo n.º 3
0
 def present(self):
     """TODO"""
     render.render_present(self.renderer)