mirror of
https://github.com/cookiengineer/audacity
synced 2025-08-10 17:11:17 +02:00
Move the scrub mouse event handler into ScrubUI...
... Making Scrubbing independent of AdornedRulerPanel.cpp
This commit is contained in:
parent
8414ebffa5
commit
a3b434be1c
@ -15,6 +15,7 @@
|
|||||||
#include "../../ClientData.h"
|
#include "../../ClientData.h"
|
||||||
#include "../../AdornedRulerPanel.h"
|
#include "../../AdornedRulerPanel.h"
|
||||||
#include "../../Project.h"
|
#include "../../Project.h"
|
||||||
|
#include "../../ProjectWindow.h"
|
||||||
#include "../../TrackPanel.h"
|
#include "../../TrackPanel.h"
|
||||||
|
|
||||||
#include <wx/dcclient.h>
|
#include <wx/dcclient.h>
|
||||||
@ -207,3 +208,70 @@ static const AudacityProject::AttachedObjects::RegisteredFactory sOverlayKey{
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
// class ScrubForwarder intercepts some mouse events of the main window
|
||||||
|
|
||||||
|
// I need this because I can't push the scrubber as an event handler
|
||||||
|
// in two places at once.
|
||||||
|
struct ScrubForwarder
|
||||||
|
: public wxEvtHandler
|
||||||
|
, public ClientData::Base
|
||||||
|
{
|
||||||
|
ScrubForwarder( AudacityProject &project ) : mProject{ project } {}
|
||||||
|
|
||||||
|
AudacityProject &mProject;
|
||||||
|
|
||||||
|
void OnMouse(wxMouseEvent &event);
|
||||||
|
DECLARE_EVENT_TABLE()
|
||||||
|
};
|
||||||
|
|
||||||
|
void ScrubForwarder::OnMouse(wxMouseEvent &event)
|
||||||
|
{
|
||||||
|
auto &scrubber = Scrubber::Get( mProject );
|
||||||
|
|
||||||
|
auto &ruler = AdornedRulerPanel::Get( mProject );
|
||||||
|
const auto &state = ::wxGetMouseState();
|
||||||
|
const auto &position = state.GetPosition();
|
||||||
|
scrubber.SetMayDragToSeek(
|
||||||
|
ruler.GetScreenRect().Contains(position) );
|
||||||
|
|
||||||
|
/*
|
||||||
|
auto trackPanel = mProject->GetTrackPanel();
|
||||||
|
if (trackPanel &&
|
||||||
|
trackPanel->GetScreenRect().Contains(position))
|
||||||
|
return true;
|
||||||
|
*/
|
||||||
|
|
||||||
|
//auto ruler = scrubber.mProject->GetRulerPanel();
|
||||||
|
auto isScrubbing = scrubber.IsScrubbing();
|
||||||
|
if (isScrubbing && !event.HasAnyModifiers()) {
|
||||||
|
if(event.LeftDown() && scrubber.MayDragToSeek()) {
|
||||||
|
// This event handler may catch mouse transitions that are missed
|
||||||
|
// by the polling of mouse state by the timer.
|
||||||
|
scrubber.SetSeekPress( true );
|
||||||
|
}
|
||||||
|
else if (event.m_wheelRotation) {
|
||||||
|
double steps = event.m_wheelRotation /
|
||||||
|
(event.m_wheelDelta > 0 ? (double)event.m_wheelDelta : 120.0);
|
||||||
|
scrubber.HandleScrollWheel(steps);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
event.Skip();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
event.Skip();
|
||||||
|
}
|
||||||
|
|
||||||
|
BEGIN_EVENT_TABLE(ScrubForwarder, wxEvtHandler)
|
||||||
|
EVT_MOUSE_EVENTS(ScrubForwarder::OnMouse)
|
||||||
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
|
static const AudacityProject::AttachedObjects::RegisteredFactory sForwarderKey{
|
||||||
|
[]( AudacityProject &parent ){
|
||||||
|
auto result = std::make_shared< ScrubForwarder >( parent );
|
||||||
|
auto &window = ProjectWindow::Get( parent );
|
||||||
|
window.PushEventHandler( result.get() );
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
@ -15,7 +15,6 @@ Paul Licameli split from TrackPanel.cpp
|
|||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
#include "../../AdornedRulerPanel.h"
|
|
||||||
#include "../../AudioIO.h"
|
#include "../../AudioIO.h"
|
||||||
#include "../../CommonCommandFlags.h"
|
#include "../../CommonCommandFlags.h"
|
||||||
#include "../../Menus.h"
|
#include "../../Menus.h"
|
||||||
@ -231,8 +230,6 @@ Scrubber::Scrubber(AudacityProject *project)
|
|||||||
wxTheApp->Bind
|
wxTheApp->Bind
|
||||||
(wxEVT_ACTIVATE_APP,
|
(wxEVT_ACTIVATE_APP,
|
||||||
&Scrubber::OnActivateOrDeactivateApp, this);
|
&Scrubber::OnActivateOrDeactivateApp, this);
|
||||||
if (mWindow)
|
|
||||||
mWindow->PushEventHandler(&mForwarder);
|
|
||||||
|
|
||||||
UpdatePrefs();
|
UpdatePrefs();
|
||||||
}
|
}
|
||||||
@ -779,27 +776,6 @@ bool Scrubber::ChoseSeeking() const
|
|||||||
mSeeking;
|
mSeeking;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Scrubber::MayDragToSeek() const
|
|
||||||
{
|
|
||||||
// Return true only if the pointer is in the
|
|
||||||
// ruler or the track panel
|
|
||||||
const auto &state = ::wxGetMouseState();
|
|
||||||
const auto &position = state.GetPosition();
|
|
||||||
|
|
||||||
auto &ruler = AdornedRulerPanel::Get( *mProject );
|
|
||||||
if (ruler.GetScreenRect().Contains(position))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
/*
|
|
||||||
auto trackPanel = mProject->GetTrackPanel();
|
|
||||||
if (trackPanel &&
|
|
||||||
trackPanel->GetScreenRect().Contains(position))
|
|
||||||
return true;
|
|
||||||
*/
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Scrubber::TemporarilySeeks() const
|
bool Scrubber::TemporarilySeeks() const
|
||||||
{
|
{
|
||||||
return mScrubSeekPress ||
|
return mScrubSeekPress ||
|
||||||
@ -891,28 +867,6 @@ void Scrubber::OnActivateOrDeactivateApp(wxActivateEvent &event)
|
|||||||
event.Skip();
|
event.Skip();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scrubber::Forwarder::OnMouse(wxMouseEvent &event)
|
|
||||||
{
|
|
||||||
//auto ruler = scrubber.mProject->GetRulerPanel();
|
|
||||||
auto isScrubbing = scrubber.IsScrubbing();
|
|
||||||
if (isScrubbing && !event.HasAnyModifiers()) {
|
|
||||||
if(event.LeftDown() && scrubber.MayDragToSeek()) {
|
|
||||||
// This event handler may catch mouse transitions that are missed
|
|
||||||
// by the polling of mouse state by the timer.
|
|
||||||
scrubber.mScrubSeekPress = true;
|
|
||||||
}
|
|
||||||
else if (event.m_wheelRotation) {
|
|
||||||
double steps = event.m_wheelRotation /
|
|
||||||
(event.m_wheelDelta > 0 ? (double)event.m_wheelDelta : 120.0);
|
|
||||||
scrubber.HandleScrollWheel(steps);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
event.Skip();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
event.Skip();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Scrubber::DoScrub(bool seek)
|
void Scrubber::DoScrub(bool seek)
|
||||||
{
|
{
|
||||||
if( !CanScrub() )
|
if( !CanScrub() )
|
||||||
@ -1005,10 +959,6 @@ BEGIN_EVENT_TABLE(Scrubber, wxEvtHandler)
|
|||||||
EVT_MENU(CMD_ID + 2, THUNK(OnToggleScrubRuler))
|
EVT_MENU(CMD_ID + 2, THUNK(OnToggleScrubRuler))
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
BEGIN_EVENT_TABLE(Scrubber::Forwarder, wxEvtHandler)
|
|
||||||
EVT_MOUSE_EVENTS(Scrubber::Forwarder::OnMouse)
|
|
||||||
END_EVENT_TABLE()
|
|
||||||
|
|
||||||
static_assert(nMenuItems == 3, "wrong number of items");
|
static_assert(nMenuItems == 3, "wrong number of items");
|
||||||
|
|
||||||
static wxString sPlayAtSpeedStatus = XO("Playing at Speed");
|
static wxString sPlayAtSpeedStatus = XO("Playing at Speed");
|
||||||
|
@ -88,7 +88,8 @@ public:
|
|||||||
{ mSmoothScrollingScrub = value; }
|
{ mSmoothScrollingScrub = value; }
|
||||||
|
|
||||||
bool ChoseSeeking() const;
|
bool ChoseSeeking() const;
|
||||||
bool MayDragToSeek() const;
|
void SetMayDragToSeek( bool value ) { mMayDragToSeek = value; }
|
||||||
|
bool MayDragToSeek() const { return mMayDragToSeek; }
|
||||||
bool TemporarilySeeks() const;
|
bool TemporarilySeeks() const;
|
||||||
bool Seeks() const;
|
bool Seeks() const;
|
||||||
bool Scrubs() const;
|
bool Scrubs() const;
|
||||||
@ -132,6 +133,8 @@ public:
|
|||||||
|
|
||||||
bool IsTransportingPinned() const;
|
bool IsTransportingPinned() const;
|
||||||
|
|
||||||
|
void SetSeekPress( bool value ) { mScrubSeekPress = value; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void UpdatePrefs() override;
|
void UpdatePrefs() override;
|
||||||
|
|
||||||
@ -140,18 +143,6 @@ private:
|
|||||||
void DoScrub(bool seek);
|
void DoScrub(bool seek);
|
||||||
void OnActivateOrDeactivateApp(wxActivateEvent & event);
|
void OnActivateOrDeactivateApp(wxActivateEvent & event);
|
||||||
|
|
||||||
// I need this because I can't push the scrubber as an event handler
|
|
||||||
// in two places at once.
|
|
||||||
struct Forwarder : public wxEvtHandler {
|
|
||||||
Forwarder(Scrubber &scrubber_) : scrubber( scrubber_ ) {}
|
|
||||||
|
|
||||||
Scrubber &scrubber;
|
|
||||||
|
|
||||||
void OnMouse(wxMouseEvent &event);
|
|
||||||
DECLARE_EVENT_TABLE()
|
|
||||||
};
|
|
||||||
Forwarder mForwarder{ *this };
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int mScrubToken;
|
int mScrubToken;
|
||||||
int mScrubSpeedDisplayCountdown;
|
int mScrubSpeedDisplayCountdown;
|
||||||
@ -192,6 +183,7 @@ private:
|
|||||||
double mMaxSpeed { 1.0 };
|
double mMaxSpeed { 1.0 };
|
||||||
|
|
||||||
bool mShowScrubbing { false };
|
bool mShowScrubbing { false };
|
||||||
|
bool mMayDragToSeek{ false };
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user