예제 #1
0
    def test_SDL_Color__copy__(self):
        c = SDL_Color()
        c2 = copy.copy(c)
        self.assertEqual(c, c2)

        c = SDL_Color(10, 20, 30)
        c2 = copy.copy(c)
        self.assertEqual(c, c2)
예제 #2
0
    def test_SDL_Color__copy__(self):
        c = SDL_Color()
        c2 = copy.copy(c)
        assert c == c2

        c = SDL_Color(10, 20, 30)
        c2 = copy.copy(c)
        assert c == c2
예제 #3
0
    def test_SDL_Color(self):
        c1 = SDL_Color()
        self.assertEqual((c1.r, c1.g, c1.b, c1.a), (0xFF, 0xFF, 0xFF, 0xFF))

        c1 = SDL_Color()
        c2 = SDL_Color()
        c3 = SDL_Color(0, 127, 255, 33)
        self.assertEqual(c1, c2)
        self.assertNotEqual(c1, c3)
예제 #4
0
    def test_SDL_Color(self):
        c1 = SDL_Color()
        assert (c1.r, c1.g, c1.b, c1.a) == (0xFF, 0xFF, 0xFF, 0xFF)

        c1 = SDL_Color()
        c2 = SDL_Color()
        c3 = SDL_Color(0, 127, 255, 33)
        assert c1 == c2
        assert c1 != c3
예제 #5
0
    def test_SDL_Color_a(self):
        c1 = SDL_Color()

        def seta(color, val):
            color.a = val

        for x in range(0, 255):
            c1.a = x
            self.assertEqual(c1.a, x)

        # TODO
        # self.assertRaises(ValueError, seta,  c1, -1)
        # self.assertRaises(ValueError, seta,  c1, 256)
        self.assertRaises(TypeError, seta, c1, "Test")
        self.assertRaises(TypeError, seta, c1, None)
예제 #6
0
 def test_SDL_Color__repr__(self):
     c1 = SDL_Color()
     self.assertEqual("SDL_Color(r=255, g=255, b=255, a=255)", repr(c1))
     c2 = eval(repr(c1))
     self.assertEqual(c2, c1)
     c3 = eval(repr(c2))
     self.assertEqual(c3, c2)
예제 #7
0
    def test_SDL_SetPaletteColors(self):
        colors = []
        for v in range(20):
            colors.append(SDL_Color(v, v + 10, v + 20))

        palette = pixels.SDL_AllocPalette(10)
        self.assertIsInstance(palette.contents, pixels.SDL_Palette)
        self.assertEqual(palette.contents.ncolors, 10)
        colors = palette.contents.colors
        for index in range(10):
            rgb = colors[index]
            self.assertEqual((rgb.r, rgb.g, rgb.b), (255, 255, 255))
        pixels.SDL_SetPaletteColors(palette, colors, 0, 10)
        for index in range(10):
            rgb = palette.contents.colors[index]
            self.assertEqual(rgb, colors[index])
        pixels.SDL_SetPaletteColors(palette, colors, 5, 1000)
        for index in range(10):
            rgb = palette.contents.colors[index]
            if index < 5:
                self.assertEqual(rgb, colors[index])
            elif index > 5:
                self.assertEqual(rgb, colors[index - 5])

        pixels.SDL_FreePalette(palette)
예제 #8
0
 def test_SDL_Color__repr__(self):
     c1 = SDL_Color()
     assert "SDL_Color(r=255, g=255, b=255, a=255)" == repr(c1)
     c2 = eval(repr(c1))
     assert c2 == c1
     c3 = eval(repr(c2))
     assert c3 == c2
예제 #9
0
    def test_SDL_SetPaletteColors(self):
        colors = []
        for v in range(20):
            colors.append(SDL_Color(v, v + 10, v + 20))

        palette = pixels.SDL_AllocPalette(10)
        assert isinstance(palette.contents, pixels.SDL_Palette)
        assert palette.contents.ncolors == 10
        colors = palette.contents.colors
        for index in range(10):
            rgb = colors[index]
            assert (rgb.r, rgb.g, rgb.b) == (255, 255, 255)
        pixels.SDL_SetPaletteColors(palette, colors, 0, 10)
        for index in range(10):
            rgb = palette.contents.colors[index]
            assert rgb == colors[index]
        pixels.SDL_SetPaletteColors(palette, colors, 5, 1000)
        for index in range(10):
            rgb = palette.contents.colors[index]
            if index < 5:
                assert rgb == colors[index]
            elif index > 5:
                assert rgb == colors[index - 5]

        pixels.SDL_FreePalette(palette)
예제 #10
0
    def test_SDL_Color_a(self):
        c1 = SDL_Color()

        def seta(color, val):
            color.a = val

        for x in range(0, 255):
            c1.a = x
            assert c1.a == x

        # TODO
        # self.assertRaises(ValueError, seta,  c1, -1)
        # self.assertRaises(ValueError, seta,  c1, 256)
        with pytest.raises(TypeError):
            seta(c1, "Test")
        with pytest.raises(TypeError):
            seta(c1, None)
