revert to 750ms delay for motor powerup.. 200ms is not really enough
[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 /* 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                                 }
137                         }
138                         
139                         if (m_have_foreground_color)
140                         {
141                                 painter.setForegroundColor(gRGB(m_foreground_color));
142                                 int xi = scale(in), xo = scale(out);
143                                 painter.fill(eRect(xi, 10, xo-xi, s.height()-14));
144                         }
145                         
146                         in = m_length;
147                         
148                         if (i == m_cue_entries.end())
149                                 break;
150                 }
151 //              painter.setForegroundColor(gRGB(0x00000000));
152
153                 if (m_have_foreground_color)
154                 {
155                         painter.setForegroundColor(gRGB(0x225b7395));
156                         painter.fill(eRect(s.width() - 2, 2, s.width() - 1, s.height() - 4));
157                         painter.fill(eRect(0, 2, 2, s.height() - 4));
158                 }
159                 
160 #if 0
161 // border
162                 if (m_have_border_color)
163                         painter.setForegroundColor(m_border_color);
164                 painter.fill(eRect(0, 0, s.width(), m_border_width));
165                 painter.fill(eRect(0, m_border_width, m_border_width, s.height()-m_border_width));
166                 painter.fill(eRect(m_border_width, s.height()-m_border_width, s.width()-m_border_width, m_border_width));
167                 painter.fill(eRect(s.width()-m_border_width, m_border_width, m_border_width, s.height()-m_border_width));
168 #endif
169
170                 return 0;
171         }
172         case evtChangedPosition:
173                 return 0;
174         default:
175                 return eWidget::event(event, data, data2);
176         }
177 }
178
179 void ePositionGauge::updatePosition()
180 {
181         m_pos = scale(m_position);
182         m_seek_pos = scale(m_seek_position);
183         int base = (size().height() - 10) / 2;
184         
185         m_point_widget->move(ePoint(m_pos - m_point_center.x(), base - m_point_center.y()));
186         m_seek_point_widget->move(ePoint(m_seek_pos - m_seek_point_center.x(), base - m_seek_point_center.y()));
187 }
188
189 int ePositionGauge::scale(const pts_t &val)
190 {
191         if (!m_length)
192                 return 0;
193
194         int width = size().width();
195
196         return width * val / m_length;
197 }
198
199 void ePositionGauge::setForegroundColor(const gRGB &col)
200 {
201         if ((!m_have_foreground_color) || !(m_foreground_color == col))
202         {
203                 m_foreground_color = col;
204                 m_have_foreground_color = 1;
205                 invalidate();
206         }
207 }
208
209 void ePositionGauge::enableSeekPointer(int enable)
210 {
211         if (enable)
212                 m_seek_point_widget->show();
213         else
214                 m_seek_point_widget->hide();
215 }
216
217 void ePositionGauge::setSeekPosition(const pts_t &pos)
218 {
219         if (m_seek_position == pos)
220                 return;
221         m_seek_position = pos;
222         updatePosition();
223 }