Add 'Select Track' Button.

This is a first take at this new feature.  I'm expecting we'll want to refine it.
https://wiki.audacityteam.org/wiki/Proposal_Select_Track_button_in_TCP has the feature proposal.
This commit is contained in:
James Crook 2019-03-21 19:41:40 +00:00
parent d2fbeaa9f5
commit 4ff7d7875a
6 changed files with 141 additions and 1 deletions

View File

@ -1379,6 +1379,36 @@ void TrackInfo::MinimizeSyncLockDrawFunction
minimized);
}
{
wxRect bev = rect;
GetSelectButtonHorizontalBounds(rect, bev);
auto target = dynamic_cast<SelectButtonHandle*>( context.target.get() );
bool hit = target && target->GetTrack().get() == pTrack;
bool captured = hit && target->IsClicked();
bool down = captured && bev.Contains( context.lastState.GetPosition());
AColor::Bevel2(*dc, !down, bev, selected, hit);
#ifdef EXPERIMENTAL_THEMING
wxColour c = theTheme.Colour(clrTrackPanelText);
dc->SetBrush(c);
dc->SetPen(c);
#else
AColor::Dark(dc, selected);
#endif
wxString str = _("Select");
wxCoord textWidth;
wxCoord textHeight;
SetTrackInfoFont(dc);
dc->GetTextExtent(str, &textWidth, &textHeight);
dc->SetTextForeground( c );
dc->SetTextBackground( wxTRANSPARENT );
dc->DrawText(str, bev.x + 2 + (bev.width-textWidth)/2, bev.y + (bev.height - textHeight) / 2);
}
// Draw the sync-lock indicator if this track is in a sync-lock selected group.
if (syncLockSelected)
{
@ -2429,7 +2459,8 @@ void TrackInfo::GetMinimizeHorizontalBounds( const wxRect &rect, wxRect &dest )
// Width is rect.width less space on left for track select
// and on right for sync-lock icon.
dest.width = rect.width - (space + syncLockRect.width);
dest.width = kTrackInfoBtnSize;
// rect.width - (space + syncLockRect.width);
}
void TrackInfo::GetMinimizeRect(const wxRect & rect, wxRect &dest)
@ -2441,6 +2472,32 @@ void TrackInfo::GetMinimizeRect(const wxRect & rect, wxRect &dest)
dest.height = results.second;
}
void TrackInfo::GetSelectButtonHorizontalBounds( const wxRect &rect, wxRect &dest )
{
const int space = 0;// was 3.
dest.x = rect.x + space;
wxRect syncLockRect;
GetSyncLockHorizontalBounds( rect, syncLockRect );
wxRect minimizeRect;
GetMinimizeHorizontalBounds( rect, minimizeRect );
dest.x = dest.x + space + minimizeRect.width;
// Width is rect.width less space on left for track select
// and on right for sync-lock icon.
dest.width = rect.width - (space + syncLockRect.width) - (space + minimizeRect.width);
}
void TrackInfo::GetSelectButtonRect(const wxRect & rect, wxRect &dest)
{
GetSelectButtonHorizontalBounds( rect, dest );
auto results = CalcBottomItemY
( commonTrackTCPBottomLines, kItemMinimize, rect.height);
dest.y = rect.y + results.first;
dest.height = results.second;
}
void TrackInfo::GetSyncLockHorizontalBounds( const wxRect &rect, wxRect &dest )
{
dest.width = kTrackInfoBtnSize;

View File

@ -182,6 +182,9 @@ namespace TrackInfo
void GetMinimizeHorizontalBounds( const wxRect &rect, wxRect &dest );
void GetMinimizeRect(const wxRect & rect, wxRect &dest);
void GetSelectButtonHorizontalBounds( const wxRect &rect, wxRect &dest );
void GetSelectButtonRect(const wxRect & rect, wxRect &dest);
void GetSyncLockHorizontalBounds( const wxRect &rect, wxRect &dest );
void GetSyncLockIconRect(const wxRect & rect, wxRect &dest);

View File

@ -73,6 +73,56 @@ UIHandlePtr MinimizeButtonHandle::HitTest
return {};
}
////////////////////////////////////////////////////////////////////////////////
SelectButtonHandle::SelectButtonHandle
( const std::shared_ptr<Track> &pTrack, const wxRect &rect )
: ButtonHandle{ pTrack, rect }
{}
SelectButtonHandle::~SelectButtonHandle()
{
}
UIHandle::Result SelectButtonHandle::CommitChanges
(const wxMouseEvent &event, AudacityProject *pProject, wxWindow*)
{
using namespace RefreshCode;
auto pTrack = mpTrack.lock();
if (pTrack)
{
const bool unsafe = pProject->IsAudioActive();
SelectActions::DoListSelection(*pProject,
pTrack.get(), event.ShiftDown(), event.ControlDown(), !unsafe);
// return RefreshAll ;
}
return RefreshNone;
}
wxString SelectButtonHandle::Tip(const wxMouseState &) const
{
auto pTrack = GetTrack();
return pTrack->GetSelected() ? _("Unselect") : _("Select");
}
UIHandlePtr SelectButtonHandle::HitTest
(std::weak_ptr<SelectButtonHandle> &holder,
const wxMouseState &state, const wxRect &rect, TrackPanelCell *pCell)
{
wxRect buttonRect;
TrackInfo::GetSelectButtonRect(rect, buttonRect);
if (buttonRect.Contains(state.m_x, state.m_y)) {
auto pTrack = static_cast<CommonTrackPanelCell*>(pCell)->FindTrack();
auto result = std::make_shared<SelectButtonHandle>( pTrack, buttonRect );
result = AssignUIHandlePtr(holder, result);
return result;
}
else
return {};
}
////////////////////////////////////////////////////////////////////////////////
CloseButtonHandle::CloseButtonHandle

