From 12f666c1d521668911b3e0143fafb8cf8bd7952b Mon Sep 17 00:00:00 2001 From: Po Lu Date: Sun, 13 Mar 2022 07:22:59 +0000 Subject: [PATCH] Improve overscrolling support on Haiku * src/haiku_support.cc (class EmacsScrollBar): New field `real_max_value'. (MessageReceived): Set real max value. (MouseMoved): Get rid of magic numbers by using real max value instead. --- src/haiku_support.cc | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/haiku_support.cc b/src/haiku_support.cc index 98cc8e93147..5fc8d2675ee 100644 --- a/src/haiku_support.cc +++ b/src/haiku_support.cc @@ -1569,7 +1569,8 @@ public: bool can_overscroll = false; BPoint last_overscroll; int last_reported_overscroll_value; - int max_value; + int max_value, real_max_value; + int overscroll_start_value; EmacsScrollBar (int x, int y, int x1, int y1, bool horizontal_p) : BScrollBar (BRect (x, y, x1, y1), NULL, NULL, 0, 0, horizontal_p ? @@ -1593,7 +1594,8 @@ public: portion = msg->GetInt32 ("emacs:portion", 0); range = msg->GetInt32 ("emacs:range", 0); dragging = msg->GetInt32 ("emacs:dragging", 0); - proportion = (float) portion / range; + proportion = ((range <= 0 || portion <= 0) + ? 1.0f : (float) portion / range); value = msg->GetInt32 ("emacs:units", 0); can_overscroll = msg->GetBool ("emacs:overscroll", false); @@ -1616,6 +1618,7 @@ public: SetRange (0, range - portion); SetProportion (proportion); max_value = range - portion; + real_max_value = range; if (in_overscroll || value > max_value) value = max_value; @@ -1634,6 +1637,7 @@ public: old_value = value; SetValue (value); max_value = range - portion; + real_max_value = range; } } } @@ -1879,21 +1883,20 @@ public: goto allow; } - range = max_value; + range = real_max_value; bounds = Bounds (); bounds.InsetBy (1.0, 1.0); - value = Value (); + value = overscroll_start_value; trough_size = BE_RECT_HEIGHT (bounds); trough_size -= BE_RECT_WIDTH (bounds) / 2; if (info.double_arrows) trough_size -= BE_RECT_WIDTH (bounds) / 2; - value += ((double) range / trough_size) * diff * 2; + value += ((double) range / trough_size) * diff; if (value != last_reported_overscroll_value) { last_reported_overscroll_value = value; - last_overscroll = point; value_event.scroll_bar = this; value_event.window = Window (); @@ -1913,6 +1916,7 @@ public: if (value == Value () && Proportion () < 1.0f) { + overscroll_start_value = value; in_overscroll = true; last_overscroll = point; last_reported_overscroll_value = value; -- 2.39.5