GraphMultiEpg/plugin.py: fix not working zap function when the bouquet is changed...
[enigma2.git] / lib / gui / eslider.cpp
1 #include <lib/gui/eslider.h>
2
3 eSlider::eSlider(eWidget *parent)
4         :eWidget(parent), m_have_border_color(false), m_start(0), m_orientation(orHorizontal), m_border_width(0)
5 {
6 }
7
8 void eSlider::setPixmap(ePtr<gPixmap> &pixmap)
9 {
10         setPixmap(pixmap.operator->());
11 }
12
13 void eSlider::setPixmap(gPixmap *pixmap)
14 {
15         m_pixmap = pixmap;
16         event(evtChangedSlider);
17 }
18
19 void eSlider::setBorderWidth(int pixel)
20 {
21         m_border_width=pixel;
22         invalidate();
23 }
24
25 void eSlider::setBorderColor(const gRGB &color)
26 {
27         m_border_color=color;
28         m_have_border_color=true;
29         invalidate();
30 }
31
32 int eSlider::event(int event, void *data, void *data2)
33 {
34         switch (event)
35         {
36         case evtPaint:
37         {
38                 ePtr<eWindowStyle> style;
39
40                 eSize s(size());
41                 getStyle(style);
42                         /* paint background */
43                 eWidget::event(evtPaint, data, data2);
44
45                 gPainter &painter = *(gPainter*)data2;
46
47                 style->setStyle(painter, eWindowStyle::styleLabel); // TODO - own style
48                 
49                 if (!m_pixmap)
50                         painter.fill(m_currently_filled);
51                 else
52                         painter.blit(m_pixmap, ePoint(0, 0), m_currently_filled.extends, isTransparent() ? gPainter::BT_ALPHATEST : 0);
53
54 // border
55                 if (m_have_border_color)
56                         painter.setForegroundColor(m_border_color);
57                 painter.fill(eRect(0, 0, s.width(), m_border_width));
58                 painter.fill(eRect(0, m_border_width, m_border_width, s.height()-m_border_width));
59                 painter.fill(eRect(m_border_width, s.height()-m_border_width, s.width()-m_border_width, m_border_width));
60                 painter.fill(eRect(s.width()-m_border_width, m_border_width, m_border_width, s.height()-m_border_width));
61
62                 return 0;
63         }
64         case evtChangedSlider:
65         {
66                 int num_pix = 0, start_pix = 0;
67                 gRegion old_currently_filled = m_currently_filled;
68
69                 int pixsize = (m_orientation == orHorizontal) ? size().width() : size().height();
70
71                 if (m_min < m_max)
72                 {
73                         num_pix = pixsize * (m_value - m_start) / (m_max - m_min);
74                         start_pix = pixsize * m_start / (m_max - m_min);
75                 }
76                 
77                 if  (start_pix < 0)
78                 {
79                         num_pix += start_pix;
80                         start_pix = 0;
81                 }
82                 
83                 if (num_pix < 0)
84                         num_pix = 0;
85
86                 if (m_orientation == orHorizontal)
87                         m_currently_filled = eRect(start_pix, 0, num_pix, pixsize);
88                 else
89                         m_currently_filled = eRect(0, start_pix, pixsize, num_pix);
90
91                         // redraw what *was* filled before and now isn't.
92                 invalidate(m_currently_filled - old_currently_filled);
93                         // redraw what wasn't filled before and is now.
94                 invalidate(old_currently_filled - m_currently_filled);
95                 
96                 return 0;
97         }
98         default:
99                 return eWidget::event(event, data, data2);
100         }
101 }
102
103 void eSlider::setValue(int value)
104 {
105         m_value = value;
106         event(evtChangedSlider);
107 }
108
109 void eSlider::setStartEnd(int start, int end)
110 {
111         m_value = end;
112         m_start = start;
113         event(evtChangedSlider);
114 }
115
116 void eSlider::setOrientation(int orientation)
117 {
118         m_orientation = orientation;
119         event(evtChangedSlider);
120 }
121
122 void eSlider::setRange(int min, int max)
123 {
124         m_min = min;
125         m_max = max;
126         event(evtChangedSlider);
127 }