Anonymous avatar Anonymous committed 64efe0e

blit can optionally accept rect as position arg

Comments (0)

Files changed (7)

docs/ref/Surface.html

 
 <a name=blit><font size=+2><b>blit
 </b></font><br><font size=+1><tt>
-Surface.blit(source, destoffset, [sourcerect]) -> Rect
+Surface.blit(source, destpos, [sourcerect]) -> Rect
 </tt></font><ul>
 The blitting will transfer one surface to another. It will
 respect any special modes like colorkeying and alpha. If hardware
 support is available, it will be used. The given source is the
 Surface to copy from. The destoffset is a 2-number-sequence that
-specifies where on the destination Surface the blit happens.
+specifies where on the destination Surface the blit happens (see below).
 When sourcerect isn't supplied, the blit will copy the
 entire source surface. If you would like to copy only a portion
 of the source, use the sourcerect argument to control
 <br>&nbsp;<br>
 The blit is subject to be clipped by the active clipping
 rectangle. The return value contains the actual area blitted.
+<br>&nbsp;<br>
+As a shortcut, the destination position can be passed as a
+rectangle. If a rectangle is given, the blit will use the topleft
+corner of the rectangle as the blit destination position. The
+rectangle sizes will be ignored.
 </ul><br>&nbsp;<br>
 
 <a name=convert><font size=+2><b>convert

docs/tut/ChimpLineByLine.html

 text = font.render("Pummel The Chimp, And Win $$$", 1, (20, 20, 20))
 textpos = text.get_rect()
 textpos.centerx = background.get_rect().centerx
-background.blit(text, textpos.topleft)
+background.blit(text, textpos)
 </td></tr></table><br>
 
 As you see, there are a couple steps to getting this done. First we
 
 <br><table border=1 bgcolor=#ddcc88><tr><td><pre>
 screen.blit(background, (0, 0))
-screen.blit(chimp, chimppos.topleft)
+screen.blit(chimp, chimppos)
 screen.blit(fist, fistpos)
 pygame.display.flip()
 </td></tr></table><br>

examples/aliens.py

     
     def draw(self, screen):
         "draws the sprite into the screen"
-        r = screen.blit(self.image, self.rect.topleft)
+        r = screen.blit(self.image, self.rect)
         dirtyrects.append(r.union(self.clearrect))
         
     def erase(self, screen, background):
         "gets the sprite off of the screen"
-        r = screen.blit(background, self.rect.topleft, self.rect)
+        r = screen.blit(background, self.rect, self.rect)
         self.clearrect = r
 
 
         text = f.render('Game Over', 1, (200, 200, 200))
         textrect = Rect((0, 0), text.get_size())
         textrect.center = SCREENRECT.center
-        screen.blit(text, textrect.topleft)
+        screen.blit(text, textrect)
         pygame.display.flip()
 
     #wait a beat

examples/chimp.py

     text = font.render("Pummel The Chimp, And Win $$$", 1, (10, 10, 10))
     textpos = text.get_rect()
     textpos.centerx = background.get_rect().centerx
-    background.blit(text, textpos.topleft)
+    background.blit(text, textpos)
 
 #Display The Background While Setup Finishes
     screen.blit(background, (0, 0))
 
     #Draw The Entire Scene
         screen.blit(background, (0, 0))
-        screen.blit(chimp, chimppos.topleft)
+        screen.blit(chimp, chimppos)
         screen.blit(fist, fistpos)
         pygame.display.flip()
 

examples/oldalien.py

     
     def draw(self, screen):
         "draws the sprite into the screen"
-        r = screen.blit(self.image, self.rect.topleft)
+        r = screen.blit(self.image, self.rect)
         dirtyrects.append(r)
         
     def erase(self, screen, background):
         "gets the sprite off of the screen"
