Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #46 from thp/better-scrolling
[util] Improve scrolling on high-DPI screens (Fixes JB#29417)
  • Loading branch information
thp committed Jun 2, 2015
2 parents 5c74711 + 2b2385a commit a41c6f3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
23 changes: 15 additions & 8 deletions util.cpp
Expand Up @@ -275,8 +275,7 @@ void Util::mouseMove(float eventX, float eventY) {
return;

if(settingsValue("ui/dragMode")=="scroll") {
scrollBackBuffer(eventPos, dragOrigin);
dragOrigin = eventPos;
dragOrigin = scrollBackBuffer(eventPos, dragOrigin);
}
else if(settingsValue("ui/dragMode")=="select" && iRenderer) {
selectionHelper(eventPos);
Expand Down Expand Up @@ -326,18 +325,26 @@ void Util::selectionHelper(QPointF scenePos)
}
}

void Util::scrollBackBuffer(QPointF now, QPointF last)
QPointF Util::scrollBackBuffer(QPointF now, QPointF last)
{
if(!iTerm)
return;
return last;

int xdist = qAbs(now.x() - last.x());
int ydist = qAbs(now.y() - last.y());
int fontSize = settingsValue("ui/fontSize").toInt();

int lines = ydist / fontSize;

if(lines > 0 && now.y() < last.y() && xdist < ydist*2) {
iTerm->scrollBackBufferFwd(lines);
last = QPointF(now.x(), last.y() - lines * fontSize);
} else if(lines > 0 && now.y() > last.y() && xdist < ydist*2) {
iTerm->scrollBackBufferBack(lines);
last = QPointF(now.x(), last.y() + lines * fontSize);
}

if(now.y() < last.y() && xdist < ydist*2)
iTerm->scrollBackBufferFwd(1);
else if(now.y() > last.y() && xdist < ydist*2)
iTerm->scrollBackBufferBack(1);
return last;
}

void Util::doGesture(Util::PanGesture gesture)
Expand Down
9 changes: 8 additions & 1 deletion util.h
Expand Up @@ -91,7 +91,14 @@ public slots:
bool swipeModeSet;
bool swipeAllowed;

void scrollBackBuffer(QPointF now, QPointF last);
/**
* Scroll the back buffer on drag.
*
* @param now The current position
* @param last The last position (or start position)
* @return The new value for last (modified by any consumed offset)
**/
QPointF scrollBackBuffer(QPointF now, QPointF last);
void doGesture(PanGesture gesture);
void clearNotifications();
void selectionHelper(QPointF scenePos);
Expand Down

0 comments on commit a41c6f3

Please sign in to comment.