fix warning
[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::setBorderWidth(int pixel)
9 {
10         m_border_width=pixel;
11         invalidate();
12 }
13
14 void eSlider::setBorderColor(const gRGB &color)
15 {
16         m_border_color=color;
17         m_have_border_color=true;
18         invalidate();
19 }
20
21 int eSlider::event(int event, void *data, void *data2)
22 {
23         switch (event)
24         {
25         case evtPaint:
26         {
27                 ePtr<eWindowStyle> style;
28                 gPainter &painter = *(gPainter*)data2;
29
30                 eSize s(size());
31
32                 getStyle(style);
33                 style->paintBackground(painter, ePoint(0,0), s);
34                 style->setStyle(painter, eWindowStyle::styleLabel); // TODO - own style
35                 painter.fill(m_currently_filled);
36
37 // border
38                 if (m_have_border_color)
39                         painter.setForegroundColor(m_border_color);
40                 painter.fill(eRect(0, 0, s.width(), m_border_width));
41                 painter.fill(eRect(0, m_border_width, m_border_width, s.height()-m_border_width));
42                 painter.fill(eRect(m_border_width, s.height()-m_border_width, s.width()-m_border_width, m_border_width));
43                 painter.fill(eRect(s.width()-m_border_width, m_border_width, m_border_width, s.height()-m_border_width));
44
45                 return 0;
46         }
47         case evtChangedSlider:
48         {
49                 int num_pix = 0, start_pix = 0;
50                 gRegion old_currently_filled = m_currently_filled;
51
52                 int pixsize = (m_orientation == orHorizontal) ? size().width() : size().height();
53
54                 if (m_min < m_max)
55                 {
56                         num_pix = pixsize * (m_value - m_start) / (m_max - m_min);
57                         start_pix = pixsize * m_start / (m_max - m_min);
58                 }
59                 
60                 if  (start_pix < 0)
61                 {
62                         num_pix += start_pix;
63                         start_pix = 0;
64                 }
65                 
66                 if (num_pix < 0)
67                         num_pix = 0;
68
69                 if (m_orientation == orHorizontal)
70                         m_currently_filled = eRect(start_pix, 0, num_pix, pixsize);
71                 else
72                         m_currently_filled = eRect(0, start_pix, pixsize, num_pix);
73
74                         // redraw what *was* filled before and now isn't.
75                 invalidate(m_currently_filled - old_currently_filled);
76                         // redraw what wasn't filled before and is now.
77                 invalidate(old_currently_filled - m_currently_filled);
78                 
79                 return 0;
80         }
81         default:
82                 return eWidget::event(event, data, data2);
83         }
84 }
85
86 void eSlider::setValue(int value)
87 {
88         m_value = value;
89         event(evtChangedSlider);
90 }
91
92 void eSlider::setStartEnd(int start, int end)
93 {
94         m_value = end;
95         m_start = start;
96         event(evtChangedSlider);
97 }
98
99 void eSlider::setOrientation(int orientation)
100 {
101         m_orientation = orientation;
102         event(evtChangedSlider);
103 }
104
105 void eSlider::setRange(int min, int max)
106 {
107         m_min = min;
108         m_max = max;
109         event(evtChangedSlider);
110 }