add 'canvas' gui element where you can draw into a pixmap from python
authorFelix Domke <tmbinc@elitedvb.net>
Thu, 19 Jul 2007 23:48:55 +0000 (23:48 +0000)
committerFelix Domke <tmbinc@elitedvb.net>
Thu, 19 Jul 2007 23:48:55 +0000 (23:48 +0000)
lib/gui/Makefile.am
lib/gui/ecanvas.cpp [new file with mode: 0644]
lib/gui/ecanvas.h [new file with mode: 0644]
lib/python/Components/Renderer/Canvas.py [new file with mode: 0644]
lib/python/Components/Renderer/Makefile.am
lib/python/Components/Sources/CanvasSource.py [new file with mode: 0644]
lib/python/Components/Sources/Makefile.am
lib/python/enigma_python.i

index a011e07..f4de9d1 100644 (file)
@@ -8,5 +8,4 @@ libenigma_gui_a_SOURCES = \
        ebutton.cpp elabel.cpp eslider.cpp ewidget.cpp ewidgetdesktop.cpp  \
        ewindow.cpp ewindowstyle.cpp elistbox.cpp elistboxcontent.cpp \
        epixmap.cpp ewindowstyleskinned.cpp einput.cpp einputstring.cpp einputnumber.cpp \
-       ewidgetanimation.cpp epositiongauge.cpp evideo.cpp esubtitle.cpp
-
+       ewidgetanimation.cpp epositiongauge.cpp evideo.cpp esubtitle.cpp ecanvas.cpp
diff --git a/lib/gui/ecanvas.cpp b/lib/gui/ecanvas.cpp
new file mode 100644 (file)
index 0000000..c646991
--- /dev/null
@@ -0,0 +1,38 @@
+#include <lib/gui/ecanvas.h>
+
+eCanvas::eCanvas(eWidget *parent): ePixmap(parent)
+{
+}
+
+void eCanvas::setSize(eSize size)
+{
+       setPixmap(new gPixmap(size, 32)); /* TODO: do we need 8bit surfaces? */
+}
+
+void eCanvas::clear(gRGB color)
+{
+#if 0
+       if (!m_pixmap)
+               return;
+
+       ePtr<gDC> d = new gDC(m_pixmap);
+       gPainter p(d, eRect());
+       p.setBackgroundColor(color);
+       p.clear();
+
+       invalidate();
+#endif
+}
+
+void eCanvas::fillRect(eRect rect, gRGB color)
+{
+       eDebug("draw into canvas... %d %d, %d %d", rect.left(), rect.top(), rect.width(), rect.height());
+#if 0
+       ePtr<gDC> d = new gDC(m_pixmap);
+       gPainter p(d, eRect());
+       p.setForegroundColor(color);
+       p.fill(rect);
+
+       invalidate(rect);
+#endif
+}
diff --git a/lib/gui/ecanvas.h b/lib/gui/ecanvas.h
new file mode 100644 (file)
index 0000000..629c603
--- /dev/null
@@ -0,0 +1,17 @@
+#ifndef __lib_gui_ecanvas_h
+#define __lib_gui_ecanvas_h
+
+#include <lib/gui/epixmap.h>
+
+class eCanvas: public ePixmap
+{
+public:
+       eCanvas(eWidget *parent);
+
+       void setSize(eSize size);
+
+       void clear(gRGB color);
+       void fillRect(eRect rect, gRGB color);
+};
+
+#endif
diff --git a/lib/python/Components/Renderer/Canvas.py b/lib/python/Components/Renderer/Canvas.py
new file mode 100644 (file)
index 0000000..01b05fb
--- /dev/null
@@ -0,0 +1,40 @@
+from Renderer import Renderer
+
+from enigma import eCanvas, eRect, gRGB
+
+class Canvas(Renderer):
+       GUI_WIDGET = eCanvas
+
+       def __init__(self):
+               Renderer.__init__(self)
+               self.sequence = None
+               self.draw_count = 0
+
+       def pull_updates(self):
+               if self.instance is None:
+                       return
+
+               # do an incremental update
+               list = self.source.drawlist
+               if list is None:
+                       return
+
+               # if the lists sequence count changed, re-start from begin
+               if list[0] != self.sequence:
+                       self.sequence = list[0]
+                       self.draw_count = 0
+
+               self.draw(list[1][self.draw_count:])
+               self.draw_count = len(list[1])
+
+       def draw(self, list):
+               for l in list:
+                       print "drawing ..", l
+                       self.instance.fillRect(eRect(l[1], l[2], l[3], l[4]), gRGB(l[5]))
+
+       def changed(self, what):
+               self.pull_updates()
+
+       def postWidgetCreate(self, instance):
+               self.sequence = None
+               self.pull_updates()
index ba082d4..31439c7 100644 (file)
@@ -2,4 +2,4 @@ installdir = $(LIBDIR)/enigma2/python/Components/Renderer
 
 install_PYTHON = \
        __init__.py Label.py Progress.py Listbox.py Renderer.py Pixmap.py \
-       FixedLabel.py PositionGauge.py
+       FixedLabel.py PositionGauge.py Canvas.py
diff --git a/lib/python/Components/Sources/CanvasSource.py b/lib/python/Components/Sources/CanvasSource.py
new file mode 100644 (file)
index 0000000..4fd0e02
--- /dev/null
@@ -0,0 +1,20 @@
+from Source import Source
+
+class CanvasSource(Source):
+       def __init__(self):
+               Source.__init__(self)
+               self.sequence = 0
+               self.clear()
+
+       def clear(self):
+               self.sequence += 1
+               self._drawlist = (self.sequence, [ ])
+
+       def get_drawlist(self):
+               return self._drawlist
+
+       drawlist = property(get_drawlist)
+
+       def fill(self, x, y, width, height, color):
+               self.drawlist[1].append( (1, x, y, width, height, color) )
+               self.changed()
index 6deb423..2e0dd44 100644 (file)
@@ -3,4 +3,4 @@ installdir = $(LIBDIR)/enigma2/python/Components/Sources
 install_PYTHON = \
        __init__.py Clock.py EventInfo.py Source.py List.py CurrentService.py \
        FrontendStatus.py Boolean.py Config.py ServiceList.py RdsDecoder.py StreamService.py \
-       StaticText.py
+       StaticText.py CanvasSource.py
index 0d559ab..cef97c3 100644 (file)
@@ -65,6 +65,7 @@ is usually caused by not marking PSignals as immutable.
 #include <lib/gui/eslider.h>
 #include <lib/gui/epositiongauge.h>
 #include <lib/gui/evideo.h>
+#include <lib/gui/ecanvas.h>
 #include <lib/python/connections.h>
 #include <lib/gui/elistbox.h>
 #include <lib/gui/elistboxcontent.h>
@@ -171,6 +172,7 @@ typedef long time_t;
 %include <lib/gui/einputstring.h>
 %include <lib/gui/einputnumber.h>
 %include <lib/gui/epixmap.h>
+%include <lib/gui/ecanvas.h>
 %include <lib/gui/ebutton.h>
 %include <lib/gui/ewindow.h>
 %include <lib/gui/eslider.h>