aboutsummaryrefslogtreecommitdiff
path: root/lib/gui/epositiongauge.cpp
blob: ff98c080835532c4565558bb35254616b2673839 (plain)
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#include <lib/gui/epositiongauge.h>
#include <lib/gui/epixmap.h>

ePositionGauge::ePositionGauge(eWidget *parent)
	: eWidget(parent)
{
	m_point_widget = new ePixmap(this);
	m_seek_point_widget = new ePixmap(this);
	m_seek_point_widget->hide();
	m_point_widget->setAlphatest(1);
	m_seek_point_widget->setAlphatest(1);
	m_position = 0;
	m_length = 0;
	m_have_foreground_color = 0;
	m_seek_position = 0;
}

ePositionGauge::~ePositionGauge()
{
	delete m_point_widget;
	delete m_seek_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(int which, ePtr<gPixmap> &pixmap, const ePoint &center)
{
	setPointer(which, pixmap.operator->(), center);
}

void ePositionGauge::setPointer(int which, gPixmap *pixmap, const ePoint &center)
{
	if (which == 0)
	{
		m_point_center = center;
		m_point_widget->setPixmap(pixmap);
		m_point_widget->resize(pixmap->size());
	} else
	{
		m_seek_point_center = center;
		m_seek_point_widget->setPixmap(pixmap);
		m_seek_point_widget->resize(pixmap->size());
	}
	updatePosition();
}

void ePositionGauge::setInOutList(ePyObject list)
{
	if (!PyList_Check(list))
		return;
	int size = PyList_Size(list);
	int i;
	
	m_cue_entries.clear();
	
	for (i=0; i<size; ++i)
	{
		ePyObject tuple = PyList_GET_ITEM(list, i);
		if (!PyTuple_Check(tuple))
			continue;

		if (PyTuple_Size(tuple) != 2)
			continue;

		ePyObject ppts = PyTuple_GET_ITEM(tuple, 0), ptype = PyTuple_GET_ITEM(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 if (i->what == 2) /* mark */
				{
					int xm = scale(i->where);
					painter.setForegroundColor(gRGB(0xFF8080));
					painter.fill(eRect(xm - 2, 0, 4, s.height()));
					i++;
					continue;
				} else /* other marker, like last position */
				{
					++i;
					continue;
				}
			}
			
			if (m_have_foreground_color)
			{
				painter.setForegroundColor(gRGB(m_foreground_color));
				int xi = scale(in), xo = scale(out);
				painter.fill(eRect(xi, (s.height()-4) / 2, xo-xi, 4));
			}
			
			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);
	m_seek_pos = scale(m_seek_position);
	int base = (size().height() - 10) / 2;
	
	m_point_widget->move(ePoint(m_pos - m_point_center.x(), base - m_point_center.y()));
	m_seek_point_widget->move(ePoint(m_seek_pos - m_seek_point_center.x(), base - m_seek_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();
	}
}

void ePositionGauge::enableSeekPointer(int enable)
{
	if (enable)
		m_seek_point_widget->show();
	else
		m_seek_point_widget->hide();
}

void ePositionGauge::setSeekPosition(const pts_t &pos)
{
	if (m_seek_position == pos)
		return;
	m_seek_position = pos;
	updatePosition();
}