1 #include <lib/gui/epositiongauge.h>
2 #include <lib/gui/epixmap.h>
4 ePositionGauge::ePositionGauge(eWidget *parent)
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);
14 m_have_foreground_color = 0;
18 ePositionGauge::~ePositionGauge()
20 delete m_point_widget;
21 delete m_seek_point_widget;
24 void ePositionGauge::setLength(const pts_t &len)
33 void ePositionGauge::setPosition(const pts_t &pos)
35 if (m_position == pos)
41 void ePositionGauge::setInColor(const gRGB &color)
46 void ePositionGauge::setPointer(int which, ePtr<gPixmap> &pixmap, const ePoint ¢er)
48 setPointer(which, pixmap.operator->(), center);
51 void ePositionGauge::setPointer(int which, gPixmap *pixmap, const ePoint ¢er)
55 m_point_center = center;
56 m_point_widget->setPixmap(pixmap);
57 m_point_widget->resize(pixmap->size());
60 m_seek_point_center = center;
61 m_seek_point_widget->setPixmap(pixmap);
62 m_seek_point_widget->resize(pixmap->size());
67 void ePositionGauge::setInOutList(ePyObject list)
69 if (!PyList_Check(list))
71 int size = PyList_Size(list);
74 m_cue_entries.clear();
76 for (i=0; i<size; ++i)
78 ePyObject tuple = PyList_GET_ITEM(list, i);
79 if (!PyTuple_Check(tuple))
82 if (PyTuple_Size(tuple) != 2)
85 ePyObject ppts = PyTuple_GET_ITEM(tuple, 0), ptype = PyTuple_GET_ITEM(tuple, 1);
86 if (!(PyLong_Check(ppts) && PyInt_Check(ptype)))
89 pts_t pts = PyLong_AsLongLong(ppts);
90 int type = PyInt_AsLong(ptype);
91 m_cue_entries.insert(cueEntry(pts, type));
96 int ePositionGauge::event(int event, void *data, void *data2)
102 ePtr<eWindowStyle> style;
103 gPainter &painter = *(gPainter*)data2;
109 eWidget::event(evtPaint, data, data2);
111 style->setStyle(painter, eWindowStyle::styleLabel); // TODO - own style
112 // painter.fill(eRect(0, 10, s.width(), s.height()-20));
114 pts_t in = 0, out = 0;
116 std::multiset<cueEntry>::iterator i(m_cue_entries.begin());
120 if (i == m_cue_entries.end())
123 if (i->what == 0) /* in */
127 } else if (i->what == 1) /* out */
129 else if (i->what == 2) /* mark */
131 int xm = scale(i->where);
132 painter.setForegroundColor(gRGB(0xFF8080));
133 painter.fill(eRect(xm - 2, 0, 4, s.height()));
136 } else /* other marker, like last position */
143 if (m_have_foreground_color)
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));
152 if (i == m_cue_entries.end())
155 // painter.setForegroundColor(gRGB(0x00000000));
157 if (m_have_foreground_color)
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));
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));
176 case evtChangedPosition:
179 return eWidget::event(event, data, data2);
183 void ePositionGauge::updatePosition()
185 m_pos = scale(m_position);
186 m_seek_pos = scale(m_seek_position);
187 int base = (size().height() - 10) / 2;
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()));
193 int ePositionGauge::scale(const pts_t &val)
198 int width = size().width();
200 return width * val / m_length;
203 void ePositionGauge::setForegroundColor(const gRGB &col)
205 if ((!m_have_foreground_color) || !(m_foreground_color == col))
207 m_foreground_color = col;
208 m_have_foreground_color = 1;
213 void ePositionGauge::enableSeekPointer(int enable)
216 m_seek_point_widget->show();
218 m_seek_point_widget->hide();
221 void ePositionGauge::setSeekPosition(const pts_t &pos)
223 if (m_seek_position == pos)
225 m_seek_position = pos;