From 242fa1ee46f90f451c625e90f16927e13030c0a0 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Tue, 29 Apr 2014 01:47:13 -0400 Subject: textscreen: Fix jump when clicking on scrollbars. Clicking on a scrollbar should scroll the cursor to that location, but the logic for it was buggy because of loss of precision when doing an integer divide. When dividing by bar_max, seek up to the nearest value so that the cursor always arrives where we clicked. Thanks to Alexandre-Xavier for reporting this bug. This fixes #359. --- textscreen/txt_scrollpane.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'textscreen') diff --git a/textscreen/txt_scrollpane.c b/textscreen/txt_scrollpane.c index c53f68df..3fd32124 100644 --- a/textscreen/txt_scrollpane.c +++ b/textscreen/txt_scrollpane.c @@ -487,7 +487,7 @@ static void TXT_ScrollPaneMousePress(TXT_UNCAST_ARG(scrollpane), int range = FullWidth(scrollpane) - scrollpane->w; int bar_max = scrollpane->w - 3; - scrollpane->x = ((rel_x - 1) * range + (bar_max / 2)) / bar_max; + scrollpane->x = ((rel_x - 1) * range + bar_max - 1) / bar_max; } return; @@ -509,7 +509,7 @@ static void TXT_ScrollPaneMousePress(TXT_UNCAST_ARG(scrollpane), int range = FullHeight(scrollpane) - scrollpane->h; int bar_max = scrollpane->h - 3; - scrollpane->y = ((rel_y - 1) * range + (bar_max / 2)) / bar_max; + scrollpane->y = ((rel_y - 1) * range + bar_max - 1) / bar_max; } return; -- cgit v1.2.3