#include <lib/gui/eslider.h>
-eSlider::eSlider(eWidget *parent): eWidget(parent)
+eSlider::eSlider(eWidget *parent): eWidget(parent), m_orientation(orHorizontal), m_start(0)
{
}
ePtr<eWindowStyle> style;
gPainter &painter = *(gPainter*)data2;
-
getStyle(style);
style->paintBackground(painter, ePoint(0, 0), size());
style->setStyle(painter, eWindowStyle::styleLabel); // TODO - own style
}
case evtChangedSlider:
{
-
- int num_pix = 0;
- if (m_min < m_max)
- num_pix = size().width() * m_value / (m_max - m_min);
+ int num_pix = 0, start_pix = 0;
gRegion old_currently_filled = m_currently_filled;
- m_currently_filled = eRect(0, 0, num_pix, size().height());
+
+ int pixsize = (m_orientation == orHorizontal) ? size().width() : size().height();
+
+ if (m_min < m_max)
+ {
+ num_pix = pixsize * (m_value - m_start) / (m_max - m_min);
+ start_pix = pixsize * m_start / (m_max - m_min);
+ }
+
+ if (start_pix < 0)
+ {
+ num_pix += start_pix;
+ start_pix = 0;
+ }
+
+ if (num_pix < 0)
+ num_pix = 0;
+
+ if (m_orientation == orHorizontal)
+ m_currently_filled = eRect(start_pix, 0, num_pix, size().height());
+ else
+ m_currently_filled = eRect(0, start_pix, size().width(), num_pix);
// redraw what *was* filled before and now isn't.
invalidate(m_currently_filled - old_currently_filled);
event(evtChangedSlider);
}
+void eSlider::setStartEnd(int start, int end)
+{
+ m_value = end;
+ m_start = start;
+ event(evtChangedSlider);
+}
+
+void eSlider::setOrientation(int orientation)
+{
+ m_orientation = orientation;
+ event(evtChangedSlider);
+}
+
void eSlider::setRange(int min, int max)
{
m_min = min;
public:
eSlider(eWidget *parent);
void setValue(int val);
+ void setStartEnd(int start, int end);
void setRange(int min, int max);
+ enum { orHorizontal, orVertical };
+ void setOrientation(int orientation);
protected:
int event(int event, void *data=0, void *data2=0);
private:
{
evtChangedSlider = evtUserWidget
};
- int m_min, m_max, m_value;
+ int m_min, m_max, m_value, m_start, m_orientation;
gRegion m_currently_filled;
};