mirror of
https://github.com/cookiengineer/audacity
synced 2025-09-18 17:10:55 +02:00
SelectHandle gets snap information in hit test
This commit is contained in:
parent
49b04208b3
commit
33c6a77f8c
@ -428,23 +428,15 @@ UIHandlePtr SelectHandle::HitTest
|
|||||||
// This handle is a little special because there may be some state to
|
// This handle is a little special because there may be some state to
|
||||||
// preserve during movement before the click.
|
// preserve during movement before the click.
|
||||||
auto old = holder.lock();
|
auto old = holder.lock();
|
||||||
std::shared_ptr<SnapManager> oldSnapManager;
|
|
||||||
if (old) {
|
if (old) {
|
||||||
// It should not have started listening to timer events
|
// It should not have started listening to timer events
|
||||||
wxASSERT( !old->mTimerHandler );
|
wxASSERT( !old->mTimerHandler );
|
||||||
oldSnapManager = std::move(old->mSnapManager);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto result = std::make_shared<SelectHandle>( pTrack );
|
|
||||||
result = AssignUIHandlePtr(holder, result);
|
|
||||||
|
|
||||||
// Copy the pre-dragging state
|
|
||||||
result->mSnapManager = std::move( oldSnapManager );
|
|
||||||
|
|
||||||
const wxMouseState &state = st.state;
|
|
||||||
const wxRect &rect = st.rect;
|
|
||||||
|
|
||||||
const ViewInfo &viewInfo = pProject->GetViewInfo();
|
const ViewInfo &viewInfo = pProject->GetViewInfo();
|
||||||
|
auto result = std::make_shared<SelectHandle>(
|
||||||
|
pTrack, *pProject->GetTracks(), st, viewInfo );
|
||||||
|
result = AssignUIHandlePtr(holder, result);
|
||||||
|
|
||||||
//Make sure we are within the selected track
|
//Make sure we are within the selected track
|
||||||
// Adjusting the selection edges can be turned off in
|
// Adjusting the selection edges can be turned off in
|
||||||
@ -455,6 +447,7 @@ UIHandlePtr SelectHandle::HitTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
const wxRect &rect = st.rect;
|
||||||
wxInt64 leftSel = viewInfo.TimeToPosition(viewInfo.selectedRegion.t0(), rect.x);
|
wxInt64 leftSel = viewInfo.TimeToPosition(viewInfo.selectedRegion.t0(), rect.x);
|
||||||
wxInt64 rightSel = viewInfo.TimeToPosition(viewInfo.selectedRegion.t1(), rect.x);
|
wxInt64 rightSel = viewInfo.TimeToPosition(viewInfo.selectedRegion.t1(), rect.x);
|
||||||
// Something is wrong if right edge comes before left edge
|
// Something is wrong if right edge comes before left edge
|
||||||
@ -464,9 +457,22 @@ UIHandlePtr SelectHandle::HitTest
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
SelectHandle::SelectHandle( const std::shared_ptr<Track> &pTrack )
|
SelectHandle::SelectHandle
|
||||||
|
( const std::shared_ptr<Track> &pTrack, const TrackList &trackList,
|
||||||
|
const TrackPanelMouseState &st, const ViewInfo &viewInfo )
|
||||||
: mpTrack{ pTrack }
|
: mpTrack{ pTrack }
|
||||||
{}
|
, mSnapManager{ std::make_shared<SnapManager>(&trackList, &viewInfo) }
|
||||||
|
{
|
||||||
|
const wxMouseState &state = st.state;
|
||||||
|
const wxRect &rect = st.rect;
|
||||||
|
|
||||||
|
auto time = std::max(0.0, viewInfo.PositionToTime(state.m_x, rect.x));
|
||||||
|
mSnapStart = mSnapManager->Snap(pTrack.get(), time, false);
|
||||||
|
if (mSnapStart.snappedPoint)
|
||||||
|
mSnapStart.outCoord += rect.x;
|
||||||
|
else
|
||||||
|
mSnapStart.outCoord = -1;
|
||||||
|
}
|
||||||
|
|
||||||
SelectHandle::~SelectHandle()
|
SelectHandle::~SelectHandle()
|
||||||
{
|
{
|
||||||
@ -563,16 +569,13 @@ UIHandle::Result SelectHandle::Click
|
|||||||
|
|
||||||
mSelectionBoundary = 0;
|
mSelectionBoundary = 0;
|
||||||
|
|
||||||
if (!mSnapManager) {
|
|
||||||
// We create a NEW snap manager in case any snap-points have changed
|
|
||||||
mSnapManager = std::make_shared<SnapManager>(trackList, &viewInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool bShiftDown = event.ShiftDown();
|
bool bShiftDown = event.ShiftDown();
|
||||||
bool bCtrlDown = event.ControlDown();
|
bool bCtrlDown = event.ControlDown();
|
||||||
|
|
||||||
auto pMixerBoard = pProject->GetMixerBoard();
|
auto pMixerBoard = pProject->GetMixerBoard();
|
||||||
|
|
||||||
|
mSelStart = mSnapStart.outTime;
|
||||||
|
|
||||||
// I. Shift-click adjusts an existing selection
|
// I. Shift-click adjusts an existing selection
|
||||||
if (bShiftDown || bCtrlDown) {
|
if (bShiftDown || bCtrlDown) {
|
||||||
if (bShiftDown)
|
if (bShiftDown)
|
||||||
@ -604,6 +607,7 @@ UIHandle::Result SelectHandle::Click
|
|||||||
mFreqSelMode = FREQ_SEL_INVALID;
|
mFreqSelMode = FREQ_SEL_INVALID;
|
||||||
#endif
|
#endif
|
||||||
mSelStartValid = true;
|
mSelStartValid = true;
|
||||||
|
if (!mSnapStart.Snapped())
|
||||||
mSelStart = value;
|
mSelStart = value;
|
||||||
AdjustSelection(pProject, viewInfo, event.m_x, mRect.x, pTrack);
|
AdjustSelection(pProject, viewInfo, event.m_x, mRect.x, pTrack);
|
||||||
break;
|
break;
|
||||||
@ -699,6 +703,7 @@ UIHandle::Result SelectHandle::Click
|
|||||||
mFreqSelMode = FREQ_SEL_INVALID;
|
mFreqSelMode = FREQ_SEL_INVALID;
|
||||||
#endif
|
#endif
|
||||||
mSelStartValid = true;
|
mSelStartValid = true;
|
||||||
|
if (!mSnapStart.Snapped())
|
||||||
mSelStart = value;
|
mSelStart = value;
|
||||||
break;
|
break;
|
||||||
#ifdef EXPERIMENTAL_SPECTRAL_EDITING
|
#ifdef EXPERIMENTAL_SPECTRAL_EDITING
|
||||||
@ -738,7 +743,7 @@ UIHandle::Result SelectHandle::Click
|
|||||||
#ifdef EXPERIMENTAL_SPECTRAL_EDITING
|
#ifdef EXPERIMENTAL_SPECTRAL_EDITING
|
||||||
StartFreqSelection (viewInfo, event.m_y, mRect.y, mRect.height, pTrack);
|
StartFreqSelection (viewInfo, event.m_y, mRect.y, mRect.height, pTrack);
|
||||||
#endif
|
#endif
|
||||||
StartSelection(pProject, event.m_x, mRect.x);
|
StartSelection(pProject);
|
||||||
selectionState.SelectTrack
|
selectionState.SelectTrack
|
||||||
( *trackList, *pTrack, true, true, pMixerBoard );
|
( *trackList, *pTrack, true, true, pMixerBoard );
|
||||||
trackPanel->SetFocusedTrack(pTrack);
|
trackPanel->SetFocusedTrack(pTrack);
|
||||||
@ -1089,25 +1094,10 @@ void SelectHandle::TimerHandler::OnTimer(wxCommandEvent &event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Reset our selection markers.
|
/// Reset our selection markers.
|
||||||
void SelectHandle::StartSelection
|
void SelectHandle::StartSelection( AudacityProject *pProject )
|
||||||
(AudacityProject *pProject, int mouseXCoordinate, int trackLeftEdge)
|
|
||||||
{
|
{
|
||||||
ViewInfo &viewInfo = pProject->GetViewInfo();
|
ViewInfo &viewInfo = pProject->GetViewInfo();
|
||||||
mSelStartValid = true;
|
mSelStartValid = true;
|
||||||
mSelStart = std::max(0.0, viewInfo.PositionToTime(mouseXCoordinate, trackLeftEdge));
|
|
||||||
|
|
||||||
if (mSnapManager.get()) {
|
|
||||||
auto pTrack = pProject->GetTracks()->Lock(mpTrack);
|
|
||||||
mSnapStart = mSnapManager->Snap(pTrack.get(), mSelStart, false);
|
|
||||||
if (mSnapStart.Snapped()) {
|
|
||||||
// Reassign mSelStart!
|
|
||||||
mSelStart = mSnapStart.outTime;
|
|
||||||
if (mSnapStart.snappedPoint)
|
|
||||||
mSnapStart.outCoord += trackLeftEdge;
|
|
||||||
}
|
|
||||||
if (!mSnapStart.snappedPoint)
|
|
||||||
mSnapStart.outCoord = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
viewInfo.selectedRegion.setTimes(mSelStart, mSelStart);
|
viewInfo.selectedRegion.setTimes(mSelStart, mSelStart);
|
||||||
|
|
||||||
|
@ -24,15 +24,19 @@ class SelectionStateChanger;
|
|||||||
class SnapManager;
|
class SnapManager;
|
||||||
class SpectrumAnalyst;
|
class SpectrumAnalyst;
|
||||||
class Track;
|
class Track;
|
||||||
|
class TrackList;
|
||||||
class ViewInfo;
|
class ViewInfo;
|
||||||
class WaveTrack;
|
class WaveTrack;
|
||||||
|
class wxMouseState;
|
||||||
|
|
||||||
class SelectHandle : public UIHandle
|
class SelectHandle : public UIHandle
|
||||||
{
|
{
|
||||||
SelectHandle(const SelectHandle&);
|
SelectHandle(const SelectHandle&);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit SelectHandle( const std::shared_ptr<Track> &pTrack );
|
explicit SelectHandle
|
||||||
|
(const std::shared_ptr<Track> &pTrack, const TrackList &trackList,
|
||||||
|
const TrackPanelMouseState &st, const ViewInfo &viewInfo);
|
||||||
|
|
||||||
// This always hits, but details of the hit vary with mouse position and
|
// This always hits, but details of the hit vary with mouse position and
|
||||||
// key state.
|
// key state.
|
||||||
@ -71,8 +75,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
void Connect(AudacityProject *pProject);
|
void Connect(AudacityProject *pProject);
|
||||||
|
|
||||||
void StartSelection
|
void StartSelection(AudacityProject *pProject);
|
||||||
(AudacityProject *pProject, int mouseXCoordinate, int trackLeftEdge);
|
|
||||||
void AdjustSelection
|
void AdjustSelection
|
||||||
(AudacityProject *pProject,
|
(AudacityProject *pProject,
|
||||||
ViewInfo &viewInfo, int mouseXCoordinate, int trackLeftEdge,
|
ViewInfo &viewInfo, int mouseXCoordinate, int trackLeftEdge,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user