1. Marcus von Appen
  2. py-sdl2

Commits

Marcus von Appen  committed 3e32fac

- fixed sdl2.pixels.SDL_Color type
- fixed base type definitions in sdl2.stdinc

  • Participants
  • Parent commits 49a2c9a
  • Branches default

Comments (0)

Files changed (3)

File sdl2/pixels.py

View file
  • Ignore whitespace
     _fields_ = [("r", Uint8),
                 ("g", Uint8),
                 ("b", Uint8),
-                ("_unused", Uint8),
+                ("a", Uint8),
                 ]
 
-    def __init__(self, r=255, g=255, b=255):
+    def __init__(self, r=255, g=255, b=255, a=255):
         super(SDL_Color, self).__init__()
         self.r = r
         self.g = g
         self.b = b
-        self._unused = 0
+        self.a = a
 
     def __repr__(self):
-        return "SDL_Color(r=%d, g=%d, b=%d)" % (self.r, self.g, self.b)
+        return "SDL_Color(r=%d, g=%d, b=%d, a=%d)" % (self.r, self.g, self.b,
+                                                      self.a)
 
     def __copy__(self):
-        return SDL_Color(self.r, self.g, self.b)
+        return SDL_Color(self.r, self.g, self.b, self.a)
 
     def __deepcopy__(self, memo):
-        return SDL_Color(self.r, self.g, self.b)
+        return SDL_Color(self.r, self.g, self.b, self.a)
 
     def __eq__(self, color):
-        return self.r == color.r and self.g == color.g and self.b == color.b
+        return self.r == color.r and self.g == color.g and \
+            self.b == color.b and self.a == color.a
+    
+    def __ne__(self, color):
+        return self.r != color.r or self.g != color.g or self.b != color.b or \
+            self.a != color.a
 
-    def __ne__(self, color):
-        return self.r != color.r or self.g != color.g or self.b != color.b
 SDL_Colour = SDL_Color
 
 class SDL_Palette(Structure):

File sdl2/stdinc.py

View file
  • Ignore whitespace
 import sys
 from .dll import _bind
-from ctypes import c_int, c_byte, c_ubyte, c_ushort, c_short, c_uint, \
-    c_longlong, c_ulonglong, cdll, c_size_t, c_void_p, c_char_p
+from ctypes import c_int, c_int8, c_uint8, c_int16, c_uint16, c_int32, \
+    c_uint32, c_int64, c_uint64, cdll, c_size_t, c_void_p, c_char_p
 
 __all__ = ["SDL_FALSE", "SDL_TRUE", "SDL_bool", "Sint8", "Uint8", "Sint16",
            "Uint16", "Sint32", "Uint32", "Sint64", "Uint64", "SDL_malloc",
 SDL_TRUE = 1
 
 SDL_bool = c_int
-Sint8 = c_byte
-Uint8 = c_ubyte
-Sint16 = c_short
-Uint16 = c_ushort
-Sint32 = c_int
-Uint32 = c_uint
-Sint64 = c_longlong
-Uint64 = c_ulonglong
+Sint8 = c_int8
+Uint8 = c_uint8
+Sint16 = c_int16
+Uint16 = c_uint16
+Sint32 = c_int32
+Uint32 = c_uint32
+Sint64 = c_int64
+Uint64 = c_uint64
 
 _libc = None
 if sys.platform == "win32":

File sdl2/test/pixels_test.py

View file
  • Ignore whitespace
 
     def test_SDL_Color(self):
         c1 = SDL_Color()
-        self.assertEqual((c1.r, c1.g, c1.b), (0xFF, 0xFF, 0xFF))
+        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)
+        c3 = SDL_Color(0, 127, 255, 33)
         self.assertEqual(c1, c2)
         self.assertNotEqual(c1, c3)
 
     def test_SDL_Color__repr__(self):
         c1 = SDL_Color()
-        self.assertEqual("SDL_Color(r=255, g=255, b=255)", repr(c1))
+        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(c, c2)
 
     def test_SDL_Color__eq__(self):
-        self.assertTrue(SDL_Color(255, 0, 0) == SDL_Color(255, 0, 0))
-        self.assertTrue(SDL_Color(0, 255, 0) == SDL_Color(0, 255, 0))
-        self.assertTrue(SDL_Color(0, 0, 255) == SDL_Color(0, 0, 255))
-        self.assertTrue(SDL_Color(0, 0, 0) == SDL_Color(0, 0, 0))
+        self.assertTrue(SDL_Color(255, 0, 0, 0) == SDL_Color(255, 0, 0, 0))
+        self.assertTrue(SDL_Color(0, 255, 0, 0) == SDL_Color(0, 255, 0, 0))
+        self.assertTrue(SDL_Color(0, 0, 255, 0) == SDL_Color(0, 0, 255, 0))
+        self.assertTrue(SDL_Color(0, 0, 0, 255) == SDL_Color(0, 0, 0, 255))
+        self.assertTrue(SDL_Color(0, 0, 0, 0) == SDL_Color(0, 0, 0, 0))
 
-        self.assertFalse(SDL_Color(0, 0, 0) == SDL_Color(255, 0, 0))
-        self.assertFalse(SDL_Color(0, 0, 0) == SDL_Color(0, 255, 0))
-        self.assertFalse(SDL_Color(0, 0, 0) == SDL_Color(0, 0, 255))
+        self.assertFalse(SDL_Color(0, 0, 0, 0) == SDL_Color(255, 0, 0, 0))
+        self.assertFalse(SDL_Color(0, 0, 0, 0) == SDL_Color(0, 255, 0, 0))
+        self.assertFalse(SDL_Color(0, 0, 0, 0) == SDL_Color(0, 0, 255, 0))
+        self.assertFalse(SDL_Color(0, 0, 0, 0) == SDL_Color(0, 0, 0, 255))
 
     def test_SDL_Color__ne__(self):
-        self.assertTrue(SDL_Color(0, 0, 0) != SDL_Color(255, 0, 0))
-        self.assertTrue(SDL_Color(0, 0, 0) != SDL_Color(0, 255, 0))
-        self.assertTrue(SDL_Color(0, 0, 0) != SDL_Color(0, 0, 255))
+        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) != SDL_Color(255, 0, 0))
-        self.assertFalse(SDL_Color(0, 255, 0) != SDL_Color(0, 255, 0))
-        self.assertFalse(SDL_Color(0, 0, 255) != SDL_Color(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))
 
     def test_SDL_Color_r(self):
         c1 = SDL_Color()
         self.assertRaises(TypeError, setb, c1, "Test")
         self.assertRaises(TypeError, setb, c1, None)
 
+    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)
+
+
 if __name__ == '__main__':
     sys.exit(unittest.main())