listboxcontent: add support for pixmaps in list
authorFelix Domke <tmbinc@elitedvb.net>
Mon, 5 Dec 2005 03:08:36 +0000 (03:08 +0000)
committerFelix Domke <tmbinc@elitedvb.net>
Mon, 5 Dec 2005 03:08:36 +0000 (03:08 +0000)
lib/gdi/epng.cpp
lib/gdi/epng.h
lib/gdi/gpixmap.h
lib/gdi/grc.cpp
lib/gui/elistboxcontent.cpp
lib/python/enigma_python.i
skin.py

index 9c12bb1..30cc529 100644 (file)
@@ -71,6 +71,7 @@ int loadPNG(ePtr<gPixmap> &result, const char *filename)
        if (color_type != 6)
        {
                result=new gPixmap(eSize(width, height), bit_depth);
+               eDebug("gPixmap at %p", (gPixmap*)result);
                gSurface *surface = result->surface;
        
                png_bytep *rowptr=new png_bytep[height];
index 09f3023..2db7bc4 100644 (file)
@@ -3,7 +3,7 @@
 
 #include <lib/gdi/gpixmap.h>
 
-int loadPNG(ePtr<gPixmap> &pixmap, const char *filename);
+SWIG_VOID(int) loadPNG(ePtr<gPixmap> &SWIG_OUTPUT, const char *filename);
 int savePNG(const char *filename, gPixmap *pixmap);
 
 #endif
index 8ea1257..bd53716 100644 (file)
@@ -4,6 +4,7 @@
 #include <pthread.h>
 #include <string>
 #include <lib/base/object.h>
+#include <lib/base/smartptr.h>
 #include <lib/base/elock.h>
 #include <lib/gdi/erect.h>
 #include <lib/gdi/fb.h>
@@ -98,16 +99,7 @@ struct gSurface
 
 class gPixmap: public iObject
 {
-private:
-DECLARE_REF(gPixmap);
-private:
-       friend class gDC;
-       void fill(const gRegion &clip, const gColor &color);
-       
-       void blit(const gPixmap &src, ePoint pos, const gRegion &clip, int flags=0);
-       
-       void mergePalette(const gPixmap &target);
-       void line(const gRegion &clip, ePoint start, ePoint end, gColor color);
+       DECLARE_REF(gPixmap);
 public:
        enum
        {
@@ -115,6 +107,10 @@ public:
                blitAlphaBlend=2
        };
 
+#ifndef SWIG
+       gPixmap(gSurface *surface);
+       gPixmap(eSize, int bpp, int accel = 0);
+
        gSurface *surface;
        
        eLock contentlock;
@@ -122,12 +118,24 @@ public:
        
        gPixmap *lock();
        void unlock();
+#endif
+       virtual ~gPixmap();
        
        eSize size() const { return eSize(surface->x, surface->y); }
        
-       gPixmap(gSurface *surface);
-       gPixmap(eSize, int bpp, int accel = 0);
-       virtual ~gPixmap();
+private:
+#ifndef SWIG
+       friend class gDC;
+       void fill(const gRegion &clip, const gColor &color);
+       
+       void blit(const gPixmap &src, ePoint pos, const gRegion &clip, int flags=0);
+       
+       void mergePalette(const gPixmap &target);
+       void line(const gRegion &clip, ePoint start, ePoint end, gColor color);
+#else
+       gPixmap();
+#endif
+
 };
 
 TEMPLATE_TYPEDEF(ePtr<gPixmap>, gPixmapPtr);
index 7f88402..f54f160 100644 (file)
@@ -1,5 +1,5 @@
 // for debugging use:
-// #define SYNC_PAINT
+ #define SYNC_PAINT
 #include <unistd.h>
 #ifndef SYNC_PAINT
 #include <pthread.h>
@@ -227,6 +227,8 @@ void gPainter::blit(gPixmap *pixmap, ePoint pos, const eRect &clip, int flags)
 {
        gOpcode o;
        
+       ASSERT(pixmap);
+       
        o.opcode=gOpcode::blit;
        o.dc = m_dc.grabRef();
        pixmap->AddRef();
index 3561878..1391a2b 100644 (file)
@@ -540,6 +540,9 @@ void eListboxPythonConfigContent::paint(gPainter &painter, eWindowStyle &style,
 
 //////////////////////////////////////
 
+       /* todo: make a real infrastructure here! */
+RESULT SwigFromPython(ePtr<gPixmap> &res, PyObject *obj);
+
 void eListboxPythonMultiContent::paint(gPainter &painter, eWindowStyle &style, const ePoint &offset, int selected)
 {
        painter.clip(eRect(offset, m_itemsize));
@@ -577,13 +580,17 @@ void eListboxPythonMultiContent::paint(gPainter &painter, eWindowStyle &style, c
                        }
                        
                        
-                       PyObject *px, *py, *pwidth, *pheight, *pfnt, *pstring, *pflags;
+                       PyObject *px = 0, *py = 0, *pwidth = 0, *pheight = 0, *pfnt = 0, *pstring = 0, *pflags = 0;
                
                        /*
                                we have a list of tuples:
                                
                                (x, y, width, height, fnt, flags, "bla" ),
                                
+                               or, for a pixmap:
+                               
+                               (x, y, width, height, pixmap )
+                               
                         */
                        
                        if (!PyTuple_Check(item))
@@ -592,56 +599,100 @@ void eListboxPythonMultiContent::paint(gPainter &painter, eWindowStyle &style, c
                                painter.clippop();
                                return;
                        }
-               
-                       px = PyTuple_GetItem(item, 0);
-                       py = PyTuple_GetItem(item, 1);
-                       pwidth = PyTuple_GetItem(item, 2);
-                       pheight = PyTuple_GetItem(item, 3);
-                       pfnt = PyTuple_GetItem(item, 4);
-                       pflags = PyTuple_GetItem(item, 5);
-                       pstring = PyTuple_GetItem(item, 6);
                        
-                       if (!(px && py && pwidth && pheight && pfnt && pstring))
+                       int size = PyTuple_Size(item);
+                       
+                       if (size >= 5)
                        {
-                               eDebug("eListboxPythonMultiContent received too small tuple (must be (x, y, width, height, fnt, flags, string[, ...])");
-                               painter.clippop();
-                               return;
-                       }
-       
-                       pstring = PyObject_Str(pstring);
+                               px = PyTuple_GetItem(item, 0);
+                               py = PyTuple_GetItem(item, 1);
+                               pwidth = PyTuple_GetItem(item, 2);
+                               pheight = PyTuple_GetItem(item, 3);
                        
-                       const char *string = (PyString_Check(pstring)) ? PyString_AsString(pstring) : "<not-a-string>";
+                               pfnt = PyTuple_GetItem(item, 4); /* could also be an pixmap */
+                               if (size >= 7)
+                               {
+                                       pflags = PyTuple_GetItem(item, 5);
+                                       pstring = PyTuple_GetItem(item, 6);
+                               }
+                       }
                        
-                       int x = PyInt_AsLong(px);
-                       int y = PyInt_AsLong(py);
-                       int width = PyInt_AsLong(pwidth);
-                       int height = PyInt_AsLong(pheight);
-                       int flags = PyInt_AsLong(pflags);
+                       ePtr<gPixmap> pixmap;
                        
-                       int fnt = PyInt_AsLong(pfnt);
+                               /* decide what type */
+                       int type = -1;
+                       if (pfnt)
+                       {
+                               if (PyNumber_Check(pfnt)) /* font index */
+                                       type = 0;
+                               else if (!SwigFromPython(pixmap, pfnt))
+                                       type = 1;
+                       }
                        
-                       if (m_font.find(fnt) == m_font.end())
+                       switch (type)
+                       {
+                       case 0: // text
                        {
-                               eDebug("eListboxPythonMultiContent: specified font %d was not found!", fnt);
+                               if (!(px && py && pwidth && pheight && pfnt && pstring))
+                               {
+                                       eDebug("eListboxPythonMultiContent received too small tuple (must be (x, y, width, height, fnt, flags, string[, ...])");
+                                       painter.clippop();
+                                       return;
+                               }
+       
+                               pstring = PyObject_Str(pstring);
+                       
+                               const char *string = (PyString_Check(pstring)) ? PyString_AsString(pstring) : "<not-a-string>";
+                       
+                               int x = PyInt_AsLong(px);
+                               int y = PyInt_AsLong(py);
+                               int width = PyInt_AsLong(pwidth);
+                               int height = PyInt_AsLong(pheight);
+                               int flags = PyInt_AsLong(pflags);
+
+                               int fnt = PyInt_AsLong(pfnt);
+
+                               if (m_font.find(fnt) == m_font.end())
+                               {
+                                       eDebug("eListboxPythonMultiContent: specified font %d was not found!", fnt);
+                                       Py_XDECREF(pstring);
+                                       painter.clippop();
+                                       return;
+                               }
+                               eRect r = eRect(x, y, width, height);
+                               r.moveBy(offset);
+
+                               painter.setFont(m_font[fnt]);
+
+                               painter.renderText(r, string, flags);
+
                                Py_XDECREF(pstring);
+                               break;
+                       }
+                       case 1: // pixmap
+                       {
+                               int x = PyInt_AsLong(px);
+                               int y = PyInt_AsLong(py);
+                               int width = PyInt_AsLong(pwidth);
+                               int height = PyInt_AsLong(pheight);
+                               
+                               eRect r = eRect(x, y, width, height);
+                               r.moveBy(offset);
+                               
+                               painter.blit(pixmap, r.topLeft(), r);
+                               break;
+                       }
+                       default:
+                               eWarning("eListboxPythonMultiContent received neither text nor pixmap entry");
                                painter.clippop();
                                return;
                        }
-                       
-                       eRect r = eRect(x, y, width, height);
-                       r.moveBy(offset);
-                       
-                       painter.setFont(m_font[fnt]);
-                       
-                       painter.renderText(r, string, flags);
-       
-                       Py_XDECREF(pstring);
-                       
-                       if (selected)
-                               style.drawFrame(painter, eRect(offset, m_itemsize), eWindowStyle::frameListboxEntry);
                }
        }
        
+       if (selected)
+               style.drawFrame(painter, eRect(offset, m_itemsize), eWindowStyle::frameListboxEntry);
+
        painter.clippop();
 }
 
