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_point_widget->setAlphatest(1);
13 ePositionGauge::~ePositionGauge()
15 delete m_point_widget;
18 void ePositionGauge::setLength(const pts_t &len)
27 void ePositionGauge::setPosition(const pts_t &pos)
29 if (m_position == pos)
35 void ePositionGauge::setInColor(const gRGB &color)
40 void ePositionGauge::setPointer(gPixmap *pixmap, const ePoint ¢er)
42 m_point_center = center;
43 m_point_widget->setPixmap(pixmap);
44 m_point_widget->resize(pixmap->size());
48 void ePositionGauge::setInOutList(PyObject *list)
50 if (!PyList_Check(list))
52 int size = PyList_Size(list);
55 m_cue_entries.clear();
57 for (i=0; i<size; ++i)
59 PyObject *tuple = PyList_GetItem(list, i);
60 if (!PyTuple_Check(tuple))
63 if (PyTuple_Size(tuple) != 2)
66 PyObject *ppts = PyTuple_GetItem(tuple, 0), *ptype = PyTuple_GetItem(tuple, 1);
67 if (!(PyLong_Check(ppts) && PyInt_Check(ptype)))
70 pts_t pts = PyLong_AsLongLong(ppts);
71 int type = PyInt_AsLong(ptype);
72 m_cue_entries.insert(cueEntry(pts, type));
77 int ePositionGauge::event(int event, void *data, void *data2)
83 ePtr<eWindowStyle> style;
84 gPainter &painter = *(gPainter*)data2;
89 style->paintBackground(painter, ePoint(0,0), s);
90 style->setStyle(painter, eWindowStyle::styleLabel); // TODO - own style
91 // painter.fill(eRect(0, 10, s.width(), s.height()-20));
93 pts_t in = 0, out = 0;
95 std::multiset<cueEntry>::iterator i(m_cue_entries.begin());
99 if (i == m_cue_entries.end())
102 if (i->what == 0) /* in */
106 } else if (i->what == 1) /* out */
110 int xm = scale(i->where);
111 painter.setForegroundColor(gRGB(0xFF8080));
112 painter.fill(eRect(xm - 2, 0, 4, s.height()));
118 painter.setForegroundColor(gRGB(0x225b7395));
119 int xi = scale(in), xo = scale(out);
120 painter.fill(eRect(xi, 10, xo-xi, s.height()-14));
123 if (i == m_cue_entries.end())
126 // painter.setForegroundColor(gRGB(0x00000000));
127 painter.setForegroundColor(gRGB(0x225b7395));
128 painter.fill(eRect(s.width() - 2, 2, s.width() - 1, s.height() - 4));
129 painter.fill(eRect(0, 2, 2, s.height() - 4));
133 if (m_have_border_color)
134 painter.setForegroundColor(m_border_color);
135 painter.fill(eRect(0, 0, s.width(), m_border_width));
136 painter.fill(eRect(0, m_border_width, m_border_width, s.height()-m_border_width));
137 painter.fill(eRect(m_border_width, s.height()-m_border_width, s.width()-m_border_width, m_border_width));
138 painter.fill(eRect(s.width()-m_border_width, m_border_width, m_border_width, s.height()-m_border_width));
143 case evtChangedPosition:
146 return eWidget::event(event, data, data2);
150 void ePositionGauge::updatePosition()
152 m_pos = scale(m_position);
153 int base = (size().height() - 10) / 2;
155 m_point_widget->move(ePoint(m_pos - m_point_center.x(), base - m_point_center.y()));
158 int ePositionGauge::scale(const pts_t &val)
163 int width = size().width();
165 return width * val / m_length;