@@ -127,6 +127,54 @@ window_destroy(pgWindowObject *self, PyObject *_null)
127
127
Py_RETURN_NONE ;
128
128
}
129
129
130
+ static PyObject *
131
+ window_get_surface (pgWindowObject * self )
132
+ {
133
+ PyObject * surf = NULL ;
134
+ SDL_Surface * _surf = SDL_GetWindowSurface (self -> _win );
135
+ if (!_surf ) {
136
+ return RAISE (pgExc_SDLError , SDL_GetError ());
137
+ }
138
+ surf = (PyObject * )pgSurface_New2 (_surf , SDL_FALSE );
139
+ if (!surf ) {
140
+ return NULL ;
141
+ }
142
+ Py_INCREF (surf );
143
+ Py_XDECREF (self -> surf );
144
+ self -> surf = (pgSurfaceObject * )surf ;
145
+ Py_INCREF (surf );
146
+ return surf ;
147
+ }
148
+
149
+ static PyObject *
150
+ window_update_from_surface (pgWindowObject * self , PyObject * const * args ,
151
+ Py_ssize_t nargs )
152
+ {
153
+ int i ;
154
+ SDL_Rect * rects = NULL , tmp , * r ;
155
+ if (nargs == 0 ) {
156
+ if (SDL_UpdateWindowSurface (self -> _win )) {
157
+ return RAISE (pgExc_SDLError , SDL_GetError ());
158
+ }
159
+ }
160
+ else {
161
+ rects = malloc (nargs * sizeof (SDL_Rect ));
162
+ for (i = 0 ; i < nargs ; i ++ ) {
163
+ r = pgRect_FromObject (args [i ], & tmp );
164
+ if (!r ) {
165
+ return RAISE (PyExc_TypeError ,
166
+ "Arguments must be rect or rect-like objects." );
167
+ }
168
+ rects [i ] = * r ;
169
+ if (SDL_UpdateWindowSurfaceRects (self -> _win , rects , (int )nargs )) {
170
+ return RAISE (pgExc_SDLError , SDL_GetError ());
171
+ }
172
+ }
173
+ free (rects );
174
+ }
175
+ Py_RETURN_NONE ;
176
+ }
177
+
130
178
static PyObject *
131
179
window_set_windowed (pgWindowObject * self , PyObject * _null )
132
180
{
@@ -739,6 +787,7 @@ window_init(pgWindowObject *self, PyObject *args, PyObject *kwargs)
739
787
}
740
788
self -> _win = _win ;
741
789
self -> _is_borrowed = SDL_FALSE ;
790
+ self -> surf = NULL ;
742
791
743
792
SDL_SetWindowData (_win , "pg_window" , self );
744
793
@@ -827,6 +876,9 @@ static PyMethodDef window_methods[] = {
827
876
DOC_SDL2_VIDEO_WINDOW_SETMODALFOR },
828
877
{"set_icon" , (PyCFunction )window_set_icon , METH_O ,
829
878
DOC_SDL2_VIDEO_WINDOW_SETICON },
879
+ {"update_from_surface" , (PyCFunction )window_update_from_surface ,
880
+ METH_FASTCALL , "docs" },
881
+ {"get_surface" , (PyCFunction )window_get_surface , METH_NOARGS , "docs" },
830
882
{"from_display_module" , (PyCFunction )window_from_display_module ,
831
883
METH_CLASS | METH_NOARGS , DOC_SDL2_VIDEO_WINDOW_FROMDISPLAYMODULE },
832
884
{NULL , NULL , 0 , NULL }};
0 commit comments