GUI: Implement finger scrolling in RichTextWidget

This commit is contained in:
Eugene Sandulenko 2023-11-02 22:52:55 +01:00
parent 7ff167190b
commit 2db0c24ce6
No known key found for this signature in database
GPG Key ID: 014D387312D34F08
2 changed files with 37 additions and 1 deletions

View File

@ -85,13 +85,45 @@ void RichTextWidget::handleMouseWheel(int x, int y, int direction) {
_verticalScroll->handleMouseWheel(x, y, direction);
}
void RichTextWidget::handleMouseDown(int x, int y, int button, int clickCount) {
_mouseDownY = _mouseDownStartY = y;
}
void RichTextWidget::handleMouseUp(int x, int y, int button, int clickCount) {
// Allow some tiny finger slipping
if (ABS(_mouseDownY - _mouseDownStartY) > 5) {
_mouseDownY = _mouseDownStartY = 0;
return;
}
_mouseDownY = _mouseDownStartY = 0;
Common::String link = _txtWnd->getMouseLink(x + _x + _scrolledX, y + _y + _scrolledY).encode();
if (link.hasPrefixIgnoreCase("http"))
g_system->openUrl(link);
}
void RichTextWidget::handleMouseMoved(int x, int y, int button) {
if (_mouseDownStartY == 0 || _mouseDownY == y)
return;
int h = _txtWnd->getTextHeight();
int prevScrolledY = _scrolledY;
_scrolledY = CLIP(_scrolledY - (y - _mouseDownY), 0, h);
_mouseDownY = y;
if (_scrolledY == prevScrolledY)
return;
recalc();
_verticalScroll->recalc();
markAsDirty();
}
void RichTextWidget::handleTooltipUpdate(int x, int y) {
_tooltip = _txtWnd->getMouseLink(x + _x + _scrolledX, y + _y + _scrolledY);
}
@ -117,7 +149,7 @@ void RichTextWidget::recalc() {
int h = _txtWnd->getTextHeight();
if (h <= _limitH) _scrolledY = 0;
if (_scrolledY > h - _limitH) _scrolledY = 0;
if (_scrolledY > h - _limitH) _scrolledY = MAX(0, h - _limitH);
_verticalScroll->_numEntries = h;
_verticalScroll->_currentPos = _scrolledY;

View File

@ -43,6 +43,8 @@ protected:
ScrollBarWidget *_verticalScroll;
int16 _scrolledX, _scrolledY;
int _mouseDownY = 0;
int _mouseDownStartY = 0;
int _scrollbarWidth;
uint16 _limitH;
int _textWidth;
@ -61,7 +63,9 @@ public:
void handleCommand(CommandSender *sender, uint32 cmd, uint32 data) override;
void handleMouseWheel(int x, int y, int direction) override;
void handleMouseDown(int x, int y, int button, int clickCount) override;
void handleMouseUp(int x, int y, int button, int clickCount) override;
void handleMouseMoved(int x, int y, int button) override;
void handleTooltipUpdate(int x, int y) override;
void markAsDirty() override;