add cutlist support to position gauge
authorFelix Domke <tmbinc@elitedvb.net>
Fri, 24 Feb 2006 22:31:39 +0000 (22:31 +0000)
committerFelix Domke <tmbinc@elitedvb.net>
Fri, 24 Feb 2006 22:31:39 +0000 (22:31 +0000)
lib/gui/epositiongauge.cpp
lib/gui/epositiongauge.h

index e16d22260c05aa2d062f9cf856b674c1f25c898a..75b592d202f77eda88a4cd1ffa565d692bf0ad4d 100644 (file)
@@ -22,6 +22,7 @@ void ePositionGauge::setLength(const pts_t &len)
                return;
        m_length = len;
        updatePosition();
+       invalidate();
 }
 
 void ePositionGauge::setPosition(const pts_t &pos)
@@ -46,6 +47,35 @@ void ePositionGauge::setPointer(gPixmap *pixmap, const ePoint &center)
        updatePosition();
 }
 
+void ePositionGauge::setInOutList(PyObject *list)
+{
+       if (!PyList_Check(list))
+               return;
+       int size = PyList_Size(list);
+       int i;
+       
+       m_cue_entries.clear();
+       
+       for (i=0; i<size; ++i)
+       {
+               PyObject *tuple = PyList_GetItem(list, i);
+               if (!PyTuple_Check(tuple))
+                       continue;
+
+               if (PyTuple_Size(tuple) != 2)
+                       continue;
+
+               PyObject *ppts = PyTuple_GetItem(tuple, 0), *ptype = PyTuple_GetItem(tuple, 1);
+               if (!(PyLong_Check(ppts) && PyInt_Check(ptype)))
+                       continue;
+
+               pts_t pts = PyLong_AsLongLong(ppts);
+               int type = PyInt_AsLong(ptype);
+               m_cue_entries.insert(cueEntry(pts, type));
+       }
+       invalidate();
+}
+
 int ePositionGauge::event(int event, void *data, void *data2)
 {
        switch (event)
@@ -60,11 +90,43 @@ int ePositionGauge::event(int event, void *data, void *data2)
                getStyle(style);
                style->paintBackground(painter, ePoint(0,0), s);
                style->setStyle(painter, eWindowStyle::styleLabel); // TODO - own style
-               painter.setForegroundColor(gRGB(0x225b7395));
-
-               painter.fill(eRect(0, 10, s.width(), s.height()-14));
+//             painter.fill(eRect(0, 10, s.width(), s.height()-20));
                
+               pts_t in = 0, out = 0;
+               
+               std::multiset<cueEntry>::iterator i(m_cue_entries.begin());
+               
+               while (1)
+               {
+                       if (i == m_cue_entries.end())
+                               out = m_length;
+                       else {
+                               if (i->what == 0) /* in */
+                               {
+                                       in = i++->where;
+                                       continue;
+                               } else if (i->what == 1) /* out */
+                                       out = i++->where;
+                               else /* mark */
+                               {
+                                       int xm = scale(i->where);
+                                       painter.setForegroundColor(gRGB(0xFF8080));
+                                       painter.fill(eRect(xm - 2, 0, 4, s.height()));
+                                       i++;
+                                       continue;
+                               }
+                       }
+                       
+                       painter.setForegroundColor(gRGB(0x225b7395));
+                       int xi = scale(in), xo = scale(out);
+                       painter.fill(eRect(xi, 10, xo-xi, s.height()-14));
+                       in = m_length;
+                       
+                       if (i == m_cue_entries.end())
+                               break;
+               }
 //             painter.setForegroundColor(gRGB(0x00000000));
+               painter.setForegroundColor(gRGB(0x225b7395));
                painter.fill(eRect(s.width() - 2, 2, s.width() - 1, s.height() - 4));
                painter.fill(eRect(0, 2, 2, s.height() - 4));
                
@@ -88,14 +150,19 @@ int ePositionGauge::event(int event, void *data, void *data2)
 }
 
 void ePositionGauge::updatePosition()
+{
+       m_pos = scale(m_position);
+       int base = (size().height() - 10) / 2;
+       
+       m_point_widget->move(ePoint(m_pos - m_point_center.x(), base - m_point_center.y()));
+}
+
+int ePositionGauge::scale(const pts_t &val)
 {
        if (!m_length)
-               return;
+               return 0;
 
        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()));
+       return width * val / m_length;
 }
index 6f72fe802c1fa582178b23dc21e3098ac9a418d0..0fa704c303418c27186acc88e1739cc4f98643ad 100644 (file)
@@ -2,6 +2,7 @@
 #define __lib_gui_epositiongauge_h
 
 #include <lib/gui/ewidget.h>
+#include <set>
 
 typedef long long pts_t;
 
@@ -17,6 +18,8 @@ public:
        
        void setInColor(const gRGB &color); /* foreground? */
        void setPointer(gPixmap *pixmap, const ePoint &center);
+       
+       void setInOutList(PyObject *list);
 #ifndef SWIG
 protected:
        int event(int event, void *data=0, void *data2=0);
@@ -31,6 +34,25 @@ private:
        
        pts_t m_position, m_length;
        int m_pos;
+
+               /* TODO: this is duplicated code from lib/service/servicedvb.h */
+       struct cueEntry
+       {
+               pts_t where;
+               unsigned int what;
+               
+               bool operator < (const struct cueEntry &o) const
+               {
+                       return what < o.what;
+               }
+               cueEntry(const pts_t &where, unsigned int what) :
+                       where(where), what(what)
+               {
+               }
+       };
+       
+       std::multiset<cueEntry> m_cue_entries;
+       int scale(const pts_t &val);
 #endif
 };