Author: ColinHahn Date: 2008-04-04 08:38:24 -0400 (Fri, 04 Apr 2008) New Revision: 1230
Added: trunk/pysoy/src/widgets/Canvas.pym trunk/pysoy/src/widgets/Container.pym trunk/pysoy/src/widgets/Projector.pym trunk/pysoy/src/widgets/StackX.pym trunk/pysoy/src/widgets/StackY.pym trunk/pysoy/src/widgets/StackZ.pym trunk/pysoy/src/widgets/Widget.pym trunk/pysoy/src/widgets/__init__.pym Removed: trunk/pysoy/src/widgets/Canvas.pxi trunk/pysoy/src/widgets/Container.pxi trunk/pysoy/src/widgets/Projector.pxi trunk/pysoy/src/widgets/StackX.pxi trunk/pysoy/src/widgets/StackY.pxi trunk/pysoy/src/widgets/StackZ.pxi trunk/pysoy/src/widgets/Widget.pxi Modified: trunk/pysoy/src/widgets/soy.widgets.pyx Log: Ticket #954 * Migrated soy.widgets to PyMill Deleted: trunk/pysoy/src/widgets/Canvas.pxi =================================================================== --- trunk/pysoy/src/widgets/Canvas.pxi 2008-04-04 06:22:33 UTC (rev 1229) +++ trunk/pysoy/src/widgets/Canvas.pxi 2008-04-04 12:38:24 UTC (rev 1230) @@ -1,125 +0,0 @@ -# PySoy widgets.Canvas class -# -# 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 Affero 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 Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program; if not, see http://www.gnu.org/licenses -# -# $Id$ - -cdef class Canvas (Widget) : - ''' PySoy's Canvas - - This widget control adds a texture on top of a Projector. - It can be stacked together with soy.textures.Font, to create display text on the Projector. - - It accepts a texture and some placement arguments. It's parent should be another widget, - (probably a soy.Window). Aspect must be a positive value (Negative values disables it). - - soy.Canvas can be used to display an image, or as a HUD, or even as a 2D background, depending on - the stack of Widgets. For example to display an image on top of the projector, but also display a 2d - background the Stack could be Canvas,Projector,Canvas. - - See also Widget,Projector,Window - ''' - - ############################################################################ - # - # Python functions - # - - def __cinit__(self, parent=None, margin=None, aspect=-1.0, - texture=None, - *args, **keywords) : - self._verts[1].px = 1.0 - self._verts[1].tx = 1.0 - self._verts[2].px = 1.0 - self._verts[2].py = 1.0 - self._verts[2].tx = 1.0 - self._verts[2].ty = 1.0 - self._verts[3].py = 1.0 - self._verts[3].ty = 1.0 - self._faces[0].a = 0 - self._faces[0].b = 1 - self._faces[0].c = 2 - self._faces[1].a = 2 - self._faces[1].b = 3 - self._faces[1].c = 0 - if isinstance(texture, soy.textures.Texture) or texture == None : - self._texture = texture - if aspect < 0.0 : - self._aspect = (<soy.textures.Texture> self._texture)._aspect - - ############################################################################ - # - # C functions - # - - cdef void _render(self) : - if not self._texture : - return - (<soy.textures.Texture> self._texture)._enable() - - if (<soy.textures.Texture> self._texture)._chans & 1: - gl.glDisable(gl.GL_BLEND) - else: - gl.glEnable(gl.GL_BLEND) - gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) - - gl.glViewport(self._xpos, self._ypos, self._width, self._height) - gl.glMatrixMode(gl.GL_PROJECTION) - gl.glLoadIdentity() - gl.glOrtho(0.0, 1.0, 0.0, 1.0, -1, 1) - gl.glMatrixMode(gl.GL_MODELVIEW) - gl.glLoadIdentity() - - if gl.GLEW_ARB_vertex_buffer_object : - gl.glBindBufferARB (gl.GL_ELEMENT_ARRAY_BUFFER_ARB, 0) - gl.glBindBufferARB (gl.GL_ARRAY_BUFFER_ARB, 0) - - gl.glVertexPointer (3, gl.GL_FLOAT, 48, &self._verts[0].px) - gl.glNormalPointer ( gl.GL_FLOAT, 48, &self._verts[0].nx) - gl.glTexCoordPointer(3, gl.GL_FLOAT, 48, &self._verts[0].tx) - - gl.glDrawElements (gl.GL_TRIANGLES, 6, gl.GL_UNSIGNED_SHORT, - <unsigned short*> self._faces) - - if (<soy.textures.Texture> self._texture)._chans & 1: - pass - else: - gl.glDisable(gl.GL_BLEND) - - (<soy.textures.Texture> self._texture)._disable() - - ############################################################################ - # - # Properties - # - - property texture : - '''Canvas texture - - This is the texture to render on the canvas. Default is None. - ''' - def __get__(self) : - if self._texture : - return self._texture - return None - def __set__(self, value) : - if isinstance(value, soy.textures.Texture) or value == None : - self._texture = value - else : - raise TypeError('that is not a texture') - def __del__(self) : - self._texture = None - Copied: trunk/pysoy/src/widgets/Canvas.pym (from rev 1229, trunk/pysoy/src/widgets/Canvas.pxi) =================================================================== --- trunk/pysoy/src/widgets/Canvas.pym (rev 0) +++ trunk/pysoy/src/widgets/Canvas.pym 2008-04-04 12:38:24 UTC (rev 1230) @@ -0,0 +1,125 @@ +# PySoy widgets.Canvas class +# +# 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 Affero 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program; if not, see http://www.gnu.org/licenses +# +# $Id$ + +cdef class Canvas (Widget) : + ''' PySoy's Canvas + + This widget control adds a texture on top of a Projector. + It can be stacked together with soy.textures.Font, to create display text on the Projector. + + It accepts a texture and some placement arguments. It's parent should be another widget, + (probably a soy.Window). Aspect must be a positive value (Negative values disables it). + + soy.Canvas can be used to display an image, or as a HUD, or even as a 2D background, depending on + the stack of Widgets. For example to display an image on top of the projector, but also display a 2d + background the Stack could be Canvas,Projector,Canvas. + + See also Widget,Projector,Window + ''' + + ############################################################################ + # + # Python functions + # + + def __cinit__(self, parent=None, margin=None, aspect=-1.0, + texture=None, + *args, **keywords) : + self._verts[1].px = 1.0 + self._verts[1].tx = 1.0 + self._verts[2].px = 1.0 + self._verts[2].py = 1.0 + self._verts[2].tx = 1.0 + self._verts[2].ty = 1.0 + self._verts[3].py = 1.0 + self._verts[3].ty = 1.0 + self._faces[0].a = 0 + self._faces[0].b = 1 + self._faces[0].c = 2 + self._faces[1].a = 2 + self._faces[1].b = 3 + self._faces[1].c = 0 + if isinstance(texture, soy.textures.Texture) or texture == None : + self._texture = texture + if aspect < 0.0 : + self._aspect = (<soy.textures.Texture> self._texture)._aspect + + ############################################################################ + # + # C functions + # + + cdef void _render(self) : + if not self._texture : + return + (<soy.textures.Texture> self._texture)._enable() + + if (<soy.textures.Texture> self._texture)._chans & 1: + gl.glDisable(gl.GL_BLEND) + else: + gl.glEnable(gl.GL_BLEND) + gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) + + gl.glViewport(self._xpos, self._ypos, self._width, self._height) + gl.glMatrixMode(gl.GL_PROJECTION) + gl.glLoadIdentity() + gl.glOrtho(0.0, 1.0, 0.0, 1.0, -1, 1) + gl.glMatrixMode(gl.GL_MODELVIEW) + gl.glLoadIdentity() + + if gl.GLEW_ARB_vertex_buffer_object : + gl.glBindBufferARB (gl.GL_ELEMENT_ARRAY_BUFFER_ARB, 0) + gl.glBindBufferARB (gl.GL_ARRAY_BUFFER_ARB, 0) + + gl.glVertexPointer (3, gl.GL_FLOAT, 48, &self._verts[0].px) + gl.glNormalPointer ( gl.GL_FLOAT, 48, &self._verts[0].nx) + gl.glTexCoordPointer(3, gl.GL_FLOAT, 48, &self._verts[0].tx) + + gl.glDrawElements (gl.GL_TRIANGLES, 6, gl.GL_UNSIGNED_SHORT, + <unsigned short*> self._faces) + + if (<soy.textures.Texture> self._texture)._chans & 1: + pass + else: + gl.glDisable(gl.GL_BLEND) + + (<soy.textures.Texture> self._texture)._disable() + + ############################################################################ + # + # Properties + # + + property texture : + '''Canvas texture + + This is the texture to render on the canvas. Default is None. + ''' + def __get__(self) : + if self._texture : + return self._texture + return None + def __set__(self, value) : + if isinstance(value, soy.textures.Texture) or value == None : + self._texture = value + else : + raise TypeError('that is not a texture') + def __del__(self) : + self._texture = None + Deleted: trunk/pysoy/src/widgets/Container.pxi =================================================================== --- trunk/pysoy/src/widgets/Container.pxi 2008-04-04 06:22:33 UTC (rev 1229) +++ trunk/pysoy/src/widgets/Container.pxi 2008-04-04 12:38:24 UTC (rev 1230) @@ -1,59 +0,0 @@ -# PySoy widgets.Container class -# -# 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 Affero 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 Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program; if not, see http://www.gnu.org/licenses -# -# $Id: Container.pxi 1038 2008-03-05 00:36:38Z ArcRiley $ - -cdef class Container (Widget) : - '''PySoy widgets.Container Class - - Container is the base class for any widget that 'contains' other - widgets. This is NOT meant to be used directly. - ''' - - ############################################################################ - # - # Python functions - # - - def __cinit__(self, parent=None, margin=None, aspect=-1.0, - *args, **keywords) : - self._widgets = soy._internals.Children() - - - # This is the same resizing method used in StackZ, which - # effectively makes Container the same as StackZ, for now. - # Maybe this should be removed. - cdef void _resize(self, int _x, int _y, int _width, int _height) : - cdef int _i - Widget._resize(self, _x, _y, _width, _height) - self._widgets._iterStart() - for _i from 0 <= _i < self._widgets._current : - (<Widget> self._widgets._list[_i])._resize(self._xpos, self._ypos, - self._width, self._height) - self._widgets._iterDone() - - ############################################################################ - # - # C functions - # - - cdef void _render(self): - cdef int _i - self._widgets._iterStart() - for _i from 0 <= _i < self._widgets._current: - (<Widget> self._widgets._list[_i])._render() - self._widgets._iterDone() Copied: trunk/pysoy/src/widgets/Container.pym (from rev 1229, trunk/pysoy/src/widgets/Container.pxi) =================================================================== --- trunk/pysoy/src/widgets/Container.pym (rev 0) +++ trunk/pysoy/src/widgets/Container.pym 2008-04-04 12:38:24 UTC (rev 1230) @@ -0,0 +1,59 @@ +# PySoy widgets.Container class +# +# 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 Affero 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program; if not, see http://www.gnu.org/licenses +# +# $Id: Container.pxi 1038 2008-03-05 00:36:38Z ArcRiley $ + +cdef class Container (Widget) : + '''PySoy widgets.Container Class + + Container is the base class for any widget that 'contains' other + widgets. This is NOT meant to be used directly. + ''' + + ############################################################################ + # + # Python functions + # + + def __cinit__(self, parent=None, margin=None, aspect=-1.0, + *args, **keywords) : + self._widgets = soy._internals.Children() + + + # This is the same resizing method used in StackZ, which + # effectively makes Container the same as StackZ, for now. + # Maybe this should be removed. + cdef void _resize(self, int _x, int _y, int _width, int _height) : + cdef int _i + Widget._resize(self, _x, _y, _width, _height) + self._widgets._iterStart() + for _i from 0 <= _i < self._widgets._current : + (<Widget> self._widgets._list[_i])._resize(self._xpos, self._ypos, + self._width, self._height) + self._widgets._iterDone() + + ############################################################################ + # + # C functions + # + + cdef void _render(self): + cdef int _i + self._widgets._iterStart() + for _i from 0 <= _i < self._widgets._current: + (<Widget> self._widgets._list[_i])._render() + self._widgets._iterDone() Deleted: trunk/pysoy/src/widgets/Projector.pxi =================================================================== --- trunk/pysoy/src/widgets/Projector.pxi 2008-04-04 06:22:33 UTC (rev 1229) +++ trunk/pysoy/src/widgets/Projector.pxi 2008-04-04 12:38:24 UTC (rev 1230) @@ -1,93 +0,0 @@ -# PySoy's widgets.Projector class -# -# 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 Affero 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 Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program; if not, see http://www.gnu.org/licenses -# -# $Id$ - -cdef class Projector (Widget) : - '''soy.widgets.Projector - - Creates a suitable container for display of the output of a camera. The - result can be placed on to soy.Screen for example and can - be viewed. - - It accepts a soy.Camera, as well as other placement arguments. - - See also soy.Widget, soy.Camera, soy.Screen - ''' - - ############################################################################ - # - # Python functions - # - - def __cinit__(self, parent=None, margin=None, aspect=-1.0, - camera=None, - *args, **keywords) : - self._camera = camera - if camera : - self._connected = 1 - else : - self._connected = 0 - self._znear = 1.0 - self._zfar = 100.0 - - ############################################################################ - # - # C functions - # - - cdef void _render(self) : - cdef float _aspect - if not self._connected : - return - if self._aspect : - _aspect = self._aspect - else : - _aspect = (<float> self._width) / (<float> self._height) - gl.glViewport(self._xpos, self._ypos, self._width, self._height) - gl.glMatrixMode(gl.GL_PROJECTION) - gl.glLoadIdentity() - gl.gluPerspective(self._camera._fovy, _aspect, self._znear, self._zfar) - gl.glMatrixMode(gl.GL_MODELVIEW) - gl.glLoadIdentity() - self._camera._project() - - ############################################################################ - # - # Properties - # - - property camera : - '''Projection Camera - - This is the camera currently attached to the projector widget. It may be - changed to a different soy.bodies.Camera or None to disable projection. - ''' - def __get__(self) : - return self._camera - def __set__(self, value) : - if value == None : - self._camera = value - self._connected = 0 - return - if not isinstance(value, soy.bodies.Camera) : - raise TypeError('Must provide an instance of soy.bodies.Camera') - self._camera = value - self._connected = 1 - def __del__(self) : - self._camera = None - self._connected = 0 Copied: trunk/pysoy/src/widgets/Projector.pym (from rev 1229, trunk/pysoy/src/widgets/Projector.pxi) =================================================================== --- trunk/pysoy/src/widgets/Projector.pym (rev 0) +++ trunk/pysoy/src/widgets/Projector.pym 2008-04-04 12:38:24 UTC (rev 1230) @@ -0,0 +1,93 @@ +# PySoy's widgets.Projector class +# +# 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 Affero 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program; if not, see http://www.gnu.org/licenses +# +# $Id$ + +cdef class Projector (Widget) : + '''soy.widgets.Projector + + Creates a suitable container for display of the output of a camera. The + result can be placed on to soy.Screen for example and can + be viewed. + + It accepts a soy.Camera, as well as other placement arguments. + + See also soy.Widget, soy.Camera, soy.Screen + ''' + + ############################################################################ + # + # Python functions + # + + def __cinit__(self, parent=None, margin=None, aspect=-1.0, + camera=None, + *args, **keywords) : + self._camera = camera + if camera : + self._connected = 1 + else : + self._connected = 0 + self._znear = 1.0 + self._zfar = 100.0 + + ############################################################################ + # + # C functions + # + + cdef void _render(self) : + cdef float _aspect + if not self._connected : + return + if self._aspect : + _aspect = self._aspect + else : + _aspect = (<float> self._width) / (<float> self._height) + gl.glViewport(self._xpos, self._ypos, self._width, self._height) + gl.glMatrixMode(gl.GL_PROJECTION) + gl.glLoadIdentity() + gl.gluPerspective(self._camera._fovy, _aspect, self._znear, self._zfar) + gl.glMatrixMode(gl.GL_MODELVIEW) + gl.glLoadIdentity() + self._camera._project() + + ############################################################################ + # + # Properties + # + + property camera : + '''Projection Camera + + This is the camera currently attached to the projector widget. It may be + changed to a different soy.bodies.Camera or None to disable projection. + ''' + def __get__(self) : + return self._camera + def __set__(self, value) : + if value == None : + self._camera = value + self._connected = 0 + return + if not isinstance(value, soy.bodies.Camera) : + raise TypeError('Must provide an instance of soy.bodies.Camera') + self._camera = value + self._connected = 1 + def __del__(self) : + self._camera = None + self._connected = 0 Deleted: trunk/pysoy/src/widgets/StackX.pxi =================================================================== --- trunk/pysoy/src/widgets/StackX.pxi 2008-04-04 06:22:33 UTC (rev 1229) +++ trunk/pysoy/src/widgets/StackX.pxi 2008-04-04 12:38:24 UTC (rev 1230) @@ -1,41 +0,0 @@ -# PySoy widgets.StackX class -# -# 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 Affero 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 Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program; if not, see http://www.gnu.org/licenses -# -# $Id$ - -cdef class StackX (Container) : - '''PySoy widgets.StackX Class - - This stacking widget packs children horizontally without overlap. - ''' - - ############################################################################ - # - # C functions - # - - cdef void _resize(self, int _x, int _y, int _width, int _height) : - cdef int _i, _part - Widget._resize(self, _x, _y, _width, _height) - self._widgets._iterStart() - if self._widgets._current > 0 : - _part = self._width / self._widgets._current - for _i from 0 <= _i < self._widgets._current : - (<Widget> self._widgets._list[_i])._resize(self._xpos + (_i * _part), - self._ypos, - _part, self._height) - self._widgets._iterDone() Copied: trunk/pysoy/src/widgets/StackX.pym (from rev 1229, trunk/pysoy/src/widgets/StackX.pxi) =================================================================== --- trunk/pysoy/src/widgets/StackX.pym (rev 0) +++ trunk/pysoy/src/widgets/StackX.pym 2008-04-04 12:38:24 UTC (rev 1230) @@ -0,0 +1,41 @@ +# PySoy widgets.StackX class +# +# 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 Affero 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program; if not, see http://www.gnu.org/licenses +# +# $Id$ + +cdef class StackX (Container) : + '''PySoy widgets.StackX Class + + This stacking widget packs children horizontally without overlap. + ''' + + ############################################################################ + # + # C functions + # + + cdef void _resize(self, int _x, int _y, int _width, int _height) : + cdef int _i, _part + Widget._resize(self, _x, _y, _width, _height) + self._widgets._iterStart() + if self._widgets._current > 0 : + _part = self._width / self._widgets._current + for _i from 0 <= _i < self._widgets._current : + (<Widget> self._widgets._list[_i])._resize(self._xpos + (_i * _part), + self._ypos, + _part, self._height) + self._widgets._iterDone() Deleted: trunk/pysoy/src/widgets/StackY.pxi =================================================================== --- trunk/pysoy/src/widgets/StackY.pxi 2008-04-04 06:22:33 UTC (rev 1229) +++ trunk/pysoy/src/widgets/StackY.pxi 2008-04-04 12:38:24 UTC (rev 1230) @@ -1,41 +0,0 @@ -# PySoy widgets.StackY class -# -# 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 Affero 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 Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program; if not, see http://www.gnu.org/licenses -# -# $Id$ - -cdef class StackY (Container) : - '''PySoy widgets.StackY Class - - This stacking widget packs children vertically without overlap. - ''' - - ############################################################################ - # - # C functions - # - - cdef void _resize(self, int _x, int _y, int _width, int _height) : - cdef int _i, _part - Widget._resize(self, _x, _y, _width, _height) - self._widgets._iterStart() - if self._widgets._current > 0 : - _part = self._height / self._widgets._current - for _i from 0 <= _i < self._widgets._current : - (<Widget> self._widgets._list[_i])._resize(self._xpos, - self._ypos + (_i * _part), - self._width, _part) - self._widgets._iterDone() Copied: trunk/pysoy/src/widgets/StackY.pym (from rev 1229, trunk/pysoy/src/widgets/StackY.pxi) =================================================================== --- trunk/pysoy/src/widgets/StackY.pym (rev 0) +++ trunk/pysoy/src/widgets/StackY.pym 2008-04-04 12:38:24 UTC (rev 1230) @@ -0,0 +1,41 @@ +# PySoy widgets.StackY class +# +# 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 Affero 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program; if not, see http://www.gnu.org/licenses +# +# $Id$ + +cdef class StackY (Container) : + '''PySoy widgets.StackY Class + + This stacking widget packs children vertically without overlap. + ''' + + ############################################################################ + # + # C functions + # + + cdef void _resize(self, int _x, int _y, int _width, int _height) : + cdef int _i, _part + Widget._resize(self, _x, _y, _width, _height) + self._widgets._iterStart() + if self._widgets._current > 0 : + _part = self._height / self._widgets._current + for _i from 0 <= _i < self._widgets._current : + (<Widget> self._widgets._list[_i])._resize(self._xpos, + self._ypos + (_i * _part), + self._width, _part) + self._widgets._iterDone() Deleted: trunk/pysoy/src/widgets/StackZ.pxi =================================================================== --- trunk/pysoy/src/widgets/StackZ.pxi 2008-04-04 06:22:33 UTC (rev 1229) +++ trunk/pysoy/src/widgets/StackZ.pxi 2008-04-04 12:38:24 UTC (rev 1230) @@ -1,39 +0,0 @@ -# PySoy widgets.StackZ class -# -# 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 Affero 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 Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program; if not, see http://www.gnu.org/licenses -# -# $Id$ - -cdef class StackZ (Container) : - '''PySoy widgets.StackZ Class - - This stacking widget overlaps children as "layers". This behavior is - identical to how a soy.Window stacks top-level widgets. Z widget indexing. - ''' - - ############################################################################ - # - # C functions - # - - cdef void _resize(self, int _x, int _y, int _width, int _height) : - cdef int _i - Widget._resize(self, _x, _y, _width, _height) - self._widgets._iterStart() - for _i from 0 <= _i < self._widgets._current : - (<Widget> self._widgets._list[_i])._resize(self._xpos, self._ypos, - self._width, self._height) - self._widgets._iterDone() Copied: trunk/pysoy/src/widgets/StackZ.pym (from rev 1229, trunk/pysoy/src/widgets/StackZ.pxi) =================================================================== --- trunk/pysoy/src/widgets/StackZ.pym (rev 0) +++ trunk/pysoy/src/widgets/StackZ.pym 2008-04-04 12:38:24 UTC (rev 1230) @@ -0,0 +1,39 @@ +# PySoy widgets.StackZ class +# +# 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 Affero 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program; if not, see http://www.gnu.org/licenses +# +# $Id$ + +cdef class StackZ (Container) : + '''PySoy widgets.StackZ Class + + This stacking widget overlaps children as "layers". This behavior is + identical to how a soy.Window stacks top-level widgets. Z widget indexing. + ''' + + ############################################################################ + # + # C functions + # + + cdef void _resize(self, int _x, int _y, int _width, int _height) : + cdef int _i + Widget._resize(self, _x, _y, _width, _height) + self._widgets._iterStart() + for _i from 0 <= _i < self._widgets._current : + (<Widget> self._widgets._list[_i])._resize(self._xpos, self._ypos, + self._width, self._height) + self._widgets._iterDone() Deleted: trunk/pysoy/src/widgets/Widget.pxi =================================================================== --- trunk/pysoy/src/widgets/Widget.pxi 2008-04-04 06:22:33 UTC (rev 1229) +++ trunk/pysoy/src/widgets/Widget.pxi 2008-04-04 12:38:24 UTC (rev 1230) @@ -1,218 +0,0 @@ -# PySoy widgets.Widget class -# -# 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 Affero 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 Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program; if not, see http://www.gnu.org/licenses -# -# $Id$ - -cdef class Widget : - '''Widget Class - - A Widget is a 2d section/layer in a soy.window.Window. This is the base - class which all widgets inherit, it has no render functionality. - - It accepts some placement arguments as well as an aspect argument. - Aspect must be a positive value (Negative values disables it). - - Classes that inherit soy.Widget: - -soy.Widget.Projector - -soy.Widget.Canvas - -soy.Widget.StackX - -soy.Widget.StackY - -soy.Widget.StackZ - ''' - - ############################################################################ - # - # Python functions - # - - def __cinit__(self, parent=None, margin=None, aspect=-1.0, - *args, **keywords) : - if not self._setMargin(margin) : - raise TypeError('margin must be a (int, int, int, int)') - if aspect > 0.0 : - self._aspect = aspect - if parent == None : - self._window = None - self._parent = None - self._resize(0, 0, 16, 16) - elif isinstance(parent, soy._core.Window) : - self._window = parent - self._parent = None - self._topLevel = 1 - self._resize(0, 0, self._window._width, self._window._height) - self._window._widgets._append(<void*> self) - elif isinstance(parent, Container) : - self._parent = parent - self._window = (<Container> self._parent)._window - self._window._widgets._append(<void*> self) - (<Container> parent)._widgets._append(<void*> self) - (<Container> parent)._resize((<Container> parent)._xpos, - (<Container> parent)._ypos, - (<Container> parent)._width, - (<Container> parent)._height) - else : - raise TypeError('parent must be either a soy.Window or stacking widget') - - - def __dealloc__(self) : - if self._window : - self._window._widgets._remove(<void*> self) - if self._parent != None : - (<Container> self._parent)._widgets._remove(<void*> self) - - - def __repr__(self) : - cdef object _name - _name = self.__class__.__name__ - if self._window : - return '<%s in Window id %d>' % (_name, self._window._windowID) - else : - return '<%s>' % (_name) - - ############################################################################ - # - # C functions - # - - cdef int _setMargin(self, object margin) : - if not margin : - margin = (0, 0, 0, 0) - if type(margin) == int : - margin = (margin, margin, margin, margin) - elif len(margin) == 1 : - margin = (margin[0], margin[0], margin[0], margin[0]) - elif len(margin) == 2 : - margin = (margin[0], margin[1], margin[0], margin[1]) - elif len(margin) == 3 : - margin = (margin[0], margin[1], margin[2], margin[1]) - if len(margin)!=4 or type(margin[0])!=int or type(margin[1])!=int \ - or type(margin[2])!=int or type(margin[3])!=int : - return 0 - self._marginTop = margin[0] - self._marginRight = margin[1] - self._marginBottom = margin[2] - self._marginLeft = margin[3] - return 1 - - - cdef void _render(self) : - return - - - cdef void _resize(self, int _xpos, int _ypos, int _width, int _height) : - # _ml = marginLeft, _mb = marginBottom, _mr=marginRight, _mt=marginTop - cdef int _ml, _mb, _mr, _mt, _alignSpace - cdef float _aspect - _ml = _xpos + self._marginLeft - _mr = _ml + _width - (self._marginLeft + self._marginRight) - _mb = _ypos + self._marginBottom - _mt = _mb + _height - (self._marginBottom + self._marginTop) - if self._aspect : - _aspect = <float> (_mr - _ml) / <float> (_mt - _mb) - if _aspect < self._aspect : - # Wide aspect == full width, aligned by height - self._xpos = _ml - self._width = _mr - _ml - self._height = <int> (<float> self._width / self._aspect) - if self._alignHeight < 0 : - self._ypos = _mb - else : - _alignSpace = (_mt - _mb) - self._height - if self._alignHeight == 0 : - self._ypos = _mb + (_alignSpace/2) - else : - self._ypos = _mb + _alignSpace - else : - # Narrow aspect == full height, aligned by width - self._ypos = _mb - self._height = _mt - _mb - self._width = <int> (self._aspect * <float> self._height) - if self._alignWidth < 0 : - self._xpos = _ml - else : - _alignSpace = (_mr - _ml) - self._width - if self._alignWidth == 0 : - self._xpos = _ml + (_alignSpace/2) - else : - self._xpos = _ml + _alignSpace - else : - # No aspect ratio, stretch it to full size - self._xpos = _ml - self._ypos = _mb - self._width = _mr - _ml - self._height = _mt - _mb - - ############################################################################ - # - # Properties - # - - property margin : - '''Widget's margin - - These are the four margins of the widget respective to it's parent. - Values are for the top, right, bottom, and left (as with CSS margin:) - - Defaults to (0, 0, 0, 0) - ''' - def __get__(self) : - return (self._marginTop, self._marginRight, - self._marginBottom, self._marginLeft) - def __set__(self, margin) : - if not self._setMargin(margin) : - raise TypeError('margin must be a (int, int, int, int)') - def __del__(self) : - self._setMargin(None) - - - property aspect : - '''Widget's aspect ratio - - This is the ratio of width:height which, if set, will be maintained. - - Defaults to disabled (0.0) - ''' - def __get__(self) : - return self._aspect - def __set__(self, aspect) : - if aspect < 0.0 : - raise ValueError('aspect cannot be negetive') - self._aspect = aspect - def __del__(self) : - self._aspect = 0.0 - - - property position : - '''Widget's position - - This is the position of the widget reletive to the window. - Use the parent, margin, and aspect properties to change this value. - ''' - def __get__(self) : - return (self._xpos, self._ypos) - - - property size : - '''Widget's size - - This is the pixel size of the widget. It cannot be set. - ''' - def __get__(self) : - return (self._width, self._height) - - -# !DIRTY: 50-53, 57-66 Copied: trunk/pysoy/src/widgets/Widget.pym (from rev 1229, trunk/pysoy/src/widgets/Widget.pxi) =================================================================== --- trunk/pysoy/src/widgets/Widget.pym (rev 0) +++ trunk/pysoy/src/widgets/Widget.pym 2008-04-04 12:38:24 UTC (rev 1230) @@ -0,0 +1,218 @@ +# PySoy widgets.Widget class +# +# 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 Affero 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program; if not, see http://www.gnu.org/licenses +# +# $Id$ + +cdef class Widget : + '''Widget Class + + A Widget is a 2d section/layer in a soy.window.Window. This is the base + class which all widgets inherit, it has no render functionality. + + It accepts some placement arguments as well as an aspect argument. + Aspect must be a positive value (Negative values disables it). + + Classes that inherit soy.Widget: + -soy.Widget.Projector + -soy.Widget.Canvas + -soy.Widget.StackX + -soy.Widget.StackY + -soy.Widget.StackZ + ''' + + ############################################################################ + # + # Python functions + # + + def __cinit__(self, parent=None, margin=None, aspect=-1.0, + *args, **keywords) : + if not self._setMargin(margin) : + raise TypeError('margin must be a (int, int, int, int)') + if aspect > 0.0 : + self._aspect = aspect + if parent == None : + self._window = None + self._parent = None + self._resize(0, 0, 16, 16) + elif isinstance(parent, soy._core.Window) : + self._window = parent + self._parent = None + self._topLevel = 1 + self._resize(0, 0, self._window._width, self._window._height) + self._window._widgets._append(<void*> self) + elif isinstance(parent, Container) : + self._parent = parent + self._window = (<Container> self._parent)._window + self._window._widgets._append(<void*> self) + (<Container> parent)._widgets._append(<void*> self) + (<Container> parent)._resize((<Container> parent)._xpos, + (<Container> parent)._ypos, + (<Container> parent)._width, + (<Container> parent)._height) + else : + raise TypeError('parent must be either a soy.Window or stacking widget') + + + def __dealloc__(self) : + if self._window : + self._window._widgets._remove(<void*> self) + if self._parent != None : + (<Container> self._parent)._widgets._remove(<void*> self) + + + def __repr__(self) : + cdef object _name + _name = self.__class__.__name__ + if self._window : + return '<%s in Window id %d>' % (_name, self._window._windowID) + else : + return '<%s>' % (_name) + + ############################################################################ + # + # C functions + # + + cdef int _setMargin(self, object margin) : + if not margin : + margin = (0, 0, 0, 0) + if type(margin) == int : + margin = (margin, margin, margin, margin) + elif len(margin) == 1 : + margin = (margin[0], margin[0], margin[0], margin[0]) + elif len(margin) == 2 : + margin = (margin[0], margin[1], margin[0], margin[1]) + elif len(margin) == 3 : + margin = (margin[0], margin[1], margin[2], margin[1]) + if len(margin)!=4 or type(margin[0])!=int or type(margin[1])!=int \ + or type(margin[2])!=int or type(margin[3])!=int : + return 0 + self._marginTop = margin[0] + self._marginRight = margin[1] + self._marginBottom = margin[2] + self._marginLeft = margin[3] + return 1 + + + cdef void _render(self) : + return + + + cdef void _resize(self, int _xpos, int _ypos, int _width, int _height) : + # _ml = marginLeft, _mb = marginBottom, _mr=marginRight, _mt=marginTop + cdef int _ml, _mb, _mr, _mt, _alignSpace + cdef float _aspect + _ml = _xpos + self._marginLeft + _mr = _ml + _width - (self._marginLeft + self._marginRight) + _mb = _ypos + self._marginBottom + _mt = _mb + _height - (self._marginBottom + self._marginTop) + if self._aspect : + _aspect = <float> (_mr - _ml) / <float> (_mt - _mb) + if _aspect < self._aspect : + # Wide aspect == full width, aligned by height + self._xpos = _ml + self._width = _mr - _ml + self._height = <int> (<float> self._width / self._aspect) + if self._alignHeight < 0 : + self._ypos = _mb + else : + _alignSpace = (_mt - _mb) - self._height + if self._alignHeight == 0 : + self._ypos = _mb + (_alignSpace/2) + else : + self._ypos = _mb + _alignSpace + else : + # Narrow aspect == full height, aligned by width + self._ypos = _mb + self._height = _mt - _mb + self._width = <int> (self._aspect * <float> self._height) + if self._alignWidth < 0 : + self._xpos = _ml + else : + _alignSpace = (_mr - _ml) - self._width + if self._alignWidth == 0 : + self._xpos = _ml + (_alignSpace/2) + else : + self._xpos = _ml + _alignSpace + else : + # No aspect ratio, stretch it to full size + self._xpos = _ml + self._ypos = _mb + self._width = _mr - _ml + self._height = _mt - _mb + + ############################################################################ + # + # Properties + # + + property margin : + '''Widget's margin + + These are the four margins of the widget respective to it's parent. + Values are for the top, right, bottom, and left (as with CSS margin:) + + Defaults to (0, 0, 0, 0) + ''' + def __get__(self) : + return (self._marginTop, self._marginRight, + self._marginBottom, self._marginLeft) + def __set__(self, margin) : + if not self._setMargin(margin) : + raise TypeError('margin must be a (int, int, int, int)') + def __del__(self) : + self._setMargin(None) + + + property aspect : + '''Widget's aspect ratio + + This is the ratio of width:height which, if set, will be maintained. + + Defaults to disabled (0.0) + ''' + def __get__(self) : + return self._aspect + def __set__(self, aspect) : + if aspect < 0.0 : + raise ValueError('aspect cannot be negetive') + self._aspect = aspect + def __del__(self) : + self._aspect = 0.0 + + + property position : + '''Widget's position + + This is the position of the widget reletive to the window. + Use the parent, margin, and aspect properties to change this value. + ''' + def __get__(self) : + return (self._xpos, self._ypos) + + + property size : + '''Widget's size + + This is the pixel size of the widget. It cannot be set. + ''' + def __get__(self) : + return (self._width, self._height) + + +# !DIRTY: 50-53, 57-66 Copied: trunk/pysoy/src/widgets/__init__.pym (from rev 1229, trunk/pysoy/src/stubs/Stub.pxi) =================================================================== --- trunk/pysoy/src/widgets/__init__.pym (rev 0) +++ trunk/pysoy/src/widgets/__init__.pym 2008-04-04 12:38:24 UTC (rev 1230) @@ -0,0 +1,18 @@ +# PySoy's stubs.Stub +# +# 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 Affero 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program; if not, see http://www.gnu.org/licenses +# +# $Id$ Modified: trunk/pysoy/src/widgets/soy.widgets.pyx =================================================================== --- trunk/pysoy/src/widgets/soy.widgets.pyx 2008-04-04 06:22:33 UTC (rev 1229) +++ trunk/pysoy/src/widgets/soy.widgets.pyx 2008-04-04 12:38:24 UTC (rev 1230) @@ -24,10 +24,10 @@ 'by '+'$Author$'[9:-2] __version__ = 'Trunk (r'+'$Rev$'[6:-2]+')' -include "Widget.pxi" -include "Canvas.pxi" -include "Projector.pxi" -include "Container.pxi" -include "StackX.pxi" -include "StackY.pxi" -include "StackZ.pxi" +include "Widget.pxm" +include "Canvas.pxm" +include "Projector.pxm" +include "Container.pxm" +include "StackX.pxm" +include "StackY.pxm" +include "StackZ.pxm" _______________________________________________ PySoy-SVN mailing list PySoy-SVN@pysoy.org http://www.pysoy.org/mailman/listinfo/pysoy-svn