[Scummvm-cvs-logs] scummvm master -> 031e062252d00fc7e6d930287b6dbd4a845d2a2f
salty-horse
ori at avtalion.name
Sun Mar 27 22:30:09 CEST 2016
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
031e062252 GUI: Improve handling of button presses while moving the cursor
Commit: 031e062252d00fc7e6d930287b6dbd4a845d2a2f
https://github.com/scummvm/scummvm/commit/031e062252d00fc7e6d930287b6dbd4a845d2a2f
Author: Ori Avtalion (ori at avtalion.name)
Date: 2016-03-27T23:29:37+03:00
Commit Message:
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.
Changed paths:
gui/widget.cpp
gui/widget.h
diff --git a/gui/widget.cpp b/gui/widget.cpp
index 851774f..e4afea0 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 9891f32..7c1437d 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;
};
More information about the Scummvm-git-logs
mailing list