diff --git a/src/LabelTrack.cpp b/src/LabelTrack.cpp index 8e8736a94..3b3fbacb1 100644 --- a/src/LabelTrack.cpp +++ b/src/LabelTrack.cpp @@ -1525,13 +1525,13 @@ auto LabelStruct::RegionRelation( /// @iEdge - which edge is requested to move, -1 for left +1 for right. /// @bAllowSwapping - if we can switch which edge is being dragged. /// fNewTime - the NEW time for this edge of the label. -void LabelTrackView::MayAdjustLabel +void LabelGlyphHandle::MayAdjustLabel ( LabelTrackHit &hit, int iLabel, int iEdge, bool bAllowSwapping, double fNewTime) { if( iLabel < 0 ) return; - const auto pTrack = FindLabelTrack(); + const auto pTrack = mpLT; const auto &mLabels = pTrack->GetLabels(); auto labelStruct = mLabels[ iLabel ]; @@ -1559,12 +1559,12 @@ void LabelTrackView::MayAdjustLabel } // If the index is for a real label, adjust its left and right boundary. -void LabelTrackView::MayMoveLabel( int iLabel, int iEdge, double fNewTime) +void LabelGlyphHandle::MayMoveLabel( int iLabel, int iEdge, double fNewTime) { if( iLabel < 0 ) return; - const auto pTrack = FindLabelTrack(); + const auto pTrack = mpLT; const auto &mLabels = pTrack->GetLabels(); auto labelStruct = mLabels[ iLabel ]; labelStruct.MoveLabel( iEdge, fNewTime ); @@ -1584,12 +1584,12 @@ static int Constrain( int value, int min, int max ) return result; } -bool LabelTrackView::HandleGlyphDragRelease +bool LabelGlyphHandle::HandleGlyphDragRelease (LabelTrackHit &hit, const wxMouseEvent & evt, wxRect & r, const ZoomInfo &zoomInfo, SelectedRegion *newSel) { - const auto pTrack = FindLabelTrack(); + const auto pTrack = mpLT; const auto &mLabels = pTrack->GetLabels(); if(evt.LeftUp()) { @@ -1643,11 +1643,12 @@ bool LabelTrackView::HandleGlyphDragRelease MayAdjustLabel( hit, hit.mMouseOverLabelRight, +1, bAllowSwapping, fNewX ); } - if( HasSelection() ) + if( pTrack->HasSelection() ) { + auto selIndex = LabelTrackView::Get( *pTrack ).GetSelectedIndex(); //Set the selection region to be equal to //the NEW size of the label. - *newSel = mLabels[mSelIndex].selectedRegion; + *newSel = mLabels[ selIndex ].selectedRegion; } pTrack->SortLabels(); } @@ -1701,7 +1702,7 @@ void LabelTrackView::HandleTextDragRelease(const wxMouseEvent & evt) return; } -void LabelTrackView::HandleGlyphClick +void LabelGlyphHandle::HandleGlyphClick (LabelTrackHit &hit, const wxMouseEvent & evt, const wxRect & r, const ZoomInfo &zoomInfo, SelectedRegion *WXUNUSED(newSel)) @@ -1709,8 +1710,8 @@ void LabelTrackView::HandleGlyphClick if (evt.ButtonDown()) { //OverGlyph sets mMouseOverLabel to be the chosen label. - const auto pTrack = FindLabelTrack(); - OverGlyph(*pTrack, hit, evt.m_x, evt.m_y); + const auto pTrack = mpLT; + LabelTrackView::OverGlyph(*pTrack, hit, evt.m_x, evt.m_y); hit.mIsAdjustingLabel = evt.Button(wxMOUSE_BTN_LEFT) && ( hit.mEdge & 3 ) != 0; diff --git a/src/tracks/labeltrack/ui/LabelGlyphHandle.cpp b/src/tracks/labeltrack/ui/LabelGlyphHandle.cpp index 2c100fa4c..c1b6ffc15 100644 --- a/src/tracks/labeltrack/ui/LabelGlyphHandle.cpp +++ b/src/tracks/labeltrack/ui/LabelGlyphHandle.cpp @@ -129,7 +129,7 @@ UIHandle::Result LabelGlyphHandle::Click const wxMouseEvent &event = evt.event; auto &viewInfo = ViewInfo::Get( *pProject ); - LabelTrackView::Get( *mpLT ).HandleGlyphClick( + HandleGlyphClick( *mpHit, event, mRect, viewInfo, &viewInfo.selectedRegion); if (! mpHit->mIsAdjustingLabel ) @@ -159,7 +159,7 @@ UIHandle::Result LabelGlyphHandle::Drag const wxMouseEvent &event = evt.event; auto &viewInfo = ViewInfo::Get( *pProject ); - LabelTrackView::Get( *mpLT ).HandleGlyphDragRelease( + HandleGlyphDragRelease( *mpHit, event, mRect, viewInfo, &viewInfo.selectedRegion); // Refresh all so that the change of selection is redrawn in all tracks @@ -180,7 +180,7 @@ UIHandle::Result LabelGlyphHandle::Release const wxMouseEvent &event = evt.event; auto &viewInfo = ViewInfo::Get( *pProject ); - if (LabelTrackView::Get( *mpLT ).HandleGlyphDragRelease( + if (HandleGlyphDragRelease( *mpHit, event, mRect, viewInfo, &viewInfo.selectedRegion)) { ProjectHistory::Get( *pProject ).PushState(_("Modified Label"), _("Label Edit"), diff --git a/src/tracks/labeltrack/ui/LabelGlyphHandle.h b/src/tracks/labeltrack/ui/LabelGlyphHandle.h index ff21fd3ec..276ea9ca7 100644 --- a/src/tracks/labeltrack/ui/LabelGlyphHandle.h +++ b/src/tracks/labeltrack/ui/LabelGlyphHandle.h @@ -16,6 +16,8 @@ Paul Licameli split from TrackPanel.cpp class wxMouseState; class LabelTrack; class LabelTrackEvent; +class SelectedRegion; +class ZoomInfo; /// mEdge: /// 0 if not over a glyph, @@ -87,8 +89,25 @@ public: (const LabelGlyphHandle &oldState, const LabelGlyphHandle &newState); private: + void HandleGlyphClick + (LabelTrackHit &hit, + const wxMouseEvent & evt, const wxRect & r, const ZoomInfo &zoomInfo, + SelectedRegion *newSel); + bool HandleGlyphDragRelease + (LabelTrackHit &hit, + const wxMouseEvent & evt, wxRect & r, const ZoomInfo &zoomInfo, + SelectedRegion *newSel); + + void MayAdjustLabel + ( LabelTrackHit &hit, + int iLabel, int iEdge, bool bAllowSwapping, double fNewTime); + void MayMoveLabel( int iLabel, int iEdge, double fNewTime); + std::shared_ptr mpLT {}; wxRect mRect {}; + + /// Displacement of mouse cursor from the centre being dragged. + int mxMouseDisplacement; }; #endif diff --git a/src/tracks/labeltrack/ui/LabelTrackView.h b/src/tracks/labeltrack/ui/LabelTrackView.h index 7fb4338ff..6550a9b34 100644 --- a/src/tracks/labeltrack/ui/LabelTrackView.h +++ b/src/tracks/labeltrack/ui/LabelTrackView.h @@ -139,17 +139,9 @@ public: private: static bool IsTextClipSupported(); - void HandleGlyphClick - (LabelTrackHit &hit, - const wxMouseEvent & evt, const wxRect & r, const ZoomInfo &zoomInfo, - SelectedRegion *newSel); void HandleTextClick (const wxMouseEvent & evt, const wxRect & r, const ZoomInfo &zoomInfo, SelectedRegion *newSel); - bool HandleGlyphDragRelease - (LabelTrackHit &hit, - const wxMouseEvent & evt, wxRect & r, const ZoomInfo &zoomInfo, - SelectedRegion *newSel); void HandleTextDragRelease(const wxMouseEvent & evt); public: @@ -168,16 +160,10 @@ public: private: void CalcHighlightXs(int *x1, int *x2) const; - void MayAdjustLabel - ( LabelTrackHit &hit, - int iLabel, int iEdge, bool bAllowSwapping, double fNewTime); - void MayMoveLabel( int iLabel, int iEdge, double fNewTime); - void ShowContextMenu(); void OnContextMenu(wxCommandEvent & evt); mutable int mSelIndex{-1}; /// Keeps track of the currently selected label - int mxMouseDisplacement; /// Displacement of mouse cursor from the centre being dragged. static int mIconHeight; static int mIconWidth; @@ -226,7 +212,6 @@ private: static wxFont msFont; friend LabelDefaultClickHandle; - friend LabelGlyphHandle; friend LabelTextHandle; };