Commits

Anonymous committed 165388d

Added copy module support for sdl.video.Surface instances.

Comments (0)

Files changed (2)

src/sdl/surface.c

 static PyObject* _surface_setalpha (PyObject *self, PyObject *args);
 static PyObject* _surface_convert (PyObject *self, PyObject *args,
     PyObject *kwds);
-static PyObject* _surface_copy (PyObject *self);
+static PyObject* _surface_copy (PyObject *self, PyObject *unused);
 static PyObject* _surface_blit (PyObject *self, PyObject *args, PyObject *kwds);
 static PyObject* _surface_fill (PyObject *self, PyObject *args, PyObject *kwds);
 static PyObject* _surface_save (PyObject *self, PyObject *args);
     { "save", _surface_save, METH_VARARGS, DOC_VIDEO_SURFACE_SAVE },
     { "scroll", (PyCFunction) _surface_scroll, METH_VARARGS | METH_KEYWORDS,
       DOC_VIDEO_SURFACE_SCROLL },
+    { "__copy__", (PyCFunction)_surface_copy, METH_NOARGS, NULL },
+    { "__deepcopy__", (PyCFunction)_surface_copy, METH_O, NULL },
     { NULL, NULL, 0, NULL }
 };
 
 }
 
 static PyObject*
-_surface_copy (PyObject *self)
+_surface_copy (PyObject *self, PyObject *unused)
 {
     return PySDLSurface_Copy (self);
 }

test/sdl_video_surface_test.py

 except ImportError:
     import io as stringio
 
+import copy
 import pygame2
 from pygame2.colorpalettes import CGAPALETTE
 from pygame2 import Rect, Color
             sf = video.Surface (10, 10, bpp)
             if bpp == 8:
                 sf.set_palette (CGAPALETTE)
+
             sfcopy = sf.copy ()
         
             self.assertEqual (sf.size, sfcopy.size)
             sf.fill (Color (200, 100, 0))
             sfcopy = sf.copy ()
             self._cmppixels (sf, sfcopy)
+
+            sfcopy2 = copy.copy (sf)
+            self.assertEqual (sf.size, sfcopy2.size)
+            self.assertEqual (sf.format.bits_per_pixel,
+                              sfcopy2.format.bits_per_pixel)
+            self.assertEqual (sf.format.masks, sfcopy2.format.masks)
+            self._cmppixels (sf, sfcopy2)
+
+            sfcopy3 = copy.deepcopy (sf)
+            self.assertEqual (sf.size, sfcopy3.size)
+            self.assertEqual (sf.format.bits_per_pixel,
+                              sfcopy3.format.bits_per_pixel)
+            self.assertEqual (sf.format.masks, sfcopy3.format.masks)
+            self._cmppixels (sf, sfcopy3)
+
         video.quit ()
 
     def test_pygame2_sdl_video_Surface_fill(self):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.