Author: ArcRiley Date: 2008-03-18 16:18:21 -0400 (Tue, 18 Mar 2008) New Revision: 1163
Modified: trunk/pysoy/src/textures/Print.pxi trunk/pysoy/src/textures/soy.textures.pxd Log: No Ticket : "Cleanup in aisle textures.Print" Modified: trunk/pysoy/src/textures/Print.pxi =================================================================== --- trunk/pysoy/src/textures/Print.pxi 2008-03-18 19:27:01 UTC (rev 1162) +++ trunk/pysoy/src/textures/Print.pxi 2008-03-18 20:18:21 UTC (rev 1163) @@ -22,6 +22,12 @@ This renders text using cairo. ''' + + ############################################################################ + # + # Python functions + # + def __cinit__(self, text='', font='serif', background=None, foreground=None, *args, **keywords) : @@ -49,14 +55,18 @@ self.text = text self.font = font + + ############################################################################ + # + # Properties + # + property background : def __get__(self) : return self._background def __set__(self, soy.colors.Color value) : self._background = value self._draw() - def __del__(self) : - self._background = soy.colors.clear property foreground : @@ -65,8 +75,6 @@ def __set__(self, soy.colors.Color value) : self._foreground = value self._draw() - def __del__(self) : - self._foreground = soy.colors.clear property text : @@ -79,6 +87,7 @@ raise TypeError('Text must be a string') self._draw() + property font : def __get__(self) : return self._font @@ -88,22 +97,37 @@ self._font = value self._draw() - cdef void _clear(self) : + + ############################################################################ + # + # C functions + # + + cdef void _draw(self) : + # + # _draw is called whenever the colors, font, or text is modified. + # It uses Cairo to (re)draw the texture based on these parameters + # to self._texels which the WindowLoop will then update the texture from. + # cdef gl.GLfloat _bg[4] + cdef gl.GLfloat _fg[4] + # + # Don't bother rendering if either the font or text don't exist + if not (self._font and self._text) : + return + # + # Lock against rendering + py.PyThread_acquire_lock(self._mutex,1) + # + # Clear the background cairo.cairo_save(self._context) (<soy.colors.Color> self._background)._getRGBA(_bg) cairo.cairo_set_source_rgba(self._context, _bg[0], _bg[1], _bg[2], _bg[3]) cairo.cairo_set_operator(self._context, cairo.CAIRO_OPERATOR_SOURCE) cairo.cairo_paint(self._context) cairo.cairo_restore(self._context) - - cdef void _draw(self) : - cdef gl.GLfloat _fg[4] - if not (self._font and self._text) : - return - # Clear the background - py.PyThread_acquire_lock(self._mutex,1) - self._clear() + # + # Now draw cairo.cairo_select_font_face(self._context, self._font, cairo.CAIRO_FONT_SLANT_NORMAL, @@ -113,5 +137,9 @@ cairo.cairo_set_source_rgba(self._context, _fg[0], _fg[1], _fg[2], _fg[3]) cairo.cairo_move_to(self._context, 10.0, 50.0) cairo.cairo_show_text(self._context, self._text) + # + # By setting the _update flag we cause self._texels to be re-sent to GPU self._update = 1 + # + # Release the lock py.PyThread_release_lock(self._mutex) Modified: trunk/pysoy/src/textures/soy.textures.pxd =================================================================== --- trunk/pysoy/src/textures/soy.textures.pxd 2008-03-18 19:27:01 UTC (rev 1162) +++ trunk/pysoy/src/textures/soy.textures.pxd 2008-03-18 20:18:21 UTC (rev 1163) @@ -60,7 +60,6 @@ cdef soy.colors.Color _foreground cdef object _text cdef object _font - cdef void _clear ( self ) cdef void _draw ( self ) _______________________________________________ PySoy-SVN mailing list PySoy-SVN@pysoy.org http://www.pysoy.org/mailman/listinfo/pysoy-svn