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_orientation_swapped(0), 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 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;
77 if (m_orientation_swapped)
78 start_pix = pixsize - num_pix - start_pix;
90 if (m_orientation == orHorizontal)
91 m_currently_filled = eRect(start_pix, 0, num_pix, pixsize);
93 m_currently_filled = eRect(0, start_pix, pixsize, num_pix);
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);
103 return eWidget::event(event, data, data2);
107 void eSlider::setValue(int value)
110 event(evtChangedSlider);
113 void eSlider::setStartEnd(int start, int end)
117 event(evtChangedSlider);
120 void eSlider::setOrientation(int orientation, int swapped)
122 m_orientation = orientation;
123 m_orientation_swapped = swapped;
124 event(evtChangedSlider);
127 void eSlider::setRange(int min, int max)
131 event(evtChangedSlider);