1 #include <lib/gui/eslider.h>
3 eSlider::eSlider(eWidget *parent)
4 :eWidget(parent), m_have_border_color(false), m_start(0), m_orientation(orHorizontal), m_border_width(0)
8 void eSlider::setPixmap(ePtr<gPixmap> &pixmap)
10 setPixmap(pixmap.operator->());
13 void eSlider::setPixmap(gPixmap *pixmap)
16 event(evtChangedSlider);
19 void eSlider::setBorderWidth(int pixel)
25 void eSlider::setBorderColor(const gRGB &color)
28 m_have_border_color=true;
32 int eSlider::event(int event, void *data, void *data2)
38 ePtr<eWindowStyle> style;
42 /* paint background */
43 eWidget::event(evtPaint, data, data2);
45 gPainter &painter = *(gPainter*)data2;
47 style->setStyle(painter, eWindowStyle::styleLabel); // TODO - own style
50 painter.fill(m_currently_filled);
52 painter.blit(m_pixmap, ePoint(0, 0), m_currently_filled.extends, isTransparent() ? gPainter::BT_ALPHATEST : 0);
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));
64 case evtChangedSlider:
66 int num_pix = 0, start_pix = 0;
67 gRegion old_currently_filled = m_currently_filled;
69 int pixsize = (m_orientation == orHorizontal) ? size().width() : size().height();
73 num_pix = pixsize * (m_value - m_start) / (m_max - m_min);
74 start_pix = pixsize * m_start / (m_max - m_min);
86 if (m_orientation == orHorizontal)
87 m_currently_filled = eRect(start_pix, 0, num_pix, pixsize);
89 m_currently_filled = eRect(0, start_pix, pixsize, num_pix);
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);
99 return eWidget::event(event, data, data2);
103 void eSlider::setValue(int value)
106 event(evtChangedSlider);
109 void eSlider::setStartEnd(int start, int end)
113 event(evtChangedSlider);
116 void eSlider::setOrientation(int orientation)
118 m_orientation = orientation;
119 event(evtChangedSlider);
122 void eSlider::setRange(int min, int max)
126 event(evtChangedSlider);