aboutsummaryrefslogtreecommitdiff
path: root/lib/gui/epositiongauge.cpp
blob: e16d22260c05aa2d062f9cf856b674c1f25c898a (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
#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;
}

ePositionGauge::~ePositionGauge()
{
	delete m_point_widget;
}

void ePositionGauge::setLength(const pts_t &len)
{
	eDebug("set len: %llx", len);
	if (m_length == len)
		return;
	m_length = len;
	updatePosition();
}

void ePositionGauge::setPosition(const pts_t &pos)
{
	eDebug("set position: %llx", pos);
	if (m_position == pos)
		return;
	m_position = pos;
	updatePosition();
}

void ePositionGauge::setInColor(const gRGB &color)
{
	invalidate();
}

void ePositionGauge::setPointer(gPixmap *pixmap, const ePoint &center)
{
	m_point_center = center;
	m_point_widget->setPixmap(pixmap);
	m_point_widget->resize(pixmap->size());
	updatePosition();
}

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);
		style->paintBackground(painter, ePoint(0,0), s);
		style->setStyle(painter, eWindowStyle::styleLabel); // TODO - own style
		painter.setForegroundColor(gRGB(0x225b7395));

		painter.fill(eRect(0, 10, s.width(), s.height()-14));
		
//		painter.setForegroundColor(gRGB(0x00000000));
		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()
{
	if (!m_length)
		return;

	int width = size().width();
	int x = width * m_position / m_length;
	m_pos = x;
	int base = (size().height() - 10) / 2;

	m_point_widget->move(ePoint(m_pos - m_point_center.x(), base - m_point_center.y()));
}