def test_TextureSprite(self):
        window = POINTER(SDL_Window)()
        renderer = POINTER(SDL_Renderer)()
        SDL_CreateWindowAndRenderer(10, 10, SDL_WINDOW_HIDDEN, byref(window),
                                    byref(renderer))

        tex = SDL_CreateTexture(renderer, 0, 0, 10, 10)
        self.assertIsInstance(tex.contents, SDL_Texture)
        sprite = sdl2ext.TextureSprite(tex.contents)
        self.assertIsInstance(sprite, sdl2ext.TextureSprite)
        SDL_DestroyRenderer(renderer)
        SDL_DestroyWindow(window)
        dogc()
 def test_TextureSprite_size(self):
     window = POINTER(SDL_Window)()
     renderer = POINTER(SDL_Renderer)()
     SDL_CreateWindowAndRenderer(10, 10, SDL_WINDOW_HIDDEN, byref(window),
                                 byref(renderer))
     for w in range(1, 200):
         for h in range(1, 200):
             tex = SDL_CreateTexture(renderer, 0, 0, w, h)
             self.assertIsInstance(tex.contents, SDL_Texture)
             sprite = sdl2ext.TextureSprite(tex.contents)
             self.assertIsInstance(sprite, sdl2ext.TextureSprite)
             self.assertEqual(sprite.size, (w, h))
             del sprite
     SDL_DestroyRenderer(renderer)
     SDL_DestroyWindow(window)
     dogc()
 def test_TextureSprite_position_xy(self):
     window = POINTER(SDL_Window)()
     renderer = POINTER(SDL_Renderer)()
     SDL_CreateWindowAndRenderer(10, 10, SDL_WINDOW_HIDDEN, byref(window),
                                 byref(renderer))
     tex = SDL_CreateTexture(renderer, 0, 0, 10, 10)
     self.assertIsInstance(tex.contents, SDL_Texture)
     sprite = sdl2ext.TextureSprite(tex.contents)
     self.assertIsInstance(sprite, sdl2ext.TextureSprite)
     self.assertEqual(sprite.position, (0, 0))
     positions = [(x, y) for x in range(-50, 50) for y in range(-50, 50)]
     for x, y in positions:
         sprite.position = x, y
         self.assertEqual(sprite.position, (x, y))
         sprite.x = x + 1
         sprite.y = y + 1
         self.assertEqual(sprite.position, (x + 1, y + 1))
     SDL_DestroyRenderer(renderer)
     SDL_DestroyWindow(window)
     dogc()
    def test_TextureSprite_area(self):
        window = POINTER(SDL_Window)()
        renderer = POINTER(SDL_Renderer)()
        SDL_CreateWindowAndRenderer(10, 10, SDL_WINDOW_HIDDEN, byref(window),
                                    byref(renderer))
        tex = SDL_CreateTexture(renderer, 0, 0, 10, 20)
        self.assertIsInstance(tex.contents, SDL_Texture)
        sprite = sdl2ext.TextureSprite(tex.contents)
        self.assertIsInstance(sprite, sdl2ext.TextureSprite)
        self.assertEqual(sprite.area, (0, 0, 10, 20))

        def setarea(s, v):
            s.area = v

        self.assertRaises(AttributeError, setarea, sprite, (1, 2, 3, 4))
        sprite.position = 7, 3
        self.assertEqual(sprite.area, (7, 3, 17, 23))
        sprite.position = -22, 99
        self.assertEqual(sprite.area, (-22, 99, -12, 119))
        SDL_DestroyRenderer(renderer)
        SDL_DestroyWindow(window)
        dogc()
Exemplo n.º 5
0
    def test_TextureSprite_area(self):
        window = POINTER(SDL_Window)()
        renderer = POINTER(SDL_Renderer)()
        SDL_CreateWindowAndRenderer(10, 10, SDL_WINDOW_HIDDEN, byref(window),
                                    byref(renderer))
        tex = SDL_CreateTexture(renderer, 0, 0, 10, 20)
        assert isinstance(tex.contents, SDL_Texture)
        sprite = sdl2ext.TextureSprite(tex.contents)
        assert isinstance(sprite, sdl2ext.TextureSprite)
        assert sprite.area == (0, 0, 10, 20)

        def setarea(s, v):
            s.area = v

        with pytest.raises(AttributeError):
            setarea(sprite, (1, 2, 3, 4))
        sprite.position = 7, 3
        assert sprite.area == (7, 3, 17, 23)
        sprite.position = -22, 99
        assert sprite.area == (-22, 99, -12, 119)
        SDL_DestroyRenderer(renderer)
        SDL_DestroyWindow(window)
        dogc()