Author: JonNeal
Date: 2008-01-28 21:41:07 +0000 (Mon, 28 Jan 2008)
New Revision: 802

Modified:
   trunk/pysoy/examples/shapes.py
   trunk/pysoy/include/stdlib.pxd
   trunk/pysoy/src/_core-x11/Window.pxi
   trunk/pysoy/src/_core-x11/glx.pxd
Log:
X Window icon (not fully functional) commit

Modified: trunk/pysoy/examples/shapes.py
===================================================================
--- trunk/pysoy/examples/shapes.py      2008-01-28 21:16:02 UTC (rev 801)
+++ trunk/pysoy/examples/shapes.py      2008-01-28 21:41:07 UTC (rev 802)
@@ -5,7 +5,7 @@
 
 sce = soy.Scene()
 scr = soy.Screen()
-win = soy.Window(scr, 'Mesh shape test')
+win = soy.Window(scr, 'Mesh shape 
test',soy.transports.File('media/pysoy_logo.soy')['gimp'])
 cam = soy.bodies.Camera(sce)
 cam.position = (0.0, 0.0, 20.0)
 lig = soy.bodies.lights.Light(sce)

Modified: trunk/pysoy/include/stdlib.pxd
===================================================================
--- trunk/pysoy/include/stdlib.pxd      2008-01-28 21:16:02 UTC (rev 801)
+++ trunk/pysoy/include/stdlib.pxd      2008-01-28 21:41:07 UTC (rev 802)
@@ -7,3 +7,4 @@
     ctypedef unsigned int size_t
     cdef void* malloc (size_t)
     cdef void  free   (void* )
+    cdef void* memcpy(void*, void*, int)

Modified: trunk/pysoy/src/_core-x11/Window.pxi
===================================================================
--- trunk/pysoy/src/_core-x11/Window.pxi        2008-01-28 21:16:02 UTC (rev 
801)
+++ trunk/pysoy/src/_core-x11/Window.pxi        2008-01-28 21:41:07 UTC (rev 
802)
@@ -18,6 +18,7 @@
 # $Id$
 
 cimport soy.controllers
+cimport stdlib
 
 cdef soy._internals.Children _windows
 _windows = soy._internals.Children()
@@ -36,6 +37,8 @@
     self._controllers = soy._internals.Children()
     self._widgets     = soy._internals.Children()
     self._title = str(title)
+    if icon:
+      self.icon = icon
     if background :
       self._background = background
     else :
@@ -236,31 +239,42 @@
         _windows.unlock()
 
 
-  #property icon:
-    #'''Window's icon texture
-    #
-    #This property is the window's "icon", however the window manager uses it.
-    #Textures must be 1D or 2D (not 3D) and /should/ be square.
-    #
-    #Defaults to None.
-    #'''
-    #def __get__(self) :
-    #  if self._iconID > 0 :
-    #    return self._icon
-    #  else :
-    #    return None
-    #def __set__(self, value) :
-      #cdef glx.Display   *_display
-      #_display = glx.DisplayOfScreen(self._screen._screen)
-      #if not isinstance(value, soy.textures.Texture) :
-      #  raise TypeError('not a Texture')
-      #if (<soy.textures.Texture> value)._depth != 1 :
-      #  raise TypeError('texture must not be 3 dimensional')
-      #self._icon = value
-      ## Need to load the Pixmap
-      #_windows.lock()
-      #self._setProperties()
-      #_windows.unlock()
+  property icon:
+    '''Window's icon texture
+    
+    This property is the window's "icon", however the window manager uses it.
+    Textures must be 1D or 2D (not 3D) and /should/ be square.
+    
+    Defaults to None.
+    '''
+    def __get__(self) :
+      if self._iconID > 0 :
+        return self._icon
+      else :
+        return None
+    def __set__(self, value) :
+      cdef glx.Display      *_display
+      cdef glx.XImage       *ximage_buffer
+      _display = glx.DisplayOfScreen(self._screen._screen)
+      if not isinstance(value, soy.textures.Texture) :
+        raise TypeError('not a Texture')
+      if (<soy.textures.Texture> value)._depth != 1 :
+        raise TypeError('texture must not be 3 dimensional')
+      if (<soy.textures.Texture> value)._chan != 3 :
+        raise TypeError('texture must be RGB format')
+      self._icon = value
+      ximage_buffer = glx.XCreateImage(_display, 
self._screen._xVisualInfo.visual,
+                                       self._screen._xVisualInfo.depth,
+                                       (<int> glx.XYPixmap), 0, value._texels, 
+                                       value._width, value._height, 32, 32)
+      stdio.printf("%s\n",ximage_buffer[0])
+      self._iconID = glx.XCreatePixmap(_display, self._screen, value._width,
+                                     value._height, 
+                                     self._screen._xVisualInfo.depth)
+      stdlib.memcpy(&self._iconID, ximage_buffer, 
value._width*value._height*value._chan)
+      _windows.lock()
+      self._setProperties()
+      _windows.unlock()
 
 
   property background:

Modified: trunk/pysoy/src/_core-x11/glx.pxd
===================================================================
--- trunk/pysoy/src/_core-x11/glx.pxd   2008-01-28 21:16:02 UTC (rev 801)
+++ trunk/pysoy/src/_core-x11/glx.pxd   2008-01-28 21:41:07 UTC (rev 802)
@@ -591,3 +591,30 @@
   cdef Bool XF86VidModeSetViewPort         ( Display*, int, int, int )
   
   cdef KeySym XLookupKeysym                ( XKeyEvent*, int )
+
+
+
+cdef extern from "X11/Xlib.h" :
+  ctypedef char *XPointer
+  ctypedef void _XDisplay
+
+  ctypedef struct XImage :
+    int width, height
+    int xoffset
+    int format
+    char *data
+    int byte_order
+    int bitmap_unit
+    int bitmap_bit_order
+    int bitmap_pad
+    int depth
+    int bytes_per_line
+    int bits_per_pixel
+    unsigned long red_mask
+    unsigned long green_mask
+    unsigned long blue_mask
+    XPointer obdata
+
+  cdef XImage *XCreateImage( Display*, Visual*, unsigned int,
+                             int, int, char*, unsigned int,
+                             unsigned int, int, int )

_______________________________________________
PySoy-SVN mailing list
[email protected]
http://www.pysoy.org/mailman/listinfo/pysoy-svn

Reply via email to