isCompatible with can now handle all frontend types
[enigma2.git] / lib / gui / eslider.cpp
1 #include <lib/gui/eslider.h>
2
3 eSlider::eSlider(eWidget *parent): eWidget(parent), m_orientation(orHorizontal), m_start(0)
4 {
5 }
6
7 int eSlider::event(int event, void *data, void *data2)
8 {
9         switch (event)
10         {
11         case evtPaint:
12         {
13                 ePtr<eWindowStyle> style;
14                 gPainter &painter = *(gPainter*)data2;
15                 
16                 getStyle(style);
17                 style->paintBackground(painter, ePoint(0, 0), size());
18                 style->setStyle(painter, eWindowStyle::styleLabel); // TODO - own style
19                 painter.fill(m_currently_filled);
20                 
21                 return 0;
22         }
23         case evtChangedSlider:
24         {
25                 int num_pix = 0, start_pix = 0;
26                 gRegion old_currently_filled = m_currently_filled;
27                 
28                 int pixsize = (m_orientation == orHorizontal) ? size().width() : size().height();
29                 
30                 if (m_min < m_max)
31                 {
32                         num_pix = pixsize * (m_value - m_start) / (m_max - m_min);
33                         start_pix = pixsize * m_start / (m_max - m_min);
34                 }
35                 
36                 if  (start_pix < 0)
37                 {
38                         num_pix += start_pix;
39                         start_pix = 0;
40                 }
41                 
42                 if (num_pix < 0)
43                         num_pix = 0;
44
45                 if (m_orientation == orHorizontal)
46                         m_currently_filled = eRect(start_pix, 0, num_pix, size().height());
47                 else
48                         m_currently_filled = eRect(0, start_pix, size().width(), num_pix);
49                 
50                         // redraw what *was* filled before and now isn't.
51                 invalidate(m_currently_filled - old_currently_filled);
52                         // redraw what wasn't filled before and is now.
53                 invalidate(old_currently_filled - m_currently_filled);
54                 
55                 return 0;
56         }
57         default:
58                 return eWidget::event(event, data, data2);
59         }
60 }
61
62 void eSlider::setValue(int value)
63 {
64         m_value = value;
65         event(evtChangedSlider);
66 }
67
68 void eSlider::setStartEnd(int start, int end)
69 {
70         m_value = end;
71         m_start = start;
72         event(evtChangedSlider);
73 }
74
75 void eSlider::setOrientation(int orientation)
76 {
77         m_orientation = orientation;
78         event(evtChangedSlider);
79 }
80
81 void eSlider::setRange(int min, int max)
82 {
83         m_min = min;
84         m_max = max;
85         event(evtChangedSlider);
86 }