Commits

Anonymous committed 60f16a2

set_mode() affects previous display surfaces

  • Participants
  • Parent commits b0910af

Comments (0)

Files changed (3)

 # BREAK = change breaks existing code
 # BUG   = fixed a bug that was crashing
 
+June 24, 2001
+	calling set_mode will change all existing display surfaces too
+
 pygame-11
 Jun 23, 2001
 	removed smooth underline font render protection

File docs/ref/pygame_display.html

 Returns true if the current display is active on the screen. This
 done with the call to <a href=#set_mode>pygame.display.set_mode()</a>. It is
 potentially subject to the activity of a running window manager.
+<br>&nbsp;<br>
+Calling <a href=#set_mode>set_mode()</a> will change all existing display surface
+to reference the new display mode. The old display surface will
+be lost after this call.
 </ul><br>&nbsp;<br>
 
 <a name=get_caption><font size=+2><b>get_caption

File src/display.c

 
 staticforward PyTypeObject PyVidInfo_Type;
 static PyObject* PyVidInfo_New(const SDL_VideoInfo* info);
+static PyObject* DisplaySurfaceObject = NULL;
 
 #if 0
 /*quick internal test to see if gamma is supported*/
 
 
 /* init routines */
+static void display_autoquit(void)
+{
+	Py_XDECREF(DisplaySurfaceObject);
+	DisplaySurfaceObject = NULL;
+}
+
+static PyObject* display_autoinit(PyObject* self, PyObject* arg)
+{
+	PyGame_RegisterQuit(display_autoquit);
+	return PyInt_FromLong(1);
+}
 
 
     /*DOC*/ static char doc_quit[] =
 		return NULL;
 
 	PyGame_Video_AutoQuit();
+	display_autoquit();
 
 	RETURN_NONE
 }
 
 	if(!PyGame_Video_AutoInit())
 		return RAISE(PyExc_SDLError, SDL_GetError());
+	if(!display_autoinit(NULL, NULL))
+		return NULL;
 
 	RETURN_NONE
 }
     /*DOC*/    "Returns true if the current display is active on the screen. This\n"
     /*DOC*/    "done with the call to pygame.display.set_mode(). It is\n"
     /*DOC*/    "potentially subject to the activity of a running window manager.\n"
+    /*DOC*/    "\n"
+    /*DOC*/    "Calling set_mode() will change all existing display surface\n"
+    /*DOC*/    "to reference the new display mode. The old display surface will\n"
+    /*DOC*/    "be lost after this call.\n"
     /*DOC*/ ;
 
 static PyObject* get_active(PyObject* self, PyObject* arg)
 
 static PyObject* get_surface(PyObject* self, PyObject* arg)
 {
-	SDL_Surface* surf;
 	if(!PyArg_ParseTuple(arg, ""))
 		return NULL;
 
 	VIDEO_INIT_CHECK();
 
-	surf = SDL_GetVideoSurface();
-	if(!surf)
+	if(!DisplaySurfaceObject)
 		RETURN_NONE
 
-	return PySurface_New(surf);
+	Py_INCREF(DisplaySurfaceObject);
+	return DisplaySurfaceObject;
 }
 
 
 	/*probably won't do much, but can't hurt, and might help*/
 	SDL_PumpEvents();
 
-	return PySurface_New(surf);
+
+	if(DisplaySurfaceObject)
+	{
+		((PySurfaceObject*)DisplaySurfaceObject)->surf = surf;
+		Py_INCREF(DisplaySurfaceObject);
+	}
+	else
+	{
+		DisplaySurfaceObject = PySurface_New(surf);
+	}
+
+	return DisplaySurfaceObject;
 }
 
 
 
 static PyMethodDef display_builtins[] =
 {
+	{ "__PYGAMEinit__", display_autoinit, 1, doc_init },
 	{ "init", init, 1, doc_init },
 	{ "quit", quit, 1, doc_quit },
 	{ "get_init", get_init, 1, doc_get_init },