From a40ed29abd3c164743f2b56c2f73aa4a956b34a8 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Tue, 28 Dec 2004 21:07:34 +0000 Subject: 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 --- gui/dialog.cpp | 25 ++++++++++++------------- gui/dialog.h | 2 +- gui/widget.cpp | 4 +--- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/gui/dialog.cpp b/gui/dialog.cpp index 95a8b804f5..99c25b70c7 100644 --- a/gui/dialog.cpp +++ b/gui/dialog.cpp @@ -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; @@ -237,14 +237,13 @@ 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) diff --git a/gui/dialog.h b/gui/dialog.h index d535cd9280..1e0339fad3 100644 --- a/gui/dialog.h +++ b/gui/dialog.h @@ -41,7 +41,7 @@ class Dialog : public GuiObject { protected: Widget *_mouseWidget; Widget *_focusedWidget; - Widget *_clickedWidget; + Widget *_dragWidget; bool _visible; private: diff --git a/gui/widget.cpp b/gui/widget.cpp index 8fff12dff9..08a88c767a 100644 --- a/gui/widget.cpp +++ b/gui/widget.cpp @@ -201,15 +201,13 @@ void CheckboxWidget::drawWidget(bool hilite) { SliderWidget::SliderWidget(GuiObject *boss, int x, int y, int w, int h, const String &label, uint labelWidth, uint32 cmd, uint8 hotkey) : ButtonWidget(boss, x, y, w, h, label, cmd, hotkey), - _value(0), _oldValue(0),_valueMin(0), _valueMax(100), _isDragging(false), + _value(0), _oldValue(0), _valueMin(0), _valueMax(100), _isDragging(false), _labelWidth(labelWidth) { _flags = WIDGET_ENABLED | WIDGET_TRACK_MOUSE | WIDGET_CLEARBG; _type = kSliderWidget; } 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) -- cgit v1.2.3