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);
11 m_have_foreground_color = 0;
14 ePositionGauge::~ePositionGauge()
16 delete m_point_widget;
19 void ePositionGauge::setLength(const pts_t &len)
28 void ePositionGauge::setPosition(const pts_t &pos)
30 if (m_position == pos)
36 void ePositionGauge::setInColor(const gRGB &color)
41 void ePositionGauge::setPointer(gPixmap *pixmap, const ePoint ¢er)
43 m_point_center = center;
44 m_point_widget->setPixmap(pixmap);
45 m_point_widget->resize(pixmap->size());
49 void ePositionGauge::setInOutList(PyObject *list)
51 if (!PyList_Check(list))
53 int size = PyList_Size(list);
56 m_cue_entries.clear();
58 for (i=0; i<size; ++i)
60 PyObject *tuple = PyList_GetItem(list, i);
61 if (!PyTuple_Check(tuple))
64 if (PyTuple_Size(tuple) != 2)
67 PyObject *ppts = PyTuple_GetItem(tuple, 0), *ptype = PyTuple_GetItem(tuple, 1);
68 if (!(PyLong_Check(ppts) && PyInt_Check(ptype)))
71 pts_t pts = PyLong_AsLongLong(ppts);
72 int type = PyInt_AsLong(ptype);
73 m_cue_entries.insert(cueEntry(pts, type));
78 int ePositionGauge::event(int event, void *data, void *data2)
84 ePtr<eWindowStyle> style;
85 gPainter &painter = *(gPainter*)data2;
91 eWidget::event(evtPaint, data, data2);
93 style->setStyle(painter, eWindowStyle::styleLabel); // TODO - own style
94 // painter.fill(eRect(0, 10, s.width(), s.height()-20));
96 pts_t in = 0, out = 0;
98 std::multiset<cueEntry>::iterator i(m_cue_entries.begin());
102 if (i == m_cue_entries.end())
105 if (i->what == 0) /* in */
109 } else if (i->what == 1) /* out */
113 int xm = scale(i->where);
114 painter.setForegroundColor(gRGB(0xFF8080));
115 painter.fill(eRect(xm - 2, 0, 4, s.height()));
121 if (m_have_foreground_color)
123 painter.setForegroundColor(gRGB(m_foreground_color));
124 int xi = scale(in), xo = scale(out);
125 painter.fill(eRect(xi, 10, xo-xi, s.height()-14));
130 if (i == m_cue_entries.end())
133 // painter.setForegroundColor(gRGB(0x00000000));
135 if (m_have_foreground_color)
137 painter.setForegroundColor(gRGB(0x225b7395));
138 painter.fill(eRect(s.width() - 2, 2, s.width() - 1, s.height() - 4));
139 painter.fill(eRect(0, 2, 2, s.height() - 4));
144 if (m_have_border_color)
145 painter.setForegroundColor(m_border_color);
146 painter.fill(eRect(0, 0, s.width(), m_border_width));
147 painter.fill(eRect(0, m_border_width, m_border_width, s.height()-m_border_width));
148 painter.fill(eRect(m_border_width, s.height()-m_border_width, s.width()-m_border_width, m_border_width));
149 painter.fill(eRect(s.width()-m_border_width, m_border_width, m_border_width, s.height()-m_border_width));
154 case evtChangedPosition:
157 return eWidget::event(event, data, data2);
161 void ePositionGauge::updatePosition()
163 m_pos = scale(m_position);
164 int base = (size().height() - 10) / 2;
166 m_point_widget->move(ePoint(m_pos - m_point_center.x(), base - m_point_center.y()));
169 int ePositionGauge::scale(const pts_t &val)
174 int width = size().width();
176 return width * val / m_length;
179 void ePositionGauge::setForegroundColor(const gRGB &col)
181 if ((!m_have_foreground_color) || !(m_foreground_color == col))
183 m_foreground_color = col;
184 m_have_foreground_color = 1;