aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorFelix Domke <tmbinc@elitedvb.net>2005-12-05 03:08:36 +0000
committerFelix Domke <tmbinc@elitedvb.net>2005-12-05 03:08:36 +0000
commit02226aee689caad4d05e65448ec7640d33e8f659 (patch)
tree4388956180ee2f705365c2c3c556d40a892d6aa7 /lib
parenta48bc4879c6ac4c6eb163f6bb3c0b5c0536fcee8 (diff)
downloadenigma2-02226aee689caad4d05e65448ec7640d33e8f659.tar.gz
enigma2-02226aee689caad4d05e65448ec7640d33e8f659.zip
listboxcontent: add support for pixmaps in list
Diffstat (limited to 'lib')
-rw-r--r--lib/gdi/epng.cpp1
-rw-r--r--lib/gdi/epng.h2
-rw-r--r--lib/gdi/gpixmap.h34
-rw-r--r--lib/gdi/grc.cpp4
-rw-r--r--lib/gui/elistboxcontent.cpp125
-rw-r--r--lib/python/enigma_python.i18
6 files changed, 130 insertions, 54 deletions
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<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];
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 <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
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 <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);
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 <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();
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<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();
}
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 <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;
+}
+%}