Commits

Anonymous committed 8d83fca

rect updates

Comments (0)

Files changed (6)

 # BREAK = change breaks existing code
 # BUG   = fixed a bug that was crashing
 
+May 22, 2001
+	added midleft, midright, midtop, and midbottom to Rect
+	added Rect.unionall() function to union a list of Rects
+
 May 20, 2001
 	applied dave wallace's patch to fix memory freeing
 
 <a href=ref/Rect.html#move>Rect.move</a> - new rectangle with position changed<br>
 <a href=ref/Rect.html#normalize>Rect.normalize</a> - corrects negative sizes<br>
 <a href=ref/Rect.html#union>Rect.union</a> - rectangle covering both input<br>
+<a href=ref/Rect.html#unionall>Rect.unionall</a> - rectangle covering all inputs<br>
 <a href=ref/Sound.html#fadeout>Sound.fadeout</a> - fadeout all channels playing this sound<br>
 <a href=ref/Sound.html#get_num_channels>Sound.get_num_channels</a> - number of channels with sound<br>
 <a href=ref/Sound.html#get_volume>Sound.get_volume</a> - query volume for sound<br>

docs/ref/Rect.html

 modifiable members:
 top, bottom, left, right, topleft, topright,
 bottomleft, bottomright, size, width, height,
-center, centerx, centery. When changing these
-members, the rectangle will be moved to the given
-assignment. (except when changing the size, width,
-or height member, which will resize the rectangle
-around the center).
+center, centerx, centery, midleft, midright, midtop,
+midbottom. When changing thesemembers, the rectangle
+will be moved to the given assignment. (except when
+changing the size, width, or height member, which will
+resize the rectangle from the topleft corner)
 <br>&nbsp;<br>
 The rectstyle arguments used frequently with the
 Rect object (and elsewhere in pygame) is one of
 rectangle covering both input</td></tr>
 
 
+<tr><td><a href=#unionall>unionall</a></td><td> -
+rectangle covering all inputs</td></tr>
+
+
 </table>
 
 <hr>
 rectangle that is not covered by the inputs.
 </ul><br>&nbsp;<br>
 
+<a name=unionall><font size=+2><b>unionall
+</b></font><br><font size=+1><tt>
+Rect.unionall(sequence_of_rectstyles) -> Rect
+</tt></font><ul>
+Returns a new rectangle that completely covers all the
+given inputs. There may be area inside the new
+rectangle that is not covered by the inputs.
+</ul><br>&nbsp;<br>
+
 
 <hr>
 </body></html>

docs/ref/pygame_image.html

 <br>
 <h2 align=center>pygame.image</h2>
 This module contains functions to transfer images in and out
-of Surfaces. At the minimum the included <a href=pygame_mixer_music.html#load>load()</a> function will
+of Surfaces. At the minimum the included <a href=#load>load()</a> function will
 support BMP files. If SDL_image is properly installed when
 pygame is installed, it will support all the formats included
 with SDL_image. You can call the <a href=#get_extended>get_extended()</a> function to test
 if the SDL_image support is available.
 <br>&nbsp;<br>
 Some functions that communicate with other libraries will require
-that those libraries are properly installed. For example, the <a href=Surface.html#save>save()</a>
+that those libraries are properly installed. For example, the <a href=#save>save()</a>
 function can only save OPENGL surfaces if pyopengl is available.
 
 <hr>

docs/ref/pygame_mixer_music.html

 <br>&nbsp;<br>
 The music module has many of the same types of functions as the
 Sound objects. The main difference is only one music object can
-be loaded at a time, with the <a href=#load>load()</a> function. Music
+be loaded at a time, with the <a href=pygame_image.html#load>load()</a> function. Music
 must be stored in an individual file on the system, it cannot be
 loaded from special file-like objects through python.
 
 }
 
 
+    /*DOC*/ static char doc_unionall[] =
+    /*DOC*/    "Rect.unionall(sequence_of_rectstyles) -> Rect\n"
+    /*DOC*/    "rectangle covering all inputs\n"
+    /*DOC*/    "\n"
+    /*DOC*/    "Returns a new rectangle that completely covers all the\n"
+    /*DOC*/    "given inputs. There may be area inside the new\n"
+    /*DOC*/    "rectangle that is not covered by the inputs.\n"
+    /*DOC*/ ;
+
+static PyObject* rect_unionall(PyObject* oself, PyObject* args)
+{
+	PyRectObject* self = (PyRectObject*)oself;
+	GAME_Rect *argrect, temp;
+	int loop, size;
+	PyObject* list, *obj;
+	int t, l, b, r;
+
+	if(!PyArg_ParseTuple(args, "O", &list))
+		return NULL;
+	if(!PySequence_Check(list))
+		return RAISE(PyExc_TypeError, "Argument must be a sequence of rectstyle objects.");
+
+	l = self->r.x;
+	t = self->r.y;
+	r = self->r.x + self->r.w;
+	b = self->r.y + self->r.h;
+
+	size = PySequence_Length(list); /*warning, size could be -1 on error?*/
+	if(size < 1)
+		return PyRect_New4((short)l, (short)t, (short)(r-l), (short)(b-t));
+
+	for(loop = 0; loop < size; ++loop)
+	{
+		obj = PySequence_GetItem(list, loop);
+		if(!obj || !(argrect = GameRect_FromObject(obj, &temp)))
+		{
+			RAISE(PyExc_TypeError, "Argument must be a sequence of rectstyle objects.");
+			Py_XDECREF(obj);
+			break;
+		}
+		t = min(t, argrect->x);
+		l = min(l, argrect->y);
+		r = max(b, argrect->x+argrect->w);
+		b = max(b, argrect->y+argrect->h);
+		Py_DECREF(obj);
+	}
+
+	return PyRect_New4((short)l, (short)t, (short)(r-l), (short)(b-t));
+}
+
+
     /*DOC*/ static char doc_collidepoint[] =
     /*DOC*/    "Rect.collidepoint(x, y) -> bool\n"
     /*DOC*/    "point inside rectangle\n"
 	{"inflate",			(PyCFunction)rect_inflate,		1, doc_inflate},		
 	{"clip",			(PyCFunction)rect_clip,			1, doc_clip},
 	{"union",			(PyCFunction)rect_union,		1, doc_union},
