1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-08-03 09:29:30 +02:00

Make some hit testing utilities of LabelTrackView static and public

This commit is contained in:
Paul Licameli 2018-11-09 07:46:29 -05:00
parent e3efd52026
commit 5eb5e24ab0
4 changed files with 25 additions and 19 deletions

View File

@ -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) &&
(x<pLabel->xText+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;

View File

@ -103,7 +103,7 @@ UIHandlePtr LabelGlyphHandle::HitTest
// LabelGlyphHandle can be copyable:
auto pHit = std::make_shared<LabelTrackHit>( 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.

View File

@ -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<LabelTextHandle>( 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))

View File

@ -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