From: Felix Domke Date: Mon, 5 Dec 2005 03:08:36 +0000 (+0000) Subject: listboxcontent: add support for pixmaps in list X-Git-Tag: 2.6.0~4829 X-Git-Url: https://git.cweiske.de/enigma2.git/commitdiff_plain/02226aee689caad4d05e65448ec7640d33e8f659 listboxcontent: add support for pixmaps in list --- diff --git a/lib/gdi/epng.cpp b/lib/gdi/epng.cpp index 9c12bb10..30cc5297 100644 --- a/lib/gdi/epng.cpp +++ b/lib/gdi/epng.cpp @@ -71,6 +71,7 @@ int loadPNG(ePtr &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]; diff --git a/lib/gdi/epng.h b/lib/gdi/epng.h index 09f30233..2db7bc43 100644 --- a/lib/gdi/epng.h +++ b/lib/gdi/epng.h @@ -3,7 +3,7 @@ #include -int loadPNG(ePtr &pixmap, const char *filename); +SWIG_VOID(int) loadPNG(ePtr &SWIG_OUTPUT, const char *filename); int savePNG(const char *filename, gPixmap *pixmap); #endif diff --git a/lib/gdi/gpixmap.h b/lib/gdi/gpixmap.h index 8ea12574..bd537164 100644 --- a/lib/gdi/gpixmap.h +++ b/lib/gdi/gpixmap.h @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -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, gPixmapPtr); diff --git a/lib/gdi/grc.cpp b/lib/gdi/grc.cpp index 7f884024..f54f1604 100644 --- a/lib/gdi/grc.cpp +++ b/lib/gdi/grc.cpp @@ -1,5 +1,5 @@ // for debugging use: -// #define SYNC_PAINT + #define SYNC_PAINT #include #ifndef SYNC_PAINT #include @@ -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(); diff --git a/lib/gui/elistboxcontent.cpp b/lib/gui/elistboxcontent.cpp index 35618786..1391a2b5 100644 --- a/lib/gui/elistboxcontent.cpp +++ b/lib/gui/elistboxcontent.cpp @@ -540,6 +540,9 @@ void eListboxPythonConfigContent::paint(gPainter &painter, eWindowStyle &style, ////////////////////////////////////// + /* todo: make a real infrastructure here! */ +RESULT SwigFromPython(ePtr &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) : ""; + 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 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) : ""; + + 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(); } diff --git a/lib/python/enigma_python.i b/lib/python/enigma_python.i index a90e2fef..d0d46723 100644 --- a/lib/python/enigma_python.i +++ b/lib/python/enigma_python.i @@ -137,6 +137,7 @@ typedef long time_t; %immutable pNavigation::m_event; %include +%include %include %include %include @@ -172,8 +173,6 @@ typedef long time_t; %include %include %include - -%include /************** eptr **************/ %template(eActionMapPtr) ePtr; @@ -234,3 +233,18 @@ void setLCDClock(const char*); %immutable keyPressed; PSignal1 &keyPressedSignal(); +%{ +RESULT SwigFromPython(ePtr &result, PyObject *obj) +{ + ePtr *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 d11cce02..520780e6 100644 --- 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"))