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