1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
#include <lib/gui/epositiongauge.h>
#include <lib/gui/epixmap.h>
ePositionGauge::ePositionGauge(eWidget *parent)
: eWidget(parent)
{
m_point_widget = new ePixmap(this);
m_point_widget->setAlphatest(1);
m_position = 0;
m_length = 0;
m_have_foreground_color = 0;
}
ePositionGauge::~ePositionGauge()
{
delete m_point_widget;
}
void ePositionGauge::setLength(const pts_t &len)
{
if (m_length == len)
return;
m_length = len;
updatePosition();
invalidate();
}
void ePositionGauge::setPosition(const pts_t &pos)
{
if (m_position == pos)
return;
m_position = pos;
updatePosition();
}
void ePositionGauge::setInColor(const gRGB &color)
{
invalidate();
}
void ePositionGauge::setPointer(gPixmap *pixmap, const ePoint ¢er)
{
m_point_center = center;
m_point_widget->setPixmap(pixmap);
m_point_widget->resize(pixmap->size());
updatePosition();
}
void ePositionGauge::setInOutList(PyObject *list)
{
if (!PyList_Check(list))
return;
int size = PyList_Size(list);
int i;
m_cue_entries.clear();
for (i=0; i<size; ++i)
{
PyObject *tuple = PyList_GetItem(list, i);
if (!PyTuple_Check(tuple))
continue;
if (PyTuple_Size(tuple) != 2)
continue;
PyObject *ppts = PyTuple_GetItem(tuple, 0), *ptype = PyTuple_GetItem(tuple, 1);
if (!(PyLong_Check(ppts) && PyInt_Check(ptype)))
continue;
pts_t pts = PyLong_AsLongLong(ppts);
int type = PyInt_AsLong(ptype);
m_cue_entries.insert(cueEntry(pts, type));
}
invalidate();
}
int ePositionGauge::event(int event, void *data, void *data2)
{
switch (event)
{
case evtPaint:
{
ePtr<eWindowStyle> style;
gPainter &painter = *(gPainter*)data2;
eSize s(size());
getStyle(style);
eWidget::event(evtPaint, data, data2);
style->setStyle(painter, eWindowStyle::styleLabel); // TODO - own style
// painter.fill(eRect(0, 10, s.width(), s.height()-20));
pts_t in = 0, out = 0;
std::multiset<cueEntry>::iterator i(m_cue_entries.begin());
while (1)
{
if (i == m_cue_entries.end())
out = m_length;
else {
if (i->what == 0) /* in */
{
in = i++->where;
continue;
} else if (i->what == 1) /* out */
out = i++->where;
else /* mark */
{
int xm = scale(i->where);
painter.setForegroundColor(gRGB(0xFF8080));
painter.fill(eRect(xm - 2, 0, 4, s.height()));
i++;
continue;
}
}
if (m_have_foreground_color)
{
painter.setForegroundColor(gRGB(m_foreground_color));
int xi = scale(in), xo = scale(out);
painter.fill(eRect(xi, 10, xo-xi, s.height()-14));
}
in = m_length;
if (i == m_cue_entries.end())
break;
}
// painter.setForegroundColor(gRGB(0x00000000));
if (m_have_foreground_color)
{
painter.setForegroundColor(gRGB(0x225b7395));
painter.fill(eRect(s.width() - 2, 2, s.width() - 1, s.height() - 4));
painter.fill(eRect(0, 2, 2, s.height() - 4));
}
#if 0
// border
if (m_have_border_color)
painter.setForegroundColor(m_border_color);
painter.fill(eRect(0, 0, s.width(), m_border_width));
painter.fill(eRect(0, m_border_width, m_border_width, s.height()-m_border_width));
painter.fill(eRect(m_border_width, s.height()-m_border_width, s.width()-m_border_width, m_border_width));
painter.fill(eRect(s.width()-m_border_width, m_border_width, m_border_width, s.height()-m_border_width));
#endif
return 0;
}
case evtChangedPosition:
return 0;
default:
return eWidget::event(event, data, data2);
}
}
void ePositionGauge::updatePosition()
{
m_pos = scale(m_position);
int base = (size().height() - 10) / 2;
m_point_widget->move(ePoint(m_pos - m_point_center.x(), base - m_point_center.y()));
}
int ePositionGauge::scale(const pts_t &val)
{
if (!m_length)
return 0;
int width = size().width();
return width * val / m_length;
}
void ePositionGauge::setForegroundColor(const gRGB &col)
{
if ((!m_have_foreground_color) || !(m_foreground_color == col))
{
m_foreground_color = col;
m_have_foreground_color = 1;
invalidate();
}
}
|