Commits

Anonymous committed c911377

colors can be mapped ints

  • Participants
  • Parent commits 2e81e0b

Comments (0)

Files changed (5)

 # BREAK = change breaks existing code
 # BUG   = fixed a bug that was crashing
 
+Jan 31, 2001
+	functions taking RGBA colors can also accept mapped ints
+
 Jan 30, 2001
 	added draw.lines()
 

File docs/ref/Surface.html

 value. If no destination rectangle is supplied, it will fill the
 entire Surface.
 <br>&nbsp;<br>
+The color argument can be a RGBA sequence or a mapped color integer.
+<br>&nbsp;<br>
 The fill is subject to be clipped by the active clipping
 rectangle. The return value contains the actual area filled.
 </ul><br>&nbsp;<br>
 </b></font><br><font size=+1><tt>
 Surface.set_at([x, y], RGBA) -> None
 </tt></font><ul>
-Assigns RGBA color to the image at the give position.
+Assigns color to the image at the give position. Color can be a
+RGBA sequence or a mapped color integer.
 <br>&nbsp;<br>
 In some situations just using the <a href=#fill>fill()</a> function with a one-pixel
 sized rectangle will be quicker. Also the fill function does not
 
 <a name=set_colorkey><font size=+2><b>set_colorkey
 </b></font><br><font size=+1><tt>
-Surface.set_colorkey([RGBA, [flags]]) -> None
+Surface.set_colorkey([color, [flags]]) -> None
 </tt></font><ul>
 Set the colorkey for the surface by passing a mapped color value
 as the color argument. If no arguments are passed, colorkeying
 will be disabled for this surface.
 <br>&nbsp;<br>
+The color argument can be either a RGBA sequence or a mapped integer.
+<br>&nbsp;<br>
 If your image is nonchanging and will be used repeatedly, you
 will probably want to pass the RLEACCEL flag to the call. This
 will take a short time to compile your surface, and increase the

File docs/ref/pygame_draw.html

 rectangle. A bounding box of the effected area is returned
 as a rectangle.
 <br>&nbsp;<br>
+The color argument can be either a RGB sequence or mapped color integer.
+<br>&nbsp;<br>
 This function will temporarily lock the surface.
 </ul><br>&nbsp;<br>
 
 This will respect the clipping rectangle. A bounding box of the
 effected area is returned as a rectangle.
 <br>&nbsp;<br>
+The color argument can be either a RGB sequence or mapped color integer.
+<br>&nbsp;<br>
 This function will temporarily lock the surface.
 </ul><br>&nbsp;<br>
 
     /*DOC*/    "rectangle. A bounding box of the effected area is returned\n"
     /*DOC*/    "as a rectangle.\n"
     /*DOC*/    "\n"
+    /*DOC*/    "The color argument can be either a RGB sequence or mapped color integer.\n"
+    /*DOC*/    "\n"
     /*DOC*/    "This function will temporarily lock the surface.\n"
     /*DOC*/ ;
 
 	if(surf->format->BytesPerPixel <= 0 || surf->format->BytesPerPixel > 4)
 		return RAISE(PyExc_ValueError, "unsupport bit depth for line draw");
 
-	if(!RGBAFromObj(colorobj, rgba))
-		return RAISE(PyExc_TypeError, "Invalid color RGB argument");
-	color = SDL_MapRGBA(surf->format, rgba[0], rgba[1], rgba[2], rgba[3]);
+	if(PyInt_Check(colorobj))
+		color = (Uint32)PyInt_AsLong(colorobj);
+	else if(RGBAFromObj(colorobj, rgba))
+		color = SDL_MapRGBA(surf->format, rgba[0], rgba[1], rgba[2], rgba[3]);
+	else
+		return RAISE(PyExc_TypeError, "invalid color argument");
 
 	if(!TwoShortsFromObj(start, &startx, &starty))
 		return RAISE(PyExc_TypeError, "Invalid start position argument");
 	/*DOC*/    "This will respect the clipping rectangle. A bounding box of the\n"
 	/*DOC*/    "effected area is returned as a rectangle.\n"
     /*DOC*/    "\n"
+    /*DOC*/    "The color argument can be either a RGB sequence or mapped color integer.\n"
+    /*DOC*/    "\n"
     /*DOC*/    "This function will temporarily lock the surface.\n"
     /*DOC*/ ;
 
 	if(surf->format->BytesPerPixel <= 0 || surf->format->BytesPerPixel > 4)
 		return RAISE(PyExc_ValueError, "unsupport bit depth for line draw");
 
-	if(!RGBAFromObj(colorobj, rgba))
-		return RAISE(PyExc_TypeError, "Invalid color RGB argument");
-	color = SDL_MapRGBA(surf->format, rgba[0], rgba[1], rgba[2], rgba[3]);
+	if(PyInt_Check(colorobj))
+		color = (Uint32)PyInt_AsLong(colorobj);
+	else if(RGBAFromObj(colorobj, rgba))
+		color = SDL_MapRGBA(surf->format, rgba[0], rgba[1], rgba[2], rgba[3]);
+	else
+		return RAISE(PyExc_TypeError, "invalid color argument");
 
 	closed = PyObject_IsTrue(closedobj);
 

