Skip to content

Commit

Permalink
Simplify mouse wheel handler hook
Browse files Browse the repository at this point in the history
(cherry picked from commit 2f54bdd;
modified for Tenacity)
Signed-off-by: Avery King <[email protected]>
  • Loading branch information
Paul-Licameli authored and generic-pers0n committed Apr 16, 2024
1 parent aff6ab1 commit 896a5d6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 37 deletions.
20 changes: 5 additions & 15 deletions src/ProjectWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,19 +349,11 @@ void ScrollBar::SetScrollbar(int position, int thumbSize,
// Common mouse wheel handling in track panel cells, moved here to avoid
// compilation dependencies on Track, TrackPanel, and Scrubbing at low levels
// which made cycles
static struct MouseWheelHandler {

MouseWheelHandler()
{
CommonTrackPanelCell::InstallMouseWheelHook( *this );
}

static CommonTrackPanelCell::MouseWheelHook::Scope scope{
// Need a bit of memory from one call to the next
mutable double mVertScrollRemainder = 0.0;

unsigned operator()
( const TrackPanelMouseEvent &evt, TenacityProject *pProject ) const
{
[mVertScrollRemainder = 0.0](
const TrackPanelMouseEvent &evt, TenacityProject *pProject )
mutable -> unsigned {
using namespace RefreshCode;

if ( TrackList::Get( *pProject ).empty() )
Expand Down Expand Up @@ -488,9 +480,7 @@ unsigned operator()
}

return result;
}

} sMouseWheelHandler;
} };

AttachedWindows::RegisteredFactory sProjectWindowKey{
[]( TenacityProject &parent ) -> wxWeakRef< wxWindow > {
Expand Down
19 changes: 1 addition & 18 deletions src/tracks/ui/CommonTrackPanelCell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,6 @@ Paul Licameli split from TrackPanel.cpp
#include "../../TrackPanelMouseEvent.h"
#include "ViewInfo.h"

namespace {
CommonTrackPanelCell::Hook &GetHook()
{
static CommonTrackPanelCell::Hook theHook;
return theHook;
}
}

auto CommonTrackPanelCell::InstallMouseWheelHook( const Hook &hook )
-> Hook
{
auto &theHook = GetHook();
auto result = theHook;
theHook = hook;
return result;
}

CommonTrackPanelCell::~CommonTrackPanelCell()
{
}
Expand Down Expand Up @@ -116,7 +99,7 @@ unsigned CommonTrackPanelCell::DoContextMenu( const wxRect &rect,
unsigned CommonTrackPanelCell::HandleWheelRotation
(const TrackPanelMouseEvent &evt, TenacityProject *pProject)
{
auto hook = GetHook();
auto &hook = MouseWheelHook::Get();
return hook ? hook( evt, pProject ) : RefreshCode::Cancelled;
}

Expand Down
7 changes: 3 additions & 4 deletions src/tracks/ui/CommonTrackPanelCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Paul Licameli split from TrackPanel.cpp
#include <memory>
#include <functional>
#include "ComponentInterfaceSymbol.h"
#include "GlobalVariable.h"

#include "XMLTagHandler.h"

Expand All @@ -29,12 +30,10 @@ class TENACITY_DLL_API CommonTrackPanelCell /* not final */
: public TrackPanelCell
{
public:
// Type of function to dispatch mouse wheel events
using Hook = std::function<
// Function to dispatch mouse wheel events
using MouseWheelHook = GlobalHook< CommonTrackPanelCell,
unsigned(const TrackPanelMouseEvent &evt, TenacityProject *pProject)
>;
// Install a dispatcher function, returning the previous function
static Hook InstallMouseWheelHook( const Hook &hook );

CommonTrackPanelCell()
{}
Expand Down

0 comments on commit 896a5d6

Please sign in to comment.