added built-in label for SliderWidget
svn-id: r11075
This commit is contained in:
parent
be560b6ec6
commit
cfd658cd29
4 changed files with 27 additions and 27 deletions
|
@ -190,19 +190,20 @@ void CheckboxWidget::drawWidget(bool hilite) {
|
|||
|
||||
// If checked, draw cross inside the box
|
||||
if (_state)
|
||||
gui->drawBitmap(checked_img, _x + 3, _y + 3, !isEnabled() ? gui->_color : gui->_textcolor);
|
||||
gui->drawBitmap(checked_img, _x + 3, _y + 3, isEnabled() ? gui->_textcolor : gui->_color);
|
||||
else
|
||||
gui->fillRect(_x + 2, _y + 2, 10, 10, gui->_bgcolor);
|
||||
|
||||
// Finally draw the label
|
||||
gui->drawString(_label, _x + 20, _y + 3, _w, !isEnabled() ? gui->_color : gui->_textcolor);
|
||||
gui->drawString(_label, _x + 20, _y + 3, _w, isEnabled() ? gui->_textcolor : gui->_color);
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
SliderWidget::SliderWidget(GuiObject *boss, int x, int y, int w, int h, uint32 cmd, uint8 hotkey)
|
||||
: ButtonWidget(boss, x, y, w, h, "", cmd, hotkey),
|
||||
_value(0), _oldValue(0),_valueMin(0), _valueMax(100), _isDragging(false) {
|
||||
SliderWidget::SliderWidget(GuiObject *boss, int x, int y, int w, int h, const String &label, int labelWidth, uint32 cmd, uint8 hotkey)
|
||||
: ButtonWidget(boss, x, y, w, h, label, cmd, hotkey),
|
||||
_value(0), _oldValue(0),_valueMin(0), _valueMax(100), _isDragging(false),
|
||||
_labelWidth(labelWidth) {
|
||||
_flags = WIDGET_ENABLED | WIDGET_TRACK_MOUSE | WIDGET_CLEARBG;
|
||||
_type = kSliderWidget;
|
||||
}
|
||||
|
@ -210,8 +211,8 @@ SliderWidget::SliderWidget(GuiObject *boss, int x, int y, int w, int h, uint32 c
|
|||
void SliderWidget::handleMouseMoved(int x, int y, int button) {
|
||||
// TODO: when the mouse is dragged outside the widget, the slider should
|
||||
// snap back to the old value.
|
||||
if (isEnabled() && _isDragging) {
|
||||
int newValue = posToValue(x);
|
||||
if (isEnabled() && _isDragging && x >= _labelWidth) {
|
||||
int newValue = posToValue(x - _labelWidth);
|
||||
if (newValue < _valueMin)
|
||||
newValue = _valueMin;
|
||||
else if (newValue > _valueMax)
|
||||
|
@ -242,17 +243,21 @@ void SliderWidget::handleMouseUp(int x, int y, int button, int clickCount) {
|
|||
void SliderWidget::drawWidget(bool hilite) {
|
||||
NewGui *gui = &g_gui;
|
||||
|
||||
// Draw the label, if any
|
||||
if (_labelWidth > 0)
|
||||
gui->drawString(_label, _x, _y + 2, _labelWidth, isEnabled() ? gui->_textcolor : gui->_color, kTextAlignRight);
|
||||
|
||||
// Draw the box
|
||||
gui->box(_x, _y, _w, _h, gui->_color, gui->_shadowcolor);
|
||||
gui->box(_x + _labelWidth, _y, _w - _labelWidth, _h, gui->_color, gui->_shadowcolor);
|
||||
|
||||
// Draw the 'bar'
|
||||
gui->fillRect(_x + 2, _y + 2, valueToPos(_value), _h - 4, hilite ? gui->_textcolorhi : gui->_textcolor);
|
||||
gui->fillRect(_x + _labelWidth + 2, _y + 2, valueToPos(_value), _h - 4, hilite ? gui->_textcolorhi : gui->_textcolor);
|
||||
}
|
||||
|
||||
int SliderWidget::valueToPos(int value) {
|
||||
return ((_w - 4) * (value - _valueMin) / (_valueMax - _valueMin));
|
||||
return ((_w - _labelWidth - 4) * (value - _valueMin) / (_valueMax - _valueMin));
|
||||
}
|
||||
|
||||
int SliderWidget::posToValue(int pos) {
|
||||
return (pos) * (_valueMax - _valueMin) / (_w - 4) + _valueMin;
|
||||
return (pos) * (_valueMax - _valueMin) / (_w - _labelWidth - 4) + _valueMin;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue