add preStart event and use it to load the cutlist
[enigma2.git] / lib / gui / epositiongauge.cpp
1 #include <lib/gui/epositiongauge.h>
2 #include <lib/gui/epixmap.h>
3
4 ePositionGauge::ePositionGauge(eWidget *parent)
5         : eWidget(parent)
6 {
7         m_point_widget = new ePixmap(this);
8         m_seek_point_widget = new ePixmap(this);
9         m_seek_point_widget->hide();
10         m_point_widget->setAlphatest(1);
11         m_seek_point_widget->setAlphatest(1);
12         m_position = 0;
13         m_length = 0;
14         m_have_foreground_color = 0;
15         m_seek_position = 0;
16 }
17
18 ePositionGauge::~ePositionGauge()
19 {
20         delete m_point_widget;
21         delete m_seek_point_widget;
22 }
23
24 void ePositionGauge::setLength(const pts_t &len)
25 {
26         if (m_length == len)
27                 return;
28         m_length = len;
29         updatePosition();
30         invalidate();
31 }
32
33 void ePositionGauge::setPosition(const pts_t &pos)
34 {
35         if (m_position == pos)
36                 return;
37         m_position = pos;
38         updatePosition();
39 }
40
41 void ePositionGauge::setInColor(const gRGB &color)
42 {
43         invalidate();
44 }
45
46 void ePositionGauge::setPointer(int which, ePtr<gPixmap> &pixmap, const ePoint &center)
47 {
48         setPointer(which, pixmap.operator->(), center);
49 }
50
51 void ePositionGauge::setPointer(int which, gPixmap *pixmap, const ePoint &center)
52 {
53         if (which == 0)
54         {
55                 m_point_center = center;
56                 m_point_widget->setPixmap(pixmap);
57                 m_point_widget->resize(pixmap->size());
58         } else
59         {
60                 m_seek_point_center = center;
61                 m_seek_point_widget->setPixmap(pixmap);
62                 m_seek_point_widget->resize(pixmap->size());
63         }
64         updatePosition();
65 }
66
67 void ePositionGauge::setInOutList(ePyObject list)
68 {
69         if (!PyList_Check(list))
70                 return;
71         int size = PyList_Size(list);
72         int i;
73         
74         m_cue_entries.clear();
75         
76         for (i=0; i<size; ++i)
77         {
78                 ePyObject tuple = PyList_GET_ITEM(list, i);
79                 if (!PyTuple_Check(tuple))
80                         continue;
81
82                 if (PyTuple_Size(tuple) != 2)
83                         continue;
84
85                 ePyObject ppts = PyTuple_GET_ITEM(tuple, 0), ptype = PyTuple_GET_ITEM(tuple, 1);
86                 if (!(PyLong_Check(ppts) && PyInt_Check(ptype)))
87                         continue;
88
89                 pts_t pts = PyLong_AsLongLong(ppts);
90                 int type = PyInt_AsLong(ptype);
91                 m_cue_entries.insert(cueEntry(pts, type));
92         }
93         invalidate();
94 }
95
96 int ePositionGauge::event(int event, void *data, void *data2)
97 {
98         switch (event)
99         {
100         case evtPaint:
101         {
102                 ePtr<eWindowStyle> style;
103                 gPainter &painter = *(gPainter*)data2;
104
105                 eSize s(size());
106
107                 getStyle(style);
108                 
109                 eWidget::event(evtPaint, data, data2);
110
111                 style->setStyle(painter, eWindowStyle::styleLabel); // TODO - own style
112 //              painter.fill(eRect(0, 10, s.width(), s.height()-20));
113                 
114                 pts_t in = 0, out = 0;
115                 
116                 std::multiset<cueEntry>::iterator i(m_cue_entries.begin());
117                 
118                 while (1)
119                 {
120                         if (i == m_cue_entries.end())
121                                 out = m_length;
122                         else {
123                                 if (i->what == 0) /* in */
124                                 {
125                                         in = i++->where;
126                                         continue;
127                                 } else if (i->what == 1) /* out */
128                                         out = i++->where;
129                                 else if (i->what == 2) /* mark */
130                                 {
131                                         int xm = scale(i->where);
132                                         painter.setForegroundColor(gRGB(0xFF8080));
133                                         painter.fill(eRect(xm - 2, 0, 4, s.height()));
134                                         i++;
135                                         continue;
136                                 } else /* other marker, like last position */
137                                 {
138                                         ++i;
139                                         continue;
140                                 }
141                         }
142                         
143                         if (m_have_foreground_color)
144                         {
145                                 painter.setForegroundColor(gRGB(m_foreground_color));
146                                 int xi = scale(in), xo = scale(out);
147                                 painter.fill(eRect(xi, (s.height()-4) / 2, xo-xi, 4));
148                         }
149                         
150                         in = m_length;
151                         
152                         if (i == m_cue_entries.end())
153                                 break;
154                 }
155 //              painter.setForegroundColor(gRGB(0x00000000));
156
157                 if (m_have_foreground_color)
158                 {
159                         painter.setForegroundColor(gRGB(0x225b7395));
160                         painter.fill(eRect(s.width() - 2, 2, s.width() - 1, s.height() - 4));
161                         painter.fill(eRect(0, 2, 2, s.height() - 4));
162                 }
163                 
164 #if 0
165 // border
166                 if (m_have_border_color)
167                         painter.setForegroundColor(m_border_color);
168                 painter.fill(eRect(0, 0, s.width(), m_border_width));
169                 painter.fill(eRect(0, m_border_width, m_border_width, s.height()-m_border_width));
170                 painter.fill(eRect(m_border_width, s.height()-m_border_width, s.width()-m_border_width, m_border_width));
171                 painter.fill(eRect(s.width()-m_border_width, m_border_width, m_border_width, s.height()-m_border_width));
172 #endif
173
174                 return 0;
175         }
176         case evtChangedPosition:
177                 return 0;
178         default:
179                 return eWidget::event(event, data, data2);
180         }
181 }
182
183 void ePositionGauge::updatePosition()
184 {
185         m_pos = scale(m_position);
186         m_seek_pos = scale(m_seek_position);
187         int base = (size().height() - 10) / 2;
188         
189         m_point_widget->move(ePoint(m_pos - m_point_center.x(), base - m_point_center.y()));
190         m_seek_point_widget->move(ePoint(m_seek_pos - m_seek_point_center.x(), base - m_seek_point_center.y()));
191 }
192
193 int ePositionGauge::scale(const pts_t &val)
194 {
195         if (!m_length)
196                 return 0;
197
198         int width = size().width();
199
200         return width * val / m_length;
201 }
202
203 void ePositionGauge::setForegroundColor(const gRGB &col)
204 {
205         if ((!m_have_foreground_color) || !(m_foreground_color == col))
206         {
207                 m_foreground_color = col;
208                 m_have_foreground_color = 1;
209                 invalidate();
210         }
211 }
212
213 void ePositionGauge::enableSeekPointer(int enable)
214 {
215         if (enable)
216                 m_seek_point_widget->show();
217         else
218                 m_seek_point_widget->hide();
219 }
220
221 void ePositionGauge::setSeekPosition(const pts_t &pos)
222 {
223         if (m_seek_position == pos)
224                 return;
225         m_seek_position = pos;
226         updatePosition();
227 }