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)
20 eDebug("set len: %llx", len);
28 void ePositionGauge::setPosition(const pts_t &pos)
30 eDebug("set position: %llx", pos);
31 if (m_position == pos)
37 void ePositionGauge::setInColor(const gRGB &color)
42 void ePositionGauge::setPointer(gPixmap *pixmap, const ePoint ¢er)
44 m_point_center = center;
45 m_point_widget->setPixmap(pixmap);
46 m_point_widget->resize(pixmap->size());
50 void ePositionGauge::setInOutList(PyObject *list)
52 if (!PyList_Check(list))
54 int size = PyList_Size(list);
57 m_cue_entries.clear();
59 for (i=0; i<size; ++i)
61 PyObject *tuple = PyList_GetItem(list, i);
62 if (!PyTuple_Check(tuple))
65 if (PyTuple_Size(tuple) != 2)
68 PyObject *ppts = PyTuple_GetItem(tuple, 0), *ptype = PyTuple_GetItem(tuple, 1);
69 if (!(PyLong_Check(ppts) && PyInt_Check(ptype)))
72 pts_t pts = PyLong_AsLongLong(ppts);
73 int type = PyInt_AsLong(ptype);
74 m_cue_entries.insert(cueEntry(pts, type));
79 int ePositionGauge::event(int event, void *data, void *data2)
85 ePtr<eWindowStyle> style;
86 gPainter &painter = *(gPainter*)data2;
91 style->paintBackground(painter, ePoint(0,0), s);
92 style->setStyle(painter, eWindowStyle::styleLabel); // TODO - own style
93 // painter.fill(eRect(0, 10, s.width(), s.height()-20));
95 pts_t in = 0, out = 0;
97 std::multiset<cueEntry>::iterator i(m_cue_entries.begin());
101 if (i == m_cue_entries.end())
104 if (i->what == 0) /* in */
108 } else if (i->what == 1) /* out */
112 int xm = scale(i->where);
113 painter.setForegroundColor(gRGB(0xFF8080));
114 painter.fill(eRect(xm - 2, 0, 4, s.height()));
120 painter.setForegroundColor(gRGB(0x225b7395));
121 int xi = scale(in), xo = scale(out);
122 painter.fill(eRect(xi, 10, xo-xi, s.height()-14));
125 if (i == m_cue_entries.end())
128 // painter.setForegroundColor(gRGB(0x00000000));
129 painter.setForegroundColor(gRGB(0x225b7395));
130 painter.fill(eRect(s.width() - 2, 2, s.width() - 1, s.height() - 4));
131 painter.fill(eRect(0, 2, 2, s.height() - 4));
135 if (m_have_border_color)
136 painter.setForegroundColor(m_border_color);
137 painter.fill(eRect(0, 0, s.width(), m_border_width));
138 painter.fill(eRect(0, m_border_width, m_border_width, s.height()-m_border_width));
139 painter.fill(eRect(m_border_width, s.height()-m_border_width, s.width()-m_border_width, m_border_width));
140 painter.fill(eRect(s.width()-m_border_width, m_border_width, m_border_width, s.height()-m_border_width));
145 case evtChangedPosition:
148 return eWidget::event(event, data, data2);
152 void ePositionGauge::updatePosition()
154 m_pos = scale(m_position);
155 int base = (size().height() - 10) / 2;
157 m_point_widget->move(ePoint(m_pos - m_point_center.x(), base - m_point_center.y()));
160 int ePositionGauge::scale(const pts_t &val)
165 int width = size().width();
167 return width * val / m_length;