index a90e2fe..d0d4672 100644 (file)
@@ -137,6 +137,7 @@ typedef long time_t;
 %immutable pNavigation::m_event;
 
 %include <lib/gdi/font.h>
+%include <lib/gdi/gpixmap.h>
 %include <lib/gdi/epoint.h>
 %include <lib/gdi/erect.h>
 %include <lib/gdi/esize.h>
@@ -172,8 +173,6 @@ typedef long time_t;
 %include <lib/driver/etimezone.h>
 %include <lib/gdi/lcd.h>
 %include <lib/dvb_ci/dvbci_ui.h>
-
-%include <lib/gdi/gpixmap.h>
 /**************  eptr  **************/
 
 %template(eActionMapPtr) ePtr<eActionMap>;
@@ -234,3 +233,18 @@ void setLCDClock(const char*);
 %immutable keyPressed;
 PSignal1<void,int> &keyPressedSignal();
 
+%{
+RESULT SwigFromPython(ePtr<gPixmap> &result, PyObject *obj)
+{      
+       ePtr<gPixmap> *res;
+
+       res = 0;
+       result = 0;
+       if (SWIG_Python_ConvertPtr(obj, (void **)&res, SWIGTYPE_p_ePtrTgPixmap_t, SWIG_POINTER_EXCEPTION | 0))
+               return -1;
+       if (!res)
+               return -1;
+       result = *res;
+       return 0;
+}
+%}
diff --git a/skin.py b/skin.py
index d11cce0..520780e 100644 (file)
--- a/skin.py
+++ b/skin.py
@@ -74,13 +74,9 @@ def applySingleAttribute(guiObject, desktop, attrib, value):
                elif attrib == 'zPosition':
                        guiObject.setZPosition(int(value))
                elif attrib == "pixmap":