+	{"unionall",		(PyCFunction)rect_unionall,		1, doc_unionall},
 	{"collidepoint",	(PyCFunction)rect_collidepoint,	1, doc_collidepoint},
 	{"colliderect",		(PyCFunction)rect_colliderect,	1, doc_colliderect},
 	{"collidelist",		(PyCFunction)rect_collidelist,	1, doc_collidelist},
 		ret = PyInt_FromLong(r->x+r->w/2);
 	else if(!strcmp(name, "centery"))
 		ret = PyInt_FromLong(r->y+r->h/2);
+
 	else if(!strcmp(name, "topleft"))
 		ret = Py_BuildValue("(ii)", r->x, r->y);
 	else if(!strcmp(name, "bottomleft"))
 		ret = Py_BuildValue("(ii)", r->w, r->h);
 	else if(!strcmp(name, "center"))
 		ret = Py_BuildValue("(ii)", r->x + r->w / 2, r->y + r->h / 2);
+
+	else if(!strcmp(name, "midleft"))
+		ret = Py_BuildValue("(ii)", r->x, r->y + r->h / 2);
+	else if(!strcmp(name, "midright"))
+		ret = Py_BuildValue("(ii)", r->x + r->w, r->y + r->h / 2);
+	else if(!strcmp(name, "midtop"))
+		ret = Py_BuildValue("(ii)", r->x + r->w / 2, r->y);
+	else if(!strcmp(name, "midbottom"))
+		ret = Py_BuildValue("(ii)", r->x + r->w / 2, r->y + r->h);
+	
 	else
 		ret = Py_FindMethod(rect_methods, (PyObject *)self, name);
 
 			ret = 0;
 		}
 	}
-	else
+
+	else if(!strcmp(name, "midleft"))
+	{
+		if(TwoShortsFromObj(op, &val1, &val2))
+		{
+			r->x = val1;
+			r->y += val2 - (r->y + r->h / 2);
+			ret = 0;
+		}
+	}
+	else if(!strcmp(name, "midright"))
+	{
+		if(TwoShortsFromObj(op, &val1, &val2))
+		{
+			r->x = val1 - r->w;
+			r->y += val2 - (r->y + r->h / 2);
+			ret = 0;
+		}
+	}
+	else if(!strcmp(name, "midtop"))
+	{
+		if(TwoShortsFromObj(op, &val1, &val2))
+		{
+			r->x += val1 - (r->x + r->w / 2);
+			r->y = val2;
+			ret = 0;
+		}
+	}
+	else if(!strcmp(name, "midbottom"))
+	{
+		if(TwoShortsFromObj(op, &val1, &val2))
+		{
+			r->x += val1 - (r->x + r->w / 2);
+			r->y = val2 - r->h;
+			ret = 0;
+		}
+	}
+	
+	else	
 	{
 		RAISE(PyExc_AttributeError, "Attribute cannot be modified");
 		return -1;
     /*DOC*/    "modifiable members:\n"
     /*DOC*/    "top, bottom, left, right, topleft, topright,\n"
     /*DOC*/    "bottomleft, bottomright, size, width, height,\n"
-    /*DOC*/    "center, centerx, centery. When changing these\n"
-    /*DOC*/    "members, the rectangle will be moved to the given\n"
-    /*DOC*/    "assignment. (except when changing the size, width,\n"
-    /*DOC*/    "or height member, which will resize the rectangle\n"
-    /*DOC*/    "around the center).\n"
+    /*DOC*/    "center, centerx, centery, midleft, midright, midtop,\n"
+	/*DOC*/    "midbottom. When changing thesemembers, the rectangle\n"
+    /*DOC*/    "will be moved to the given assignment. (except when\n"
+    /*DOC*/    "changing the size, width, or height member, which will\n"
+    /*DOC*/    "resize the rectangle from the topleft corner)\n"
     /*DOC*/    "\n"
     /*DOC*/    "The rectstyle arguments used frequently with the\n"
     /*DOC*/    "Rect object (and elsewhere in pygame) is one of\n"