From ba4ae4f7bde14da562bcf46ad701f18a91b9347d Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Sun, 29 Jul 2018 15:47:07 -0400 Subject: [PATCH] Manage ruler cursor changes in CellularPanel base class --- src/widgets/Ruler.cpp | 70 ++++++++++++++++++++++--------------------- src/widgets/Ruler.h | 5 ---- 2 files changed, 36 insertions(+), 39 deletions(-) diff --git a/src/widgets/Ruler.cpp b/src/widgets/Ruler.cpp index 3cf59e675..6ca7ce818 100644 --- a/src/widgets/Ruler.cpp +++ b/src/widgets/Ruler.cpp @@ -2041,6 +2041,20 @@ public: : mParent{ parent } , mMenuChoice{ menuChoice } {} + + HitTestPreview DefaultPreview + (const TrackPanelMouseState &state, const AudacityProject *pProject) + override + { + // May come here when recording is in progress, so hit tests are turned + // off. + static wxCursor cursor{ wxCURSOR_DEFAULT }; + return { + {}, + &cursor, + {}, + }; + } unsigned DoContextMenu (const wxRect &rect, @@ -2284,11 +2298,6 @@ AdornedRulerPanel::AdornedRulerPanel(AudacityProject* project, SetName(GetLabel()); SetBackgroundStyle(wxBG_STYLE_PAINT); - mCursorDefault = wxCursor(wxCURSOR_DEFAULT); - mCursorHand = wxCursor(wxCURSOR_HAND); - mCursorSizeWE = wxCursor(wxCURSOR_SIZEWE); - mIsWE = false; - mLeftOffset = 0; mIndTime = -1; @@ -2554,9 +2563,6 @@ void AdornedRulerPanel::OnRecordStartStop(wxCommandEvent & evt) this->CellularPanel::CancelDragging(); this->CellularPanel::ClearTargets(); - // Set cursor immediately because OnMouseEvents is not called - // if recording is initiated by a modal window (Timer Record). - SetCursor(mCursorDefault); UpdateButtonStates(); // The quick play indicator is useless during recording @@ -2564,9 +2570,11 @@ void AdornedRulerPanel::OnRecordStartStop(wxCommandEvent & evt) } else { mIsRecording = false; - SetCursor(mCursorHand); UpdateButtonStates(); } + + CallAfter( [this]{ HandleCursorForPresentMouseState(); } ); + RegenerateTooltips(mPrevZone); } @@ -2751,9 +2759,6 @@ void AdornedRulerPanel::OnMouseEvents(wxMouseEvent &evt) DrawBothOverlays(); } - SetCursor(mCursorDefault); - mIsWE = false; - mSnapManager.reset(); if(evt.Leaving()) @@ -2761,7 +2766,6 @@ void AdornedRulerPanel::OnMouseEvents(wxMouseEvent &evt) // else, may detect a scrub click below } else if (evt.Entering() || (changeInZone && zone == StatusChoice::EnteringQP)) { - SetCursor(mCursorHand); DrawBothOverlays(); return; } @@ -2802,22 +2806,6 @@ void AdornedRulerPanel::OnMouseEvents(wxMouseEvent &evt) return; } else if ( mQuickPlayEnabled) { - bool isWithinStart = IsWithinMarker(mousePosX, mOldPlayRegionStart); - bool isWithinEnd = IsWithinMarker(mousePosX, mOldPlayRegionEnd); - - if (isWithinStart || isWithinEnd) { - if (!mIsWE) { - SetCursor(mCursorSizeWE); - mIsWE = true; - } - } - else { - if (mIsWE) { - SetCursor(mCursorHand); - mIsWE = false; - } - } - if (evt.LeftDown()) { if( inQPZone ){ HandleQPClick(evt, mousePosX); @@ -2890,10 +2878,6 @@ void AdornedRulerPanel::HandleQPClick(wxMouseEvent &evt, wxCoord mousePosX) // Clicked but not yet dragging mMouseEventState = mesSelectingPlayRegionClick; } - - // Check if we are dragging BEFORE CaptureMouse. - if (mMouseEventState != mesNone) - SetCursor(mCursorSizeWE); } auto AdornedRulerPanel::QPHandle::Drag @@ -2997,7 +2981,25 @@ auto AdornedRulerPanel::ScrubbingHandle::Preview auto AdornedRulerPanel::QPHandle::Preview (const TrackPanelMouseState &state, const AudacityProject *pProject) -> HitTestPreview -{ return {}; } +{ + static wxCursor cursorHand{ wxCURSOR_HAND }; + static wxCursor cursorSizeWE{ wxCURSOR_SIZEWE }; + + bool showArrows = false; + if (mParent && mParent->mQuickPlayEnabled) + showArrows = + (mClicked == Button::Left) + || mParent->IsWithinMarker( + state.state.m_x, mParent->mOldPlayRegionStart) + || mParent->IsWithinMarker( + state.state.m_x, mParent->mOldPlayRegionEnd); + + return { + {}, + showArrows ? &cursorSizeWE : &cursorHand, + {}, + }; +} auto AdornedRulerPanel::QPHandle::Release (const TrackPanelMouseEvent &event, AudacityProject *pProject, diff --git a/src/widgets/Ruler.h b/src/widgets/Ruler.h index 493febc70..3bea2b7fb 100644 --- a/src/widgets/Ruler.h +++ b/src/widgets/Ruler.h @@ -410,11 +410,6 @@ private: private: - wxCursor mCursorDefault; - wxCursor mCursorHand; - wxCursor mCursorSizeWE; - bool mIsWE; - Ruler mRuler; AudacityProject *const mProject; TrackList *mTracks;