-                       ptr = gPixmapPtr()
-                       if loadPNG(ptr, value):
-                               raise "loading PNG failed!"
-                       x = ptr
-                       ptr = ptr.__deref__()
-                       desktop.makeCompatiblePixmap(ptr)
-                       guiObject.setPixmap(ptr)
+                       ptr = loadPNG(value)
+                       desktop.makeCompatiblePixmap(ptr.__deref__())
+                       guiObject.setPixmap(ptr.__deref__())
                        # guiObject.setPixmapFromFile(value)
                elif attrib == "alphatest": # used by ePixmap
                        guiObject.setAlphatest(
@@ -143,12 +139,6 @@ def applyAllAttributes(guiObject, desktop, attributes):
 def loadSkin(desktop):
        print "loading skin..."
        
-       def getPNG(x):
-               g = gPixmapPtr()
-               loadPNG(g, x)
-               g = g.grabRef()
-               return g
-       
        skin = dom.childNodes[0]
        assert skin.tagName == "skin", "root element in skin must be 'skin'!"
        
@@ -174,11 +164,11 @@ def loadSkin(desktop):
                                bpName = str(pixmap.getAttribute("pos"))
                                filename = str(pixmap.getAttribute("filename"))
                                
-                               png = getPNG(filename)
+                               png = loadPNG(filename)
                                
                                # adapt palette
-                               desktop.makeCompatiblePixmap(png)
-                               style.setPixmap(eWindowStyleSkinned.__dict__[bsName], eWindowStyleSkinned.__dict__[bpName], png)
+                               desktop.makeCompatiblePixmap(png.__deref__())
+                               style.setPixmap(eWindowStyleSkinned.__dict__[bsName], eWindowStyleSkinned.__dict__[bpName], png.__deref__())
 
                for color in elementsWithTag(windowstyle.childNodes, "color"):
                        type = str(color.getAttribute("name"))