View File

@ -40,7 +40,31 @@ public:
};
////////////////////////////////////////////////////////////////////////////////
class SelectButtonHandle final : public ButtonHandle
{
SelectButtonHandle(const SelectButtonHandle&) = delete;
protected:
Result CommitChanges
(const wxMouseEvent &event, AudacityProject *pProject, wxWindow *pParent)
override;
wxString Tip(const wxMouseState &state) const override;
public:
explicit SelectButtonHandle
( const std::shared_ptr<Track> &pTrack, const wxRect &rect );
SelectButtonHandle &operator=(const SelectButtonHandle&) = default;
virtual ~SelectButtonHandle();
static UIHandlePtr HitTest
(std::weak_ptr<SelectButtonHandle> &holder,
const wxMouseState &state, const wxRect &rect, TrackPanelCell *pCell);
};
////////////////////////////////////////////////////////////////////////////////
class CloseButtonHandle final : public ButtonHandle
{
CloseButtonHandle(const CloseButtonHandle&) = delete;

View File

@ -68,6 +68,10 @@ std::vector<UIHandlePtr> TrackControls::HitTest
mMinimizeHandle, state, rect, this)))
results.push_back(result);
if (NULL != (result = SelectButtonHandle::HitTest(
mSelectButtonHandle, state, rect, this)))
results.push_back(result);
if (results.empty()) {
if (NULL != (result = TrackSelectHandle::HitAnywhere(
mSelectHandle, pTrack)))

View File

@ -20,6 +20,7 @@ class Track;
class CloseButtonHandle;
class MenuButtonHandle;
class MinimizeButtonHandle;
class SelectButtonHandle;
class TrackSelectHandle;
class TrackControls /* not final */ : public CommonTrackPanelCell
@ -60,6 +61,7 @@ protected:
std::weak_ptr<CloseButtonHandle> mCloseHandle;
std::weak_ptr<MenuButtonHandle> mMenuHandle;
std::weak_ptr<MinimizeButtonHandle> mMinimizeHandle;
std::weak_ptr<SelectButtonHandle> mSelectButtonHandle;
std::weak_ptr<TrackSelectHandle> mSelectHandle;
};