File src/surface.c

     /*DOC*/    "Surface.set_at([x, y], RGBA) -> None\n"
     /*DOC*/    "set pixel at given position\n"
     /*DOC*/    "\n"
-    /*DOC*/    "Assigns RGBA color to the image at the give position.\n"
+    /*DOC*/    "Assigns color to the image at the give position. Color can be a\n"
+    /*DOC*/    "RGBA sequence or a mapped color integer.\n"
     /*DOC*/    "\n"
     /*DOC*/    "In some situations just using the fill() function with a one-pixel\n"
     /*DOC*/    "sized rectangle will be quicker. Also the fill function does not\n"
 	if(format->BytesPerPixel < 1 || format->BytesPerPixel > 4)
 		return RAISE(PyExc_RuntimeError, "invalid color depth for surface");
 
-	if(!RGBAFromObj(rgba_obj, rgba))
-		return RAISE(PyExc_TypeError, "Invalid RGBA object");
-	color = SDL_MapRGBA(surf->format, rgba[0], rgba[1], rgba[2], rgba[3]);
+	if(PyInt_Check(rgba_obj))
+		color = (Uint32)PyInt_AsLong(rgba_obj);
+	else if(RGBAFromObj(rgba_obj, rgba))
+		color = SDL_MapRGBA(surf->format, rgba[0], rgba[1], rgba[2], rgba[3]);
+	else
+		return RAISE(PyExc_TypeError, "invalid color argument");
 
 	if(!PySurface_Lock(self)) return NULL;
 	pixels = (Uint8*)surf->pixels;
 
 
     /*DOC*/ static char doc_surf_set_colorkey[] =
-    /*DOC*/    "Surface.set_colorkey([RGBA, [flags]]) -> None\n"
+    /*DOC*/    "Surface.set_colorkey([color, [flags]]) -> None\n"
     /*DOC*/    "change colorkey information\n"
     /*DOC*/    "\n"
     /*DOC*/    "Set the colorkey for the surface by passing a mapped color value\n"
     /*DOC*/    "as the color argument. If no arguments are passed, colorkeying\n"
     /*DOC*/    "will be disabled for this surface.\n"
     /*DOC*/    "\n"
+    /*DOC*/    "The color argument can be either a RGBA sequence or a mapped integer.\n"
+    /*DOC*/    "\n"
     /*DOC*/    "If your image is nonchanging and will be used repeatedly, you\n"
     /*DOC*/    "will probably want to pass the RLEACCEL flag to the call. This\n"
     /*DOC*/    "will take a short time to compile your surface, and increase the\n"
 static PyObject* surf_set_colorkey(PyObject* self, PyObject* args)
 {
 	SDL_Surface* surf = PySurface_AsSurface(self);
-	Uint32 flags = 0, key = 0;
+	Uint32 flags = 0, color = 0;
 	PyObject* rgba_obj = NULL;
 	Uint8 rgba[4];
 	int result;
 	if(!PyArg_ParseTuple(args, "|Oi", &rgba_obj, &flags))
 		return NULL;
 
-	if(rgba_obj)
-	{
-		if(!RGBAFromObj(rgba_obj, rgba))
-			return RAISE(PyExc_TypeError, "Invalid RGBA argument");
-		key = SDL_MapRGBA(surf->format, rgba[0], rgba[1], rgba[2], rgba[3]);
-	}
+	if(PyInt_Check(rgba_obj))
+		color = (Uint32)PyInt_AsLong(rgba_obj);
+	else if(RGBAFromObj(rgba_obj, rgba))
+		color = SDL_MapRGBA(surf->format, rgba[0], rgba[1], rgba[2], rgba[3]);
+	else
+		return RAISE(PyExc_TypeError, "invalid color argument");
 
 	if(PyTuple_Size(args) > 0)
 		flags |= SDL_SRCCOLORKEY;
 
 	PySurface_Prep(self);
-	result = SDL_SetColorKey(surf, flags, key);
+	result = SDL_SetColorKey(surf, flags, color);
 	PySurface_Unprep(self);
 
 	if(result == -1)
     /*DOC*/    "value. If no destination rectangle is supplied, it will fill the\n"
     /*DOC*/    "entire Surface.\n"
     /*DOC*/    "\n"
+    /*DOC*/    "The color argument can be a RGBA sequence or a mapped color integer.\n"
+    /*DOC*/    "\n"
     /*DOC*/    "The fill is subject to be clipped by the active clipping\n"
     /*DOC*/    "rectangle. The return value contains the actual area filled.\n"
     /*DOC*/ ;
 	if(!PyArg_ParseTuple(args, "O|O", &rgba_obj, &r))
 		return NULL;
 
-	if(!RGBAFromObj(rgba_obj, rgba))
-		return RAISE(PyExc_TypeError, "Invalid RGBA argument");
-	color = SDL_MapRGBA(surf->format, rgba[0], rgba[1], rgba[2], rgba[3]);
+	if(PyInt_Check(rgba_obj))
+		color = (Uint32)PyInt_AsLong(rgba_obj);
+	else if(RGBAFromObj(rgba_obj, rgba))
+		color = SDL_MapRGBA(surf->format, rgba[0], rgba[1], rgba[2], rgba[3]);
+	else
+		return RAISE(PyExc_TypeError, "invalid color argument");
 
 	if(!r)
 	{