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 */
131 int xm = scale(i->where);
132 painter.setForegroundColor(gRGB(0xFF8080));
133 painter.fill(eRect(xm - 2, 0, 4, s.height()));
139 if (m_have_foreground_color)
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));
148 if (i == m_cue_entries.end())
151 // painter.setForegroundColor(gRGB(0x00000000));
153 if (m_have_foreground_color)
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));
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));
172 case evtChangedPosition:
175 return eWidget::event(event, data, data2);
179 void ePositionGauge::updatePosition()
181 m_pos = scale(m_position);
182 m_seek_pos = scale(m_seek_position);
183 int base = (size().height() - 10) / 2;
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()));
189 int ePositionGauge::scale(const pts_t &val)
194 int width = size().width();
196 return width * val / m_length;
199 void ePositionGauge::setForegroundColor(const gRGB &col)
201 if ((!m_have_foreground_color) || !(m_foreground_color == col))
203 m_foreground_color = col;
204 m_have_foreground_color = 1;
209 void ePositionGauge::enableSeekPointer(int enable)
212 m_seek_point_widget->show();
214 m_seek_point_widget->hide();
217 void ePositionGauge::setSeekPosition(const pts_t &pos)
219 if (m_seek_position == pos)
221 m_seek_position = pos;