add position gauge
authorFelix Domke <tmbinc@elitedvb.net>
Tue, 21 Feb 2006 02:15:28 +0000 (02:15 +0000)
committerFelix Domke <tmbinc@elitedvb.net>
Tue, 21 Feb 2006 02:15:28 +0000 (02:15 +0000)
data/position_pointer.png [new file with mode: 0644]
lib/gui/Makefile.am
lib/gui/epositiongauge.cpp [new file with mode: 0644]
lib/gui/epositiongauge.h [new file with mode: 0644]
lib/python/enigma_python.i

diff --git a/data/position_pointer.png b/data/position_pointer.png
new file mode 100644 (file)
index 0000000..df90291
Binary files /dev/null and b/data/position_pointer.png differ
index 55a7e53..730150a 100644 (file)
@@ -8,4 +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
+       ewidgetanimation.cpp epositiongauge.cpp
diff --git a/lib/gui/epositiongauge.cpp b/lib/gui/epositiongauge.cpp
new file mode 100644 (file)
index 0000000..1d8775e
--- /dev/null
@@ -0,0 +1,96 @@
+#include <lib/gui/epositiongauge.h>
+#include <lib/gui/epixmap.h>
+
+ePositionGauge::ePositionGauge(eWidget *parent)
+       : eWidget(parent)
+{
+       m_point_widget = new ePixmap(this);
+       m_point_widget->setAlphatest(1);
+       m_position = 0;
+       m_length = 0;
+}
+
+ePositionGauge::~ePositionGauge()
+{
+       delete m_point_widget;
+}
+
+void ePositionGauge::setLength(const pts_t &len)
+{
+       eDebug("set len: %llx", len);
+       if (m_length == len)
+               return;
+       m_length = len;
+       updatePosition();
+}
+
+void ePositionGauge::setPosition(const pts_t &pos)
+{
+       eDebug("set position: %llx", pos);
+       if (m_position == pos)
+               return;
+       m_position = pos;
+       updatePosition();
+}
+
+void ePositionGauge::setInColor(const gRGB &color)
+{
+       invalidate();
+}
+
+void ePositionGauge::setPointer(gPixmap *pixmap, const ePoint &center)
+{
+       m_point_center = center;
+       m_point_widget->setPixmap(pixmap);
+       m_point_widget->resize(pixmap->size());
+       updatePosition();
+}
+
+int ePositionGauge::event(int event, void *data, void *data2)
+{
+       switch (event)
+       {
+       case evtPaint:
+       {
+               ePtr<eWindowStyle> style;
+               gPainter &painter = *(gPainter*)data2;
+
+               eSize s(size());
+
+               getStyle(style);
+               style->paintBackground(painter, ePoint(0,0), s);
+               style->setStyle(painter, eWindowStyle::styleLabel); // TODO - own style
+
+               painter.fill(eRect(0, 10, s.width(), s.height()-20));
+               
+#if 0
+// border
+               if (m_have_border_color)
+                       painter.setForegroundColor(m_border_color);
+               painter.fill(eRect(0, 0, s.width(), m_border_width));
+               painter.fill(eRect(0, m_border_width, m_border_width, s.height()-m_border_width));
+               painter.fill(eRect(m_border_width, s.height()-m_border_width, s.width()-m_border_width, m_border_width));
+               painter.fill(eRect(s.width()-m_border_width, m_border_width, m_border_width, s.height()-m_border_width));
+#endif
+
+               return 0;
+       }
+       case evtChangedPosition:
+               return 0;
+       default:
+               return eWidget::event(event, data, data2);
+       }
+}
+
+void ePositionGauge::updatePosition()
+{
+       if (!m_length)
+               return;
+
+       int width = size().width();
+       int x = width * m_position / m_length;
+       m_pos = x;
+       int base = (size().height() - 10) / 2;
+
+       m_point_widget->move(ePoint(m_pos - m_point_center.x(), base - m_point_center.y()));
+}
diff --git a/lib/gui/epositiongauge.h b/lib/gui/epositiongauge.h
new file mode 100644 (file)
index 0000000..6f72fe8
--- /dev/null
@@ -0,0 +1,37 @@
+#ifndef __lib_gui_epositiongauge_h
+#define __lib_gui_epositiongauge_h
+
+#include <lib/gui/ewidget.h>
+
+typedef long long pts_t;
+
+class ePixmap;
+
+class ePositionGauge: public eWidget
+{
+public:
+       ePositionGauge(eWidget *parent);
+       ~ePositionGauge();
+       void setLength(const pts_t &len);
+       void setPosition(const pts_t &pos);
+       
+       void setInColor(const gRGB &color); /* foreground? */
+       void setPointer(gPixmap *pixmap, const ePoint &center);
+#ifndef SWIG
+protected:
+       int event(int event, void *data=0, void *data2=0);
+private:
+       void updatePosition();
+       enum ePositionGaugeEvent
+       {
+               evtChangedPosition = evtUserWidget
+       };
+       ePixmap *m_point_widget;
+       ePoint m_point_center;
+       
+       pts_t m_position, m_length;
+       int m_pos;
+#endif
+};
+
+#endif
index 322b3e5..8261385 100644 (file)
@@ -57,6 +57,7 @@ is usually caused by not marking PSignals as immutable.
 #include <lib/gui/ewindowstyleskinned.h>
 #include <lib/gui/ewidgetanimation.h>
 #include <lib/gui/eslider.h>
+#include <lib/gui/epositiongauge.h>
 #include <lib/python/connections.h>
 #include <lib/gui/elistbox.h>
 #include <lib/gui/elistboxcontent.h>
@@ -159,6 +160,7 @@ typedef long time_t;
 %include <lib/gui/ebutton.h>
 %include <lib/gui/ewindow.h>
 %include <lib/gui/eslider.h>
+%include <lib/gui/epositiongauge.h>
 %include <lib/gui/ewidgetdesktop.h>
 %include <lib/gui/elistbox.h>
 %include <lib/gui/elistboxcontent.h>