[Scummvm-git-logs] scummvm master -> fbc9242afc5b133e972317694188f08e58c4cdeb
bluegr
noreply at scummvm.org
Tue Dec 24 11:19:40 UTC 2024
This automated email contains information about 3 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
dc2f3d7c47 JANITORIAL: Move function declarations
6e286e4628 GUI: Prevent select and scroll beyond bounds in console
fbc9242afc GUI: Improve selection behaviour outside console area
Commit: dc2f3d7c47f4ed95c8b088aab890334864105f03
https://github.com/scummvm/scummvm/commit/dc2f3d7c47f4ed95c8b088aab890334864105f03
Author: tunnelsociety (150493071+tunnelsociety at users.noreply.github.com)
Date: 2024-12-24T13:19:37+02:00
Commit Message:
JANITORIAL: Move function declarations
Changed paths:
gui/console.h
diff --git a/gui/console.h b/gui/console.h
index 6b1a38ad541..dd3fcb27875 100644
--- a/gui/console.h
+++ b/gui/console.h
@@ -119,9 +119,6 @@ protected:
int _historyIndex;
int _historyLine;
- void loadHistory();
- void saveHistory();
-
float _widthPercent, _heightPercent;
int _leftPadding;
@@ -208,6 +205,8 @@ protected:
void killLastWord();
// History
+ void loadHistory();
+ void saveHistory();
void addToHistory(const Common::String &str);
void historyScroll(int direction);
};
Commit: 6e286e4628a7317bd79d5cdfe0bd57178c62a58e
https://github.com/scummvm/scummvm/commit/6e286e4628a7317bd79d5cdfe0bd57178c62a58e
Author: tunnelsociety (150493071+tunnelsociety at users.noreply.github.com)
Date: 2024-12-24T13:19:37+02:00
Commit Message:
GUI: Prevent select and scroll beyond bounds in console
Select only within existing text; a buffer overread was possible.
Changed paths:
gui/console.cpp
gui/console.h
diff --git a/gui/console.cpp b/gui/console.cpp
index fa8b592c371..84f9a269ac4 100644
--- a/gui/console.cpp
+++ b/gui/console.cpp
@@ -28,6 +28,7 @@
#include "base/version.h"
#include "common/system.h"
+#include "common/util.h"
#include "graphics/fontman.h"
@@ -254,8 +255,12 @@ void ConsoleDialog::handleTickle() {
if (_selectionTime < time) {
_selectionTime += kDraggingTime;
if (_isDragging && _scrollDirection != 0) {
- _scrollBar->handleMouseWheel(0, 0, -_scrollDirection);
+ handleMouseWheel(0, 0, -_scrollDirection);
_selEnd -= kCharsPerLine * _scrollDirection;
+ if (clampSelection(_selEnd))
+ // Scrolled as far as possible. Don't re-execute this block
+ // unnecessarily.
+ _scrollDirection = 0;
}
}
// Perform the "slide animation".
@@ -911,6 +916,7 @@ void ConsoleDialog::handleMouseDown(int x, int y, int button, int clickCount) {
int lineNumber = (y - _topPadding) / kConsoleLineHeight;
int ind = (x - _leftPadding) / kConsoleCharWidth;
_selBegin = (_scrollLine - _linesPerPage + 1 + lineNumber) * kCharsPerLine + ind;
+ clampSelection(_selBegin);
_selEnd = _selBegin;
_isDragging = true;
} else {
@@ -920,6 +926,19 @@ void ConsoleDialog::handleMouseDown(int x, int y, int button, int clickCount) {
}
}
+bool ConsoleDialog::clampSelection(int &sel) {
+ int oldSel = sel;
+ int lowerBound = 0;
+ int upperBound;
+
+ upperBound = MAX(_promptEndPos, _currentPos);
+ upperBound = MAX(upperBound, _linesPerPage * kCharsPerLine); // at least the whole first page
+ upperBound += kCharsPerLine - (upperBound % kCharsPerLine); // to end of line
+
+ sel = MAX(lowerBound, MIN(upperBound, sel));
+ return sel != oldSel;
+}
+
void ConsoleDialog::handleMouseMoved(int x, int y, int button) {
if (!_isDragging)
Dialog::handleMouseMoved(x, y, button);
@@ -929,6 +948,7 @@ void ConsoleDialog::handleMouseMoved(int x, int y, int button) {
lineNumber = MIN(lineNumber, _linesPerPage - 1);
int col = (x - _leftPadding) / kConsoleCharWidth;
_selEnd = (_scrollLine - _linesPerPage + 1 + lineNumber) * kCharsPerLine + col;
+ clampSelection(_selEnd);
if (_selEnd == selEndPreviousMove)
return;
diff --git a/gui/console.h b/gui/console.h
index dd3fcb27875..5967d67456d 100644
--- a/gui/console.h
+++ b/gui/console.h
@@ -209,6 +209,11 @@ protected:
void saveHistory();
void addToHistory(const Common::String &str);
void historyScroll(int direction);
+
+ /**
+ * Returns whether sel was modified
+ */
+ bool clampSelection(int &sel);
};
} // End of namespace GUI
Commit: fbc9242afc5b133e972317694188f08e58c4cdeb
https://github.com/scummvm/scummvm/commit/fbc9242afc5b133e972317694188f08e58c4cdeb
Author: tunnelsociety (150493071+tunnelsociety at users.noreply.github.com)
Date: 2024-12-24T13:19:37+02:00
Commit Message:
GUI: Improve selection behaviour outside console area
Selecting outside the console text area would result in a strange
selection startpoint and/or endpoint. Now the selection feels more
natural.
Changed paths:
gui/console.cpp
diff --git a/gui/console.cpp b/gui/console.cpp
index 84f9a269ac4..d653e056fca 100644
--- a/gui/console.cpp
+++ b/gui/console.cpp
@@ -910,8 +910,8 @@ void ConsoleDialog::handleMouseDown(int x, int y, int button, int clickCount) {
w->handleMouseDown(x - (w->getAbsX() - _x), y - (w->getAbsY() - _y), button, clickCount);
} else if (_selBegin == -1 || _selEnd == -1) {
- if (y > _h)
- return;
+ x = MIN(MAX(x, _leftPadding), kCharsPerLine * kConsoleCharWidth + _leftPadding);
+ y = MIN(MAX(y, _topPadding), (decltype(y))_h - kConsoleLineHeight);
int lineNumber = (y - _topPadding) / kConsoleLineHeight;
int ind = (x - _leftPadding) / kConsoleCharWidth;
@@ -944,6 +944,8 @@ void ConsoleDialog::handleMouseMoved(int x, int y, int button) {
Dialog::handleMouseMoved(x, y, button);
else {
int selEndPreviousMove = _selEnd;
+ x = MIN(MAX(x, _leftPadding), kCharsPerLine * kConsoleCharWidth + _leftPadding);
+ y = MIN(MAX(y, _topPadding), (decltype(y))_h - kConsoleLineHeight);
int lineNumber = (y - _topPadding) / kConsoleLineHeight;
lineNumber = MIN(lineNumber, _linesPerPage - 1);
int col = (x - _leftPadding) / kConsoleCharWidth;
More information about the Scummvm-git-logs
mailing list