aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Avtalion2016-03-23 21:24:43 +0200
committerOri Avtalion2016-03-27 23:29:37 +0300
commit031e062252d00fc7e6d930287b6dbd4a845d2a2f (patch)
tree2ba4d9ab80f92e917b761b771c6b138100d07ebc
parentc5b8adb370d9d707aee4b00cf1c711dcd7419d17 (diff)
downloadscummvm-rg350-031e062252d00fc7e6d930287b6dbd4a845d2a2f.tar.gz
scummvm-rg350-031e062252d00fc7e6d930287b6dbd4a845d2a2f.tar.bz2
scummvm-rg350-031e062252d00fc7e6d930287b6dbd4a845d2a2f.zip
GUI: Improve handling of button presses while moving the cursor
Keep track of where a mouse press started when deciding how mouse-over and mouse-up should behave. This handles the following situations: 1) If a mouse press starts outside a button (e.g. the UI background), mouse-up inside the button has no effect. Previously, it triggered a button click. 2) If a mouse press starts inside a button, the cursor moves outside of its region, then back inside, the button will show as pressed. Previously, it showed as highlighted instead of pressed.
-rw-r--r--gui/widget.cpp14
-rw-r--r--gui/widget.h3
2 files changed, 11 insertions, 6 deletions
diff --git a/gui/widget.cpp b/gui/widget.cpp
index 851774fd70..e4afea0c36 100644
--- a/gui/widget.cpp
+++ b/gui/widget.cpp
@@ -277,7 +277,7 @@ void StaticTextWidget::drawWidget() {
ButtonWidget::ButtonWidget(GuiObject *boss, int x, int y, int w, int h, const Common::String &label, const char *tooltip, uint32 cmd, uint8 hotkey)
: StaticTextWidget(boss, x, y, w, h, cleanupHotkey(label), Graphics::kTextAlignCenter, tooltip), CommandSender(boss),
- _cmd(cmd), _hotkey(hotkey), _lastTime(0) {
+ _cmd(cmd), _hotkey(hotkey), _lastTime(0), _duringPress(false) {
if (hotkey == 0)
_hotkey = parseHotkey(label);
@@ -288,7 +288,7 @@ ButtonWidget::ButtonWidget(GuiObject *boss, int x, int y, int w, int h, const Co
ButtonWidget::ButtonWidget(GuiObject *boss, const Common::String &name, const Common::String &label, const char *tooltip, uint32 cmd, uint8 hotkey)
: StaticTextWidget(boss, name, cleanupHotkey(label), tooltip), CommandSender(boss),
- _cmd(cmd), _hotkey(hotkey), _lastTime(0) {
+ _cmd(cmd), _hotkey(hotkey), _lastTime(0), _duringPress(false) {
if (hotkey == 0)
_hotkey = parseHotkey(label);
setFlags(WIDGET_ENABLED/* | WIDGET_BORDER*/ | WIDGET_CLEARBG);
@@ -296,13 +296,15 @@ ButtonWidget::ButtonWidget(GuiObject *boss, const Common::String &name, const Co
}
void ButtonWidget::handleMouseUp(int x, int y, int button, int clickCount) {
- if (isEnabled() && x >= 0 && x < _w && y >= 0 && y < _h) {
+ if (isEnabled() && _duringPress && x >= 0 && x < _w && y >= 0 && y < _h) {
startAnimatePressedState();
sendCommand(_cmd, 0);
}
+ _duringPress = false;
}
void ButtonWidget::handleMouseDown(int x, int y, int button, int clickCount) {
+ _duringPress = true;
setPressedState();
}
@@ -460,9 +462,10 @@ CheckboxWidget::CheckboxWidget(GuiObject *boss, const Common::String &name, cons
}
void CheckboxWidget::handleMouseUp(int x, int y, int button, int clickCount) {
- if (isEnabled() && x >= 0 && x < _w && y >= 0 && y < _h) {
+ if (isEnabled() && _duringPress && x >= 0 && x < _w && y >= 0 && y < _h) {
toggleState();
}
+ _duringPress = false;
}
void CheckboxWidget::setState(bool state) {
@@ -523,9 +526,10 @@ RadiobuttonWidget::RadiobuttonWidget(GuiObject *boss, const Common::String &name
}
void RadiobuttonWidget::handleMouseUp(int x, int y, int button, int clickCount) {
- if (isEnabled() && x >= 0 && x < _w && y >= 0 && y < _h) {
+ if (isEnabled() && _duringPress && x >= 0 && x < _w && y >= 0 && y < _h) {
toggleState();
}
+ _duringPress = false;
}
void RadiobuttonWidget::setState(bool state, bool setGroup) {
diff --git a/gui/widget.h b/gui/widget.h
index 9891f32b36..7c1437de0a 100644
--- a/gui/widget.h
+++ b/gui/widget.h
@@ -198,7 +198,7 @@ public:
void handleMouseUp(int x, int y, int button, int clickCount);
void handleMouseDown(int x, int y, int button, int clickCount);
- void handleMouseEntered(int button) { setFlags(WIDGET_HILITED); draw(); }
+ void handleMouseEntered(int button) { if (_duringPress) { setFlags(WIDGET_PRESSED); } else { setFlags(WIDGET_HILITED); } draw(); }
void handleMouseLeft(int button) { clearFlags(WIDGET_HILITED | WIDGET_PRESSED); draw(); }
void handleTickle();
@@ -211,6 +211,7 @@ public:
protected:
void drawWidget();
void wantTickle(bool tickled);
+ bool _duringPress;
private:
uint32 _lastTime;
};