Renamed _clickedWidget -> _dragWidget; if a drag is in process, send the mouse moved / mouse up events to the widget on which the drag is performed (this fixes at least one bug and improves the user experience)

svn-id: r16362
This commit is contained in:
Max Horn 2004-12-28 21:07:34 +00:00
parent 8e42cbde2a
commit a40ed29abd
3 changed files with 14 additions and 17 deletions

View file

@ -38,7 +38,7 @@ namespace GUI {
Dialog::Dialog(int x, int y, int w, int h)
: GuiObject(x, y, w, h),
_mouseWidget(0), _focusedWidget(0), _clickedWidget(0), _visible(false) {
_mouseWidget(0), _focusedWidget(0), _dragWidget(0), _visible(false) {
}
Dialog::~Dialog() {
@ -120,7 +120,7 @@ void Dialog::handleMouseDown(int x, int y, int button, int clickCount) {
Widget *w;
w = findWidget(x, y);
_clickedWidget = w;
_dragWidget = w;
// If the click occured inside a widget which is not the currently
// focused one, change the focus to that widget.
@ -143,8 +143,6 @@ void Dialog::handleMouseDown(int x, int y, int button, int clickCount) {
void Dialog::handleMouseUp(int x, int y, int button, int clickCount) {
Widget *w;
w = findWidget(x, y);
if (_focusedWidget) {
//w = _focusedWidget;
@ -154,10 +152,12 @@ void Dialog::handleMouseUp(int x, int y, int button, int clickCount) {
}
}
if (w && w == _clickedWidget)
w = _dragWidget;
if (w)
w->handleMouseUp(x - (w->getAbsX() - _x), y - (w->getAbsY() - _y), button, clickCount);
_clickedWidget = 0;
_dragWidget = 0;
}
void Dialog::handleMouseWheel(int x, int y, int direction) {
@ -215,9 +215,9 @@ void Dialog::handleMouseMoved(int x, int y, int button) {
Widget *w;
//if (!button)
// _clickedWidget = 0;
// _dragWidget = 0;
if (_focusedWidget && !_clickedWidget) {
if (_focusedWidget && !_dragWidget) {
w = _focusedWidget;
int wx = w->getAbsX() - _x;
int wy = w->getAbsY() - _y;
@ -238,13 +238,12 @@ void Dialog::handleMouseMoved(int x, int y, int button) {
w->handleMouseMoved(x - wx, y - wy, button);
}
w = findWidget(x, y);
// While a "drag" is in process (i.e. mouse is moved while a button is pressed),
// only deal with the widget in which the click originated.
if (_clickedWidget && w != _clickedWidget) {
w = 0;
}
if (_dragWidget)
w = _dragWidget;
else
w = findWidget(x, y);
if (_mouseWidget != w) {
if (_mouseWidget)

View file

@ -41,7 +41,7 @@ class Dialog : public GuiObject {
protected:
Widget *_mouseWidget;
Widget *_focusedWidget;
Widget *_clickedWidget;
Widget *_dragWidget;
bool _visible;
private:

View file

@ -208,8 +208,6 @@ SliderWidget::SliderWidget(GuiObject *boss, int x, int y, int w, int h, const St
}
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 && x >= (int)_labelWidth) {
int newValue = posToValue(x - _labelWidth);
if (newValue < _valueMin)