Enigma2: add CleanupWizard to SystemPlugins and Enigma2 build.
[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_orientation_swapped(0), 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                         int val_range = m_max - m_min;
74                         num_pix = (pixsize * (m_value - m_start) + val_range - 1) / val_range; /* properly round up */
75                         start_pix = (pixsize * m_start + val_range - 1) / val_range;
76
77                         if (m_orientation_swapped)
78                                 start_pix = pixsize - num_pix - start_pix;
79                 }
80
81                 if  (start_pix < 0)
82                 {
83                         num_pix += start_pix;
84                         start_pix = 0;
85                 }
86                 
87                 if (num_pix < 0)
88                         num_pix = 0;
89
90                 if (m_orientation == orHorizontal)
91                         m_currently_filled = eRect(start_pix, 0, num_pix, pixsize);
92                 else
93                         m_currently_filled = eRect(0, start_pix, pixsize, num_pix);
94
95                         // redraw what *was* filled before and now isn't.
96                 invalidate(m_currently_filled - old_currently_filled);
97                         // redraw what wasn't filled before and is now.
98                 invalidate(old_currently_filled - m_currently_filled);
99                 
100                 return 0;
101         }
102         default:
103                 return eWidget::event(event, data, data2);
104         }
105 }
106
107 void eSlider::setValue(int value)
108 {
109         m_value = value;
110         event(evtChangedSlider);
111 }
112
113 void eSlider::setStartEnd(int start, int end)
114 {
115         m_value = end;
116         m_start = start;
117         event(evtChangedSlider);
118 }
119
120 void eSlider::setOrientation(int orientation, int swapped)
121 {
122         m_orientation = orientation;
123         m_orientation_swapped = swapped;
124         event(evtChangedSlider);
125 }
126
127 void eSlider::setRange(int min, int max)
128 {
129         m_min = min;
130         m_max = max;
131         event(evtChangedSlider);
132 }