-        r = screen.blit(background, self.rect.topleft, self.rect)
+        r = screen.blit(background, self.rect, self.rect)
         dirtyrects.append(r)
 
 
 
 	if(PyRect_Check(obj))
 		return &((PyRectObject*)obj)->r;
+
 	if(PySequence_Check(obj))
 	{
 		if(PySequence_Length(obj) == 4)
 		return NULL;
 
 	if(!pal)
-		return RAISE(PyExc_SDLError, "Surface is not palettized\n");
+		return RAISE(PyExc_SDLError, "Surface has no palette to get\n");
 
 	list = PyTuple_New(pal->ncolors);
 	if(!list)
 		return NULL;
 
 	if(!pal)
-		return RAISE(PyExc_SDLError, "Surface is not palettized\n");
+		return RAISE(PyExc_SDLError, "Surface has no palette to set\n");
 	if(index >= pal->ncolors || index < 0)
 		return RAISE(PyExc_IndexError, "index out of bounds");
 
 
 
     /*DOC*/ static char doc_surf_blit[] =
-    /*DOC*/    "Surface.blit(source, destoffset, [sourcerect]) -> Rect\n"
+    /*DOC*/    "Surface.blit(source, destpos, [sourcerect]) -> Rect\n"
     /*DOC*/    "copy a one Surface to another.\n"
     /*DOC*/    "\n"
     /*DOC*/    "The blitting will transfer one surface to another. It will\n"
     /*DOC*/    "respect any special modes like colorkeying and alpha. If hardware\n"
     /*DOC*/    "support is available, it will be used. The given source is the\n"
     /*DOC*/    "Surface to copy from. The destoffset is a 2-number-sequence that\n"
-    /*DOC*/    "specifies where on the destination Surface the blit happens.\n"
+    /*DOC*/    "specifies where on the destination Surface the blit happens (see below).\n"
     /*DOC*/    "When sourcerect isn't supplied, the blit will copy the\n"
     /*DOC*/    "entire source surface. If you would like to copy only a portion\n"
     /*DOC*/    "of the source, use the sourcerect argument to control\n"
     /*DOC*/    "\n"
     /*DOC*/    "The blit is subject to be clipped by the active clipping\n"
     /*DOC*/    "rectangle. The return value contains the actual area blitted.\n"
+    /*DOC*/    "\n"
+    /*DOC*/    "As a shortcut, the destination position can be passed as a\n"
+    /*DOC*/    "rectangle. If a rectangle is given, the blit will use the topleft\n"
+    /*DOC*/    "corner of the rectangle as the blit destination position. The\n"
+    /*DOC*/    "rectangle sizes will be ignored.\n"
     /*DOC*/ ;
 
 static PyObject* surf_blit(PyObject* self, PyObject* args)
 {
 	SDL_Surface* src, *dest = PySurface_AsSurface(self);
 	GAME_Rect* src_rect, temp;
-	PyObject* srcobject, *argrect = NULL;
+	PyObject* srcobject, *argpos, *argrect = NULL;
 	int dx, dy, result;
 	SDL_Rect dest_rect;
+	short sx, sy;
 
-	if(!PyArg_ParseTuple(args, "O!(ii)|O", &PySurface_Type, &srcobject, &dx, &dy, &argrect))
+	if(!PyArg_ParseTuple(args, "O!O|O", &PySurface_Type, &srcobject, &argpos, &argrect))
 		return NULL;
 	src = PySurface_AsSurface(srcobject);
 
+	if(src_rect = GameRect_FromObject(argpos, &temp))
+	{
+		dx = src_rect->x;
+		dy = src_rect->y;
+	}
+	else if(TwoShortsFromObj(argpos, &sx, &sy))
+	{
+		dx = (int)sx;
+		dy = (int)sy;
+	}
+	else
+		return RAISE(PyExc_TypeError, "invalid destination position for blit");
+
 	if(argrect)
 	{
 		if(!(src_rect = GameRect_FromObject(argrect, &temp)))
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.