Ticket #8387: slider.patch
File slider.patch, 4.1 KB (added by , 20 years ago) |
---|
-
gui/widget.cpp
RCS file: /cvsroot/scummvm/scummvm/gui/widget.cpp,v retrieving revision 1.38 diff -u -r1.38 gui/widget.cpp
18 18 * $Header: /cvsroot/scummvm/scummvm/gui/widget.cpp,v 1.38 2004/03/13 13:03:25 fingolfin Exp $ 19 19 */ 20 20 21 #include <math.h> 22 21 23 #include "stdafx.h" 22 24 #include "common/util.h" 23 25 #include "gui/widget.h" … … 208 210 } 209 211 210 212 void SliderWidget::handleMouseMoved(int x, int y, int button) { 211 // TODO: when the mouse is dragged outside the widget, the slider should212 // snap back to the old value.213 213 if (isEnabled() && _isDragging && x >= (int)_labelWidth) { 214 214 int newValue = posToValue(x - _labelWidth); 215 215 if (newValue < _valueMin) … … 228 228 void SliderWidget::handleMouseDown(int x, int y, int button, int clickCount) { 229 229 if (isEnabled()) { 230 230 _isDragging = true; 231 _valueDragStart = _value; 231 232 handleMouseMoved(x, y, button); 232 233 } 233 234 } 234 235 235 236 void SliderWidget::handleMouseUp(int x, int y, int button, int clickCount) { 237 if (isEnabled() && _isDragging) 238 sendCommand(_cmd, _value); 239 240 _isDragging = false; 241 } 242 243 void SliderWidget::handleMouseLeft(int button) { 244 ButtonWidget::handleMouseLeft(button); 236 245 if (isEnabled() && _isDragging) { 246 _value = _valueDragStart; 247 draw(); 237 248 sendCommand(_cmd, _value); 238 249 } 239 250 _isDragging = false; … … 249 260 // Draw the box 250 261 gui->box(_x + _labelWidth, _y, _w - _labelWidth, _h, gui->_color, gui->_shadowcolor); 251 262 252 // Draw the 'bar' 253 gui->fillRect(_x + _labelWidth + 2, _y + 2, valueToPos(_value), _h - 4, 254 !isEnabled() ? gui->_color : 255 hilite ? gui->_textcolorhi : gui->_textcolor); 263 OverlayColor color = !isEnabled() ? gui->_color : hilite ? gui->_textcolorhi : gui->_textcolor; 264 265 // Draw handle 266 int handlePos = valueToPos(_value); 267 gui->vLine(_x + handlePos + _labelWidth + 2, _y + 4, _y + _h - 6, color); 268 gui->vLine(_x + handlePos + _labelWidth + 1, _y + 3, _y + _h - 5, color); 269 gui->vLine(_x + handlePos + _labelWidth - 1, _y + 3, _y + _h - 5, color); 270 gui->vLine(_x + handlePos + _labelWidth - 2, _y + 4, _y + _h - 6, color); 271 272 // Draw Tracks 273 if (handlePos > 5) { 274 gui->hLine(_x + _labelWidth + 3, _y + _h / 2 - 2, _x + _labelWidth + handlePos - 4, color); 275 gui->hLine(_x + _labelWidth + 3, _y + _h / 2, _x + _labelWidth + handlePos - 4, color); 276 } 277 278 if ((uint)handlePos < _w - _labelWidth - 11) { 279 gui->hLine(_x + _labelWidth + handlePos + 4, _y + _h / 2 - 2, _x + _w - 4, color); 280 gui->hLine(_x + _labelWidth + handlePos + 4, _y + _h / 2, _x + _w - 4, color); 281 } 256 282 } 257 283 258 284 int SliderWidget::valueToPos(int value) { 259 return ((_w - _labelWidth - 4) * (value - _valueMin) / (_valueMax - _valueMin));285 return ((_w - _labelWidth - 11) * (value - _valueMin) / (_valueMax - _valueMin) + 5); 260 286 } 261 287 262 288 int SliderWidget::posToValue(int pos) { 263 return (pos) * (_valueMax - _valueMin) / (_w - _labelWidth - 4) + _valueMin; 289 // Align pos to middle of handle 290 if (pos < 5) 291 pos = 5; 292 else if ((uint)pos > _w - _labelWidth - 5) 293 pos = _w - _labelWidth - 5; 294 295 return int(((float)((pos - 5) * (_valueMax - _valueMin)) / (_w - _labelWidth - 11) + _valueMin) + 0.5); 264 296 } 265 297 266 298 } // End of namespace GUI -
gui/widget.h
RCS file: /cvsroot/scummvm/scummvm/gui/widget.h,v retrieving revision 1.36 diff -u -r1.36 gui/widget.h
185 185 /* SliderWidget */ 186 186 class SliderWidget : public ButtonWidget { 187 187 protected: 188 int _value, _oldValue ;188 int _value, _oldValue, _valueDragStart; 189 189 int _valueMin, _valueMax; 190 190 bool _isDragging; 191 191 uint _labelWidth; … … 200 200 int getMaxValue() const { return _valueMax; } 201 201 202 202 void handleMouseMoved(int x, int y, int button); 203 void handleMouseLeft(int button); 203 204 void handleMouseDown(int x, int y, int button, int clickCount); 204 205 void handleMouseUp(int x, int y, int button, int clickCount);