[Scummvm-git-logs] scummvm master -> 19036610c977f2799b93764349e78d3a0cd02ddc
eriktorbjorn
noreply at scummvm.org
Sun Nov 19 14:19:30 UTC 2023
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:
19036610c9 SCUMM: Make MacDialogWindow responsible for handling double clicks
Commit: 19036610c977f2799b93764349e78d3a0cd02ddc
https://github.com/scummvm/scummvm/commit/19036610c977f2799b93764349e78d3a0cd02ddc
Author: Torbjörn Andersson (eriktorbjorn at users.sourceforge.net)
Date: 2023-11-19T15:15:38+01:00
Commit Message:
SCUMM: Make MacDialogWindow responsible for handling double clicks
Before, individual Mac widgets were responsible.
Changed paths:
engines/scumm/gfx_mac.cpp
engines/scumm/gfx_mac.h
diff --git a/engines/scumm/gfx_mac.cpp b/engines/scumm/gfx_mac.cpp
index 9c4e1a322cf..36ebb56b1cc 100644
--- a/engines/scumm/gfx_mac.cpp
+++ b/engines/scumm/gfx_mac.cpp
@@ -742,77 +742,69 @@ void MacGui::MacEditText::handleMouseDown(Common::Event &event) {
int oldSelectLen = _selectLen;
int oldCaretPos = _caretPos;
- uint32 now = _window->_system->getMillis();
- int x = event.mouse.x - _bounds.left;
-
_caretPos = getTextPosFromMouse(event.mouse.x, event.mouse.y);
_selectLen = 0;
- if (now - _lastClickTime < 500 && ABS(x - _lastClickX) < 5) {
- _selectLen = 0;
+ if (_selectLen != oldSelectLen || _caretPos != oldCaretPos)
+ setRedraw();
+}
- if (!_text.empty()) {
- int startPos = _caretPos;
- int endPos = _caretPos;
+void MacGui::MacEditText::handleDoubleClick(Common::Event &event) {
+ if (_text.empty())
+ return;
- // Check if used clicked past the end of the text
- if (_caretPos >= (int)_text.size())
- startPos = endPos = _text.size() - 1;
+ _selectLen = 0;
- if (_text[startPos] == ' ') {
- while (startPos >= 0) {
- if (_text[startPos] != ' ') {
- startPos++;
- break;
- }
- startPos--;
- }
+ int startPos = _caretPos;
+ int endPos = _caretPos;
- while (endPos < (int)_text.size()) {
- if (_text[endPos] != ' ') {
- endPos--;
- break;
- }
- endPos++;
- }
- } else {
- while (startPos >= 0) {
- if (_text[startPos] == ' ') {
- startPos++;
- break;
- }
- startPos--;
- }
+ // Check if used clicked past the end of the text
+ if (_caretPos >= (int)_text.size())
+ startPos = endPos = _text.size() - 1;
- while (endPos < (int)_text.size()) {
- if (_text[endPos] == ' ') {
- endPos--;
- break;
- }
- endPos++;
- }
+ if (_text[startPos] == ' ') {
+ while (startPos >= 0) {
+ if (_text[startPos] != ' ') {
+ startPos++;
+ break;
}
-
- if (startPos < 0)
- startPos = 0;
-
- if (endPos >= (int)_text.size())
- endPos = _text.size() - 1;
-
- _caretPos = startPos;
- _selectLen = endPos - startPos + 1;
+ startPos--;
}
- _lastClickTime = 0;
- _lastClickX = 0;
+ while (endPos < (int)_text.size()) {
+ if (_text[endPos] != ' ') {
+ endPos--;
+ break;
+ }
+ endPos++;
+ }
} else {
- _lastClickTime = now;
- _lastClickX = x;
- _selectLen = 0;
+ while (startPos >= 0) {
+ if (_text[startPos] == ' ') {
+ startPos++;
+ break;
+ }
+ startPos--;
+ }
+
+ while (endPos < (int)_text.size()) {
+ if (_text[endPos] == ' ') {
+ endPos--;
+ break;
+ }
+ endPos++;
+ }
}
- if (_selectLen != oldSelectLen || _caretPos != oldCaretPos)
- setRedraw();
+ if (startPos < 0)
+ startPos = 0;
+
+ if (endPos >= (int)_text.size())
+ endPos = _text.size() - 1;
+
+ _caretPos = startPos;
+ _selectLen = endPos - startPos + 1;
+ setRedraw();
}
bool MacGui::MacEditText::handleKeyDown(Common::Event &event) {
@@ -2006,8 +1998,19 @@ int MacGui::MacDialogWindow::runDialog(Common::Array<int> &deferredActionIds) {
buttonPressed = true;
nextMouseRepeat = _system->getMillis() + 40;
setFocusedWidget(event.mouse.x, event.mouse.y);
- if (_focusedWidget)
+ if (_focusedWidget) {
_focusedWidget->handleMouseDown(event);
+
+ uint32 now = _system->getMillis();
+
+ if (now - _lastClickTime < 500 && ABS(event.mouse.x - _lastClickPos.x) < 5 && ABS(event.mouse.y - _lastClickPos.y) < 5) {
+ _focusedWidget->handleDoubleClick(event);
+ }
+
+ _lastClickTime = _system->getMillis();
+ _lastClickPos.x = event.mouse.x;
+ _lastClickPos.y = event.mouse.y;
+ }
break;
case Common::EVENT_LBUTTONUP:
diff --git a/engines/scumm/gfx_mac.h b/engines/scumm/gfx_mac.h
index eab9a5d9394..0c5e07da6ef 100644
--- a/engines/scumm/gfx_mac.h
+++ b/engines/scumm/gfx_mac.h
@@ -199,6 +199,7 @@ public:
virtual void handleMouseHeld() {}
virtual void handleWheelUp() {}
virtual void handleWheelDown() {}
+ virtual void handleDoubleClick(Common::Event &event) {}
virtual bool handleKeyDown(Common::Event &event) { return false; }
};
@@ -275,10 +276,6 @@ public:
int _caretPos = 0;
int _caretX = -1;
- uint32 _lastClickTime = 0;
-
- int _lastClickX = 0;
-
uint32 _nextCaretBlink = 0;
bool _caretVisible = true;
@@ -305,9 +302,10 @@ public:
void draw(bool drawFocused = false) override;
void handleMouseDown(Common::Event &event) override;
+ void handleDoubleClick(Common::Event &event) override;
bool handleKeyDown(Common::Event &event) override;
- void handleMouseMove(Common::Event &event) override;
void handleMouseHeld() override;
+ void handleMouseMove(Common::Event &event) override;
};
class MacPicture : public MacWidget {
@@ -464,6 +462,9 @@ public:
bool _visible = false;
+ uint32 _lastClickTime = 0;
+ Common::Point _lastClickPos;
+
Graphics::Surface *_beamCursor = nullptr;
Common::Point _beamCursorPos;
bool _cursorWasVisible = false;
More information about the Scummvm-git-logs
mailing list