Author: ArcRiley Date: 2008-03-05 13:50:20 -0500 (Wed, 05 Mar 2008) New Revision: 1046
Modified: trunk/pysoy/src/_core/Screen-w32.pxi trunk/pysoy/src/_core/Screen-x11.pxi Log: Ticket #901 : * updated Screen (x11 and w32) for new Children API * some minor code cleanup and commenting Modified: trunk/pysoy/src/_core/Screen-w32.pxi =================================================================== --- trunk/pysoy/src/_core/Screen-w32.pxi 2008-03-05 16:48:44 UTC (rev 1045) +++ trunk/pysoy/src/_core/Screen-w32.pxi 2008-03-05 18:50:20 UTC (rev 1046) @@ -1,143 +1,148 @@ -# PySoy Screen Class for Win32 -# -# Copyright (C) 2006,2007,2008 PySoy Group -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, see http://www.gnu.org/licenses -# -# $Id$ - -cdef soy._internals.Children _screens -#cdef windows.HDC _display -_screens = soy._internals.Children() -#_display = NULL - -from support cimport get_screen_info - -cdef class Screen : - '''Screen Class - - An instance of this class for every useable screen is added to - soy.screens when PySoy is first imported. - - Screen objects may only be created and destroyed by soy.screens - ''' - def __cinit__(self, sId=-1) : - if type(sId) == int and sId == 0 or sId == -1: - self._screenID = 0 - else: - raise('Only one screen is available on Windows at this time.') - self._fullScreen = None - _screens.lock() - if _screens.current: - _screens.unlock() - raise ValueError('The screen has already been opened.') - _screens._append(<void *>self) - _screens.unlock() - - def __dealloc__(self) : - _screens.lock() - if _screens.current == 0: - _screens.unlock() - return - _screens.remove(<void *>self) - _screens.unlock() - - def __repr__(self) : - return '<Screen>' - - property size : - def __get__(self): - cdef int width, height, depth - get_screen_info(&width, &height, &depth) - return (width, height) - - property depth : - def __get__(self) : - cdef int width, height, depth - get_screen_info(&width, &height, &depth) - return depth - - property fullscreen : - def __get__(self) : - return self._fullScreen - def __set__(self, value) : - cdef Window _fsWin - cdef int width, height, depth - if value == None : - if self._fullScreen : - #_windows.lock() - _fsWin = <Window> self._fullScreen - _fsWin._request_destroy() - self._fullScreen = None - _fsWin._request_create(0, 0, _fsWin._savedWidth, _fsWin._savedHeight) - #_windows.unlock() - elif isinstance(value, Window) : - if value == self._fullScreen : - return - #_windows.lock() - if self._fullScreen : - _fsWin = <Window> self._fullScreen - _fsWin._request_destroy() - self._fullScreen = None - _fsWin._request_create(0, 0, _fsWin._savedWidth, _fsWin._savedHeight) - #stdio.printf("fullscreen.__set__: Entering\n") - _fsWin = <Window> value - _fsWin._request_destroy() - #stdio.printf("fullscreen.__set__: Window destroyed\n") - _windows.lock() - self._fullScreen = _fsWin - _fsWin._savedWidth = _fsWin._width - _fsWin._savedHeight = _fsWin._height - get_screen_info(&width, &height, &depth) - _windows.unlock() - #stdio.printf("Sending new window request\n") - _fsWin._request_create(0, 0, width, height) - #stdio.printf("New window request sent\n") - #_windows.unlock() - else : - raise TypeError('must be instance of Window or None') - - - property version : - def __get__(self) : - if self._glVersion : - return 'OpenGL v1.%d' % self._glVersion - else : - return 'Unknown - open a Window first' - - cdef void _coreGlewInit(self) : - gl.glewInit() - if gl.glewIsSupported("GL_VERSION_1_4") : - self._glVersion = 4 - elif gl.glewIsSupported("GL_VERSION_1_3") : - self._glVersion = 3 - elif gl.glewIsSupported("GL_VERSION_1_2") : - self._glVersion = 2 - elif gl.glewIsSupported("GL_VERSION_1_1") : - self._glVersion = 1 - - cdef void _events(self) : - cdef int i - cdef windows.MSG msg - cdef windows.HWND hwnd - _windows.lock() - while windows.PeekMessage(&msg, NULL, 0, 0, windows.PM_REMOVE): - windows.TranslateMessage(&msg) - windows.DispatchMessage(&msg) - _windows.unlock() - -# vim: sts=2:sw=2:et - -# !DIRTY: 41-46 -# !DIRTY: 49-54 +# PySoy Screen Class for Win32 +# +# Copyright (C) 2006,2007,2008 PySoy Group +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, see http://www.gnu.org/licenses +# +# $Id$ + +cdef soy._internals.Children _screens +#cdef windows.HDC _display +_screens = soy._internals.Children() +#_display = NULL + +from support cimport get_screen_info + +cdef class Screen : + '''Screen Class + + An instance of this class for every useable screen is added to + soy.screens when PySoy is first imported. + + Screen objects may only be created and destroyed by soy.screens + ''' + def __cinit__(self, sId=-1) : + if type(sId) == int and sId == 0 or sId == -1 : + self._screenID = 0 + else: + raise('Only one screen is available on Windows at this time.') + self._fullScreen = None + if _screens._current : + raise ValueError('The screen has already been opened.') + _screens._append(<void *> self) + + + def __dealloc__(self) : + if _screens._current == 0 : + return + _screens._remove(<void *> self) + + + def __repr__(self) : + return '<Screen>' + + + property size : + def __get__(self): + cdef int _width, _height, _depth + get_screen_info(&_width, &_height, &_depth) + return (_width, _height) + + + property depth : + def __get__(self) : + cdef int _width, _height, _depth + get_screen_info(&_width, &_height, &_depth) + return _depth + + + property fullscreen : + def __get__(self) : + return self._fullScreen + + def __set__(self, value) : + cdef Window _fsWin + cdef int _width, _height, _depth + # + # Type check + if value != None and not isinstance(value, Window) : + raise TypeError('must be instance of Window or None') + # + # If we're resetting fullscreen to the same window, do nothing. + if value == self._fullScreen : + return + # + # Since it's changing, clear the old fullscreen window now + if self._fullScreen : + # RenderLock + _fsWin = <Window> self._fullScreen + _fsWin._request_destroy() + self._fullScreen = None + _fsWin._request_create(0, 0, _fsWin._savedWidth, _fsWin._savedHeight) + # RenderUnLock + # + # If just turning off fullscreen mode, we've already finished + if value == None : + return + # + # Now destroy this window ... + _fsWin = <Window> value + _fsWin._request_destroy() + # + # ... and recreate it as a fullscreen window + # RenderLock + self._fullScreen = _fsWin + _fsWin._savedWidth = _fsWin._width + _fsWin._savedHeight = _fsWin._height + get_screen_info(&width, &height, &depth) + # RenderUnLock + _fsWin._request_create(0, 0, width, height) + #_windows.unlock() + + + property version : + def __get__(self) : + if self._glVersion : + return 'OpenGL v1.%d' % self._glVersion + else : + return 'Unknown - open a Window first' + + + cdef void _coreGlewInit(self) : + gl.glewInit() + if gl.glewIsSupported("GL_VERSION_1_5") : + self._glVersion = 5 + elif gl.glewIsSupported("GL_VERSION_1_4") : + self._glVersion = 4 + elif gl.glewIsSupported("GL_VERSION_1_3") : + self._glVersion = 3 + elif gl.glewIsSupported("GL_VERSION_1_2") : + self._glVersion = 2 + elif gl.glewIsSupported("GL_VERSION_1_1") : + self._glVersion = 1 + + + cdef void _events(self) : + cdef windows.MSG _msg + # + # DEBUG: does this really need locking? does the MSWindows API require + # that you do nothing else while processing events? + # + #_windows.lock() + while windows.PeekMessage (&_msg, NULL, 0, 0, windows.PM_REMOVE) : + windows.TranslateMessage(&_msg) + windows.DispatchMessage (&_msg) + #_windows.unlock() + +# vim: sts=2:sw=2:et Modified: trunk/pysoy/src/_core/Screen-x11.pxi =================================================================== --- trunk/pysoy/src/_core/Screen-x11.pxi 2008-03-05 16:48:44 UTC (rev 1045) +++ trunk/pysoy/src/_core/Screen-x11.pxi 2008-03-05 18:50:20 UTC (rev 1046) @@ -33,8 +33,8 @@ Screen objects may only be created and destroyed by soy.screens ''' - def __cinit__(self, sId=-1) : - cdef int i, _modeNum + def __cinit__(self, _sId=-1) : + cdef int _i, _modeNum cdef int _glxAttrs[16] cdef glx.XF86VidModeModeInfo **_modes cdef glx.XSetWindowAttributes _winAttr @@ -42,24 +42,24 @@ global _glxContext # # If the display hasn't been opened already - _screens.lock() + _screens.iterStart() if _display==NULL : _display = glx.XOpenDisplay(NULL) if _display==NULL : _screens.unlock() raise SystemError('Could not open display') - if type(sId)==int and sId<0 : - sId = glx.DefaultScreen(_display) - if type(sId)==int and sId>=0 and sId<glx.ScreenCount(_display) : - for i from 0 <= i < _screens.current : - if (<Screen> _screens.list[i])._screenID == sId : + if type(_sId)==int and _sId<0 : + _sId = glx.DefaultScreen(_display) + if type(_sId)==int and _sId>=0 and _sId<glx.ScreenCount(_display) : + for _i from 0 <= _i < _screens._current : + if (<Screen> _screens._list[_i])._screenID == _sId : _screens.unlock() raise ValueError('This screen has already been opened') - self._screen = glx.ScreenOfDisplay(_display, sId) - self._screenID = sId + self._screen = glx.ScreenOfDisplay(_display, _sId) + self._screenID = _sId else : _screens.unlock() - raise('Requested screen %d not available' % sId) + raise('Requested screen %d not available' % _sId) self._wmDelWin = glx.XInternAtom(_display, "WM_DELETE_WINDOW", 0) _glxAttrs[0] = glx.GLX_RGBA _glxAttrs[1] = glx.GLX_DOUBLEBUFFER @@ -74,9 +74,9 @@ _glxAttrs[10] = glx.GLX_STENCIL_SIZE _glxAttrs[11] = 8 _glxAttrs[12] = 0 - self._xVisualInfo = glx.glXChooseVisual(_display, sId, _glxAttrs) + self._xVisualInfo = glx.glXChooseVisual(_display, _sId, _glxAttrs) if self._xVisualInfo == NULL : - _screens.unlock() + _screens.iterDone() raise SystemError('Screen cannot support PySoy') if _glxContext == NULL : _glxContext = glx.glXCreateContext(_display, self._xVisualInfo, @@ -89,24 +89,23 @@ glx.RootWindowOfScreen(self._screen), glx.CWEventMask, &_winAttr) glx.XFlush(_display) - _screens.append(<void *>self) - _screens.unlock() + _screens.iterDone() + _screens._append(<void *> self) + def __dealloc__(self) : global _display if self._screen == NULL : - if _screens.current == 0 : + if _screens._current == 0 : # When the first attempted screen open failed glx.XCloseDisplay(_display) _display = NULL return - _screens.lock() - _screens.remove(<void *>self) - if _screens.current == 0 : + _screens._remove(<void *> self) + if _screens._current == 0 : # When the last screen is closed.. glx.XCloseDisplay(_display) _display = NULL - _screens.unlock() def __repr__(self) : return '<Screen>' @@ -169,7 +168,7 @@ self._glVersion = 1 cdef void _events(self) : - cdef int i + cdef int _i cdef glx.XEvent _event cdef glx.KeySym _keysym cdef glx.Window _target @@ -181,61 +180,58 @@ _target = _event.xcreatewindow.window else : _target = _event.xany.window - _windows.lock() - for i from 0 <= i < _windows.current : - if (<Window> _windows.list[i])._windowID == _target : + _windows.iterStart() + for _i from 0 <= _i < _windows._current : + if (<Window> _windows._list[_i])._windowID == _target : if _event.type == glx.KeyPress : _keysym = glx.XLookupKeysym(&_event.xkey,0) - (<Window> _windows.list[i])._coreEventKeyDown(_event.xkey.time, - _event.xkey.keycode-8, - _keysym) + (<Window> + _windows._list[_i])._coreEventKeyDown (_event.xkey.time, + _event.xkey.keycode-8, + _keysym) elif _event.type == glx.KeyRelease : _keysym = glx.XLookupKeysym(&_event.xkey,0) - (<Window> _windows.list[i])._coreEventKeyUp (_event.xkey.time, - _event.xkey.keycode-8, - _keysym) + (<Window> + _windows._list[_i])._coreEventKeyUp (_event.xkey.time, + _event.xkey.keycode-8, + _keysym) elif _event.type == glx.ButtonPress : - (<Window> _windows.list[i])._coreEventButtonDown( - _event.xbutton.time, - _event.xbutton.button, - _event.xbutton.x, - _event.xbutton.y) + (<Window> + _windows._list[_i])._coreEventButtonDown(_event.xbutton.time, + _event.xbutton.button, + _event.xbutton.x, + _event.xbutton.y) elif _event.type == glx.ButtonRelease : - (<Window> _windows.list[i])._coreEventButtonUp( - _event.xbutton.time, - _event.xbutton.button, - _event.xbutton.x, - _event.xbutton.y) + (<Window> + _windows._list[_i])._coreEventButtonUp (_event.xbutton.time, + _event.xbutton.button, + _event.xbutton.x, + _event.xbutton.y) elif _event.type == glx.MotionNotify : - (<Window> _windows.list[i])._coreEventMotion (_event.xmotion.time, - _event.xmotion.x, - _event.xmotion.y) + (<Window> + _windows._list[_i])._coreEventMotion (_event.xmotion.time, + _event.xmotion.x, + _event.xmotion.y) elif _event.type == glx.Expose : - if (<Window> _windows.list[i])._opened == -1 : - (<Window> _windows.list[i])._opened = 0 + if (<Window> _windows._list[_i])._opened == -1 : + (<Window> _windows._list[_i])._opened = 0 elif _event.type == glx.ConfigureNotify : - (<Window> _windows.list[i])._coreEventConfigure( - _event.xconfigure.x, _event.xconfigure.y, - _event.xconfigure.width, _event.xconfigure.height) + (<Window> + _windows._list[_i])._coreEventConfigure (_event.xconfigure.x, + _event.xconfigure.y, + _event.xconfigure.width, + _event.xconfigure.height) elif _event.type == glx.CreateNotify : - (<Window> _windows.list[i])._coreEventCreate() + (<Window> _windows._list[_i])._coreEventCreate() elif _event.type == glx.DestroyNotify : - (<Window> _windows.list[i])._coreEventDestroy() + (<Window> _windows._list[_i])._coreEventDestroy() elif _event.type == glx.MapNotify : - (<Window> _windows.list[i])._coreEventMap() + (<Window> _windows._list[_i])._coreEventMap() elif _event.type == glx.UnmapNotify : - (<Window> _windows.list[i])._coreEventUnmap() + (<Window> _windows._list[_i])._coreEventUnmap() elif _event.type == glx.ClientMessage : if _event.xclient.format == 32 and \ _event.xclient.data.l[0] == self._wmDelWin : - (<Window> _windows.list[i])._coreEventWinClose() + (<Window> _windows._list[_i])._coreEventWinClose() break - _windows.unlock() - -''' -glx.XF86VidModeSwitchToMode(_display, self._screenID, self._deskMode) -glx.XF86VidModeSetViewPort(_display, self._screenID, 0, 0) -''' - -# !DIRTY: 79-93 -# !DIRTY: 103-109 + _windows.iterDone() _______________________________________________ PySoy-SVN mailing list PySoy-SVN@pysoy.org http://www.pysoy.org/mailman/listinfo/pysoy-svn