예제 #11
0
 def render_text(self, text, color):
     '''
         wrapper for SDL2TFF method rendertextsolid
         Arguments:
             text - what you want the text to say
             color - color of the text
         Return:
             a sprite containing our text
     '''
     if sdl2.sdlttf.TTF_Init() == -1:
         print(sdl2.sdlttf.TTF_GetError())
     fname = Resources.get_path("Roboto-Regular.ttf")
     fname = ctypes.c_char_p(str.encode(fname))
     font = sdl2.sdlttf.TTF_OpenFont(fname, ctypes.c_int(12))
     text = ctypes.c_char_p(str.encode(str(text)))
     color = SDL_Color(*color)
     surface = sdl2.sdlttf.TTF_RenderUTF8_Solid(font, text, color)
     return self.factory.from_surface(surface, free=True)
예제 #12
0
path_resource = "res\\"
path_image = path_resource + "img\\"
path_font = path_resource + "font\\"
path_theme = path_image + "theme\\"
path_entity = path_image + "entity\\"
path_effect = path_image + "effect\\"
path_background = path_image + "bg\\"
path_ui = path_image + "ui\\"
path_map = path_resource + "maps\\"
path_audio = path_resource + "audio\\"
path_data = ".\\data\\"

# Colors
# 흑백
c_white = SDL_Color()
c_ltgray = SDL_Color(192, 192, 192)
c_gray = SDL_Color(128, 128, 128)
c_dkgray = SDL_Color(64, 64, 64)
c_black = SDL_Color(0, 0, 0)

# 적녹청
c_red = SDL_Color(255, 0, 0)
c_lime = SDL_Color(0, 255, 0)
c_green = SDL_Color(0, 128, 0)
c_blue = SDL_Color(0, 0, 255)

# 어두운 적녹청
c_maroon = SDL_Color(128, 0, 0)
c_dkrose = SDL_Color(64, 0, 0)
c_dkgreen = SDL_Color(0, 64, 0)
예제 #13
0
    def test_SDL_Color__ne__(self):
        self.assertTrue(SDL_Color(0, 0, 0, 0) != SDL_Color(255, 0, 0, 0))
        self.assertTrue(SDL_Color(0, 0, 0, 0) != SDL_Color(0, 255, 0, 0))
        self.assertTrue(SDL_Color(0, 0, 0, 0) != SDL_Color(0, 0, 255, 0))
        self.assertTrue(SDL_Color(0, 0, 0, 0) != SDL_Color(0, 0, 255, 0))
        self.assertTrue(SDL_Color(0, 0, 0, 0) != SDL_Color(0, 0, 0, 255))

        self.assertFalse(SDL_Color(255, 0, 0, 0) != SDL_Color(255, 0, 0, 0))
        self.assertFalse(SDL_Color(0, 255, 0, 0) != SDL_Color(0, 255, 0, 0))
        self.assertFalse(SDL_Color(0, 0, 255, 0) != SDL_Color(0, 0, 255, 0))
        self.assertFalse(SDL_Color(0, 0, 0, 255) != SDL_Color(0, 0, 0, 255))
예제 #14
0
    def test_SDL_Color__ne__(self):
        assert SDL_Color(0, 0, 0, 0) != SDL_Color(255, 0, 0, 0)
        assert SDL_Color(0, 0, 0, 0) != SDL_Color(0, 255, 0, 0)
        assert SDL_Color(0, 0, 0, 0) != SDL_Color(0, 0, 255, 0)
        assert SDL_Color(0, 0, 0, 0) != SDL_Color(0, 0, 255, 0)
        assert SDL_Color(0, 0, 0, 0) != SDL_Color(0, 0, 0, 255)

        assert not (SDL_Color(255, 0, 0, 0) != SDL_Color(255, 0, 0, 0))
        assert not (SDL_Color(0, 255, 0, 0) != SDL_Color(0, 255, 0, 0))
        assert not (SDL_Color(0, 0, 255, 0) != SDL_Color(0, 0, 255, 0))
        assert not (SDL_Color(0, 0, 0, 255) != SDL_Color(0, 0, 0, 255))
예제 #15
0
    def test_SDL_Color__eq__(self):
        assert SDL_Color(255, 0, 0, 0) == SDL_Color(255, 0, 0, 0)
        assert SDL_Color(0, 255, 0, 0) == SDL_Color(0, 255, 0, 0)
        assert SDL_Color(0, 0, 255, 0) == SDL_Color(0, 0, 255, 0)
        assert SDL_Color(0, 0, 0, 255) == SDL_Color(0, 0, 0, 255)
        assert SDL_Color(0, 0, 0, 0) == SDL_Color(0, 0, 0, 0)

        assert not (SDL_Color(0, 0, 0, 0) == SDL_Color(255, 0, 0, 0))
        assert not (SDL_Color(0, 0, 0, 0) == SDL_Color(0, 255, 0, 0))
        assert not (SDL_Color(0, 0, 0, 0) == SDL_Color(0, 0, 255, 0))
        assert not (SDL_Color(0, 0, 0, 0) == SDL_Color(0, 0, 0, 255))