From 5eb5e24ab0e4ccdb122a0d3e58b4638d6be2606c Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Fri, 9 Nov 2018 07:46:29 -0500 Subject: [PATCH] Make some hit testing utilities of LabelTrackView static and public --- src/LabelTrack.cpp | 24 ++++++++++--------- src/tracks/labeltrack/ui/LabelGlyphHandle.cpp | 2 +- src/tracks/labeltrack/ui/LabelTextHandle.cpp | 6 ++--- src/tracks/labeltrack/ui/LabelTrackView.h | 12 ++++++---- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/LabelTrack.cpp b/src/LabelTrack.cpp index d31ddb372..8e8736a94 100644 --- a/src/LabelTrack.cpp +++ b/src/LabelTrack.cpp @@ -1248,7 +1248,8 @@ Track::Holder LabelTrack::Clone() const /// TODO: Investigate what happens with large /// numbers of labels, might need a binary search /// rather than a linear one. -void LabelTrackView::OverGlyph(LabelTrackHit &hit, int x, int y) const +void LabelTrackView::OverGlyph( + const LabelTrack &track, LabelTrackHit &hit, int x, int y) { //Determine the NEW selection. int result=0; @@ -1260,7 +1261,7 @@ void LabelTrackView::OverGlyph(LabelTrackHit &hit, int x, int y) const hit.mMouseOverLabelRight = -1; hit.mEdge = 0; - const auto pTrack = FindLabelTrack(); + const auto pTrack = &track; const auto &mLabels = pTrack->GetLabels(); { int i = -1; for (const auto &labelStruct : mLabels) { ++i; //over left or right selection bound @@ -1304,13 +1305,13 @@ void LabelTrackView::OverGlyph(LabelTrackHit &hit, int x, int y) const hit.mEdge = result; } -int LabelTrackView::OverATextBox(int xx, int yy) const +int LabelTrackView::OverATextBox( const LabelTrack &track, int xx, int yy ) { - const auto pTrack = FindLabelTrack(); + const auto pTrack = &track; const auto &mLabels = pTrack->GetLabels(); for (int nn = (int)mLabels.size(); nn--;) { const auto &labelStruct = mLabels[nn]; - if (OverTextBox(&labelStruct, xx, yy)) + if ( OverTextBox( &labelStruct, xx, yy ) ) return nn; } @@ -1318,7 +1319,7 @@ int LabelTrackView::OverATextBox(int xx, int yy) const } // return true if the mouse is over text box, false otherwise -bool LabelTrackView::OverTextBox(const LabelStruct *pLabel, int x, int y) const +bool LabelTrackView::OverTextBox(const LabelStruct *pLabel, int x, int y) { if( (pLabel->xText-(mIconWidth/2) < x) && (xxText+pLabel->width+(mIconWidth/2)) && @@ -1689,7 +1690,8 @@ void LabelTrackView::HandleTextDragRelease(const wxMouseEvent & evt) if (evt.RightUp()) { const auto pTrack = FindLabelTrack(); if (HasSelection() && - OverTextBox(pTrack->GetLabel(mSelIndex), evt.m_x, evt.m_y)) { + OverTextBox( + pTrack->GetLabel(mSelIndex), evt.m_x, evt.m_y)) { // popup menu for editing // TODO: handle context menus via CellularPanel? ShowContextMenu(); @@ -1707,7 +1709,8 @@ void LabelTrackView::HandleGlyphClick if (evt.ButtonDown()) { //OverGlyph sets mMouseOverLabel to be the chosen label. - OverGlyph(hit, evt.m_x, evt.m_y); + const auto pTrack = FindLabelTrack(); + OverGlyph(*pTrack, hit, evt.m_x, evt.m_y); hit.mIsAdjustingLabel = evt.Button(wxMOUSE_BTN_LEFT) && ( hit.mEdge & 3 ) != 0; @@ -1730,7 +1733,6 @@ void LabelTrackView::HandleGlyphClick // Dragging of three label edges at the same time is not supported (yet). - const auto pTrack = FindLabelTrack(); const auto &mLabels = pTrack->GetLabels(); if( ( hit.mMouseOverLabelRight >= 0 ) && ( hit.mMouseOverLabelLeft >= 0 ) @@ -1766,9 +1768,9 @@ void LabelTrackView::HandleTextClick(const wxMouseEvent & evt, if (evt.ButtonDown()) { - mSelIndex = OverATextBox(evt.m_x, evt.m_y); + const auto pTrack = FindLabelTrack(); + mSelIndex = OverATextBox( *pTrack, evt.m_x, evt.m_y ); if (mSelIndex != -1) { - const auto pTrack = FindLabelTrack(); const auto &mLabels = pTrack->GetLabels(); const auto &labelStruct = mLabels[mSelIndex]; *newSel = labelStruct.selectedRegion; diff --git a/src/tracks/labeltrack/ui/LabelGlyphHandle.cpp b/src/tracks/labeltrack/ui/LabelGlyphHandle.cpp index ec71c5748..2c100fa4c 100644 --- a/src/tracks/labeltrack/ui/LabelGlyphHandle.cpp +++ b/src/tracks/labeltrack/ui/LabelGlyphHandle.cpp @@ -103,7 +103,7 @@ UIHandlePtr LabelGlyphHandle::HitTest // LabelGlyphHandle can be copyable: auto pHit = std::make_shared( pLT ); - LabelTrackView::Get( *pLT ).OverGlyph(*pHit, state.m_x, state.m_y); + LabelTrackView::OverGlyph(*pLT, *pHit, state.m_x, state.m_y); // IF edge!=0 THEN we've set the cursor and we're done. // signal this by setting the tip. diff --git a/src/tracks/labeltrack/ui/LabelTextHandle.cpp b/src/tracks/labeltrack/ui/LabelTextHandle.cpp index eaa313a04..7c3948e58 100644 --- a/src/tracks/labeltrack/ui/LabelTextHandle.cpp +++ b/src/tracks/labeltrack/ui/LabelTextHandle.cpp @@ -55,8 +55,8 @@ UIHandlePtr LabelTextHandle::HitTest // If Control is down, let the select handle be hit instead int labelNum; if (!state.ControlDown() && - (labelNum = LabelTrackView::Get( *pLT ). - OverATextBox(state.m_x, state.m_y) ) >= 0) { + (labelNum = + LabelTrackView::OverATextBox(*pLT, state.m_x, state.m_y) ) >= 0) { auto result = std::make_shared( pLT, labelNum ); result = AssignUIHandlePtr(holder, result); return result; @@ -137,7 +137,7 @@ UIHandle::Result LabelTextHandle::Drag if (pLT && (pView->GetSelectedIndex() != -1) && - pView->OverTextBox( + LabelTrackView::OverTextBox( pLT->GetLabel(pView->GetSelectedIndex()), mLabelTrackStartXPos, mLabelTrackStartYPos)) diff --git a/src/tracks/labeltrack/ui/LabelTrackView.h b/src/tracks/labeltrack/ui/LabelTrackView.h index 34b4301fb..7fb4338ff 100644 --- a/src/tracks/labeltrack/ui/LabelTrackView.h +++ b/src/tracks/labeltrack/ui/LabelTrackView.h @@ -110,9 +110,10 @@ public: bool CopySelectedText(); bool PasteSelectedText(double sel0, double sel1); -private: - void OverGlyph(LabelTrackHit &hit, int x, int y) const; + static void OverGlyph( + const LabelTrack &track, LabelTrackHit &hit, int x, int y ); +private: static wxBitmap & GetGlyph( int i); struct Flags { @@ -130,9 +131,12 @@ private: } void RestoreFlags( const Flags& flags ); - int OverATextBox(int xx, int yy) const; - bool OverTextBox(const LabelStruct *pLabel, int x, int y) const; +public: + static int OverATextBox( const LabelTrack &track, int xx, int yy ); + static bool OverTextBox( const LabelStruct *pLabel, int x, int y ); + +private: static bool IsTextClipSupported(); void HandleGlyphClick