From c7338938468d2b88409ef3ec4c3289d389da693e Mon Sep 17 00:00:00 2001 From: Stefano Ceccherini Date: Fri, 29 Dec 2006 07:01:08 +0000 Subject: [PATCH] Greatly improved scrolling, and simplified the code too. Now scrolling is done from inside the BMenu::_track() function, and not inside Pulse() anymore. Patch by Lucasz Zemczak git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19653 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/interface/MenuWindow.h | 2 ++ src/kits/interface/Menu.cpp | 14 ++++++--- src/kits/interface/MenuWindow.cpp | 42 +++++++++++++++++--------- 3 files changed, 40 insertions(+), 18 deletions(-) diff --git a/headers/private/interface/MenuWindow.h b/headers/private/interface/MenuWindow.h index 3c19fbf2eb..269f5c32b6 100644 --- a/headers/private/interface/MenuWindow.h +++ b/headers/private/interface/MenuWindow.h @@ -32,6 +32,8 @@ class BMenuWindow : public BWindow { void AttachScrollers(); void DetachScrollers(); + bool CheckForScrolling(BPoint cursor); + private: BMenuScroller *fScroller; BMenuFrame *fMenuFrame; diff --git a/src/kits/interface/Menu.cpp b/src/kits/interface/Menu.cpp index d29dbc7ee9..4d97201f81 100644 --- a/src/kits/interface/Menu.cpp +++ b/src/kits/interface/Menu.cpp @@ -1270,11 +1270,17 @@ BMenu::_track(int *action, bigtime_t trackTime, long start) BPoint location; ulong buttons; GetMouse(&location, &buttons, true); - + + BMenuWindow *window(static_cast(Window())); + BPoint screenLocation = ConvertToScreen(location); - item = HitTestItems(location, B_ORIGIN); - if (item != NULL) - _UpdateStateOpenSelect(item, openTime, closeTime); + if (window->CheckForScrolling(screenLocation)) { + item = NULL; + } else { + item = HitTestItems(location, B_ORIGIN); + if (item != NULL) + _UpdateStateOpenSelect(item, openTime, closeTime); + } // Track the submenu if (OverSubmenu(fSelected, screenLocation)) { diff --git a/src/kits/interface/MenuWindow.cpp b/src/kits/interface/MenuWindow.cpp index ccfe87e349..6f8fd2fcc5 100644 --- a/src/kits/interface/MenuWindow.cpp +++ b/src/kits/interface/MenuWindow.cpp @@ -23,8 +23,8 @@ class BMenuScroller : public BView { BMenuScroller(BRect frame, BMenu *menu); virtual ~BMenuScroller(); - virtual void Pulse(); virtual void Draw(BRect updateRect); + bool Scroll(BPoint cursor); private: BMenu *fMenu; @@ -62,12 +62,11 @@ using namespace BPrivate; const int kScrollerHeight = 10; -const int kScrollStep = 16; +const int kScrollStep = 19; BMenuScroller::BMenuScroller(BRect frame, BMenu *menu) - : BView(frame, "menu scroller", 0, - B_WILL_DRAW | B_FRAME_EVENTS | B_PULSE_NEEDED), + : BView(frame, "menu scroller", 0, B_WILL_DRAW | B_FRAME_EVENTS), fMenu(menu), fUpperButton(0, 0, frame.right, kScrollerHeight), fLowerButton(0, frame.bottom - kScrollerHeight, frame.right, frame.bottom), @@ -88,18 +87,15 @@ BMenuScroller::~BMenuScroller() } -void -BMenuScroller::Pulse() +bool +BMenuScroller::Scroll(BPoint cursor) { - // To reduce the overhead even a little, fButton and fPosition were - // made private variables. + ConvertFromScreen(&cursor); - // We track the mouse and move the scrollers depending on its position. - GetMouse(&fPosition, &fButton); - if (fLowerButton.Contains(fPosition) && fLowerEnabled) { + if (fLowerEnabled && fLowerButton.Contains(cursor)) { if (fValue == 0) { fUpperEnabled = true; - + Invalidate(fUpperButton); } @@ -110,11 +106,12 @@ BMenuScroller::Pulse() fValue = fLimit; fLowerEnabled = false; Invalidate(fLowerButton); + } else { fMenu->ScrollBy(0, kScrollStep); fValue += kScrollStep; } - } else if (fUpperButton.Contains(fPosition) && fUpperEnabled) { + } else if (fUpperEnabled && fUpperButton.Contains(cursor)) { if (fValue == fLimit) { fLowerEnabled = true; Invalidate(fLowerButton); @@ -125,11 +122,18 @@ BMenuScroller::Pulse() fValue = 0; fUpperEnabled = false; Invalidate(fUpperButton); + } else { fMenu->ScrollBy(0, -kScrollStep); fValue -= kScrollStep; } + } else { + return false; } + + snooze(10000); + + return true; } @@ -252,7 +256,6 @@ BMenuWindow::BMenuWindow(const char *name) fScroller(NULL), fMenuFrame(NULL) { - SetPulseRate(200000); } @@ -325,3 +328,14 @@ BMenuWindow::DetachScrollers() delete fScroller; fScroller = NULL; } + + +bool +BMenuWindow::CheckForScrolling(BPoint cursor) +{ + if (!fScroller) + return false; + + return fScroller->Scroll(cursor); +} +