Audacity  3.0.3
NoteTrackAffordanceControls.cpp
Go to the documentation of this file.
1 /*!********************************************************************
2 *
3  Audacity: A Digital Audio Editor
4 
5  NoteTrackAffordanceControls.cpp
6 
7  Vitaly Sverchinsky
8 
9  **********************************************************************/
10 
12 
13 #include <wx/dc.h>
14 
15 #include "../../../ui/AffordanceHandle.h"
16 #include "../../../ui/SelectHandle.h"
17 #include "../../../ui/TrackView.h"
18 #include "AllThemeResources.h"
19 #include "AColor.h"
20 #include "../../../../NoteTrack.h"
21 #include "ViewInfo.h"
22 #include "../../../../TrackArtist.h"
23 #include "../../../../TrackPanelMouseEvent.h"
24 #include "../../../../TrackPanelDrawingContext.h"
25 
26 #include "../lib-src/header-substitutes/allegro.h"
27 
28 
29 #include "../../../../ProjectHistory.h"
30 #include "../../../../SelectionState.h"
31 #include "../../../../ProjectSettings.h"
32 #include "../../../../RefreshCode.h"
33 #include "Theme.h"
34 
36 {
37 public:
38  NoteTrackAffordanceHandle(const std::shared_ptr<Track>& track) : AffordanceHandle(track) { }
39 
40  static UIHandlePtr HitAnywhere(std::weak_ptr<NoteTrackAffordanceHandle>& holder, const std::shared_ptr<Track>& pTrack)
41  {
42  return AssignUIHandlePtr(holder, std::make_shared<NoteTrackAffordanceHandle>(pTrack));
43  }
44 
46  {
47  auto& viewInfo = ViewInfo::Get(*pProject);
48  const auto& settings = ProjectSettings::Get(*pProject);
49  const auto track = TrackList::Get(*pProject).Lock<Track>(GetTrack());
50 
51  SelectionState::SelectTrackLength(viewInfo, *track, settings.IsSyncLocked());
52 
53  ProjectHistory::Get(*pProject).ModifyState(false);
54 
56  }
57 };
58 
59 NoteTrackAffordanceControls::NoteTrackAffordanceControls(const std::shared_ptr<Track>& pTrack)
60  : CommonTrackCell(pTrack)
61 {
62 
63 }
64 
65 std::vector<UIHandlePtr> NoteTrackAffordanceControls::HitTest(const TrackPanelMouseState& state, const AudacityProject* pProject)
66 {
67  std::vector<UIHandlePtr> results;
68 
69  auto track = FindTrack();
70  const auto nt = std::static_pointer_cast<const NoteTrack>(track->SubstitutePendingChangedTrack());
71 
72  const auto rect = state.rect;
73 
74  auto& zoomInfo = ViewInfo::Get(*pProject);
75  auto left = zoomInfo.TimeToPosition(nt->GetOffset(), rect.x);
76  auto right = zoomInfo.TimeToPosition(nt->GetOffset() + nt->GetSeq().get_real_dur(), rect.x);
77  auto headerRect = wxRect(left, rect.y, right - left, rect.height);
78 
79  auto px = state.state.m_x;
80  auto py = state.state.m_y;
81 
82  if (px >= headerRect.GetLeft() && px <= headerRect.GetRight() &&
83  py >= headerRect.GetTop() && py <= headerRect.GetBottom())
84  {
86  }
87 
88  const auto& settings = ProjectSettings::Get(*pProject);
89  const auto currentTool = settings.GetTool();
90  if (currentTool == ToolCodes::multiTool || currentTool == ToolCodes::selectTool)
91  {
92  results.push_back(
94  mSelectHandle, state, pProject, std::static_pointer_cast<TrackView>(track->GetTrackView())
95  )
96  );
97  }
98 
99  return results;
100 }
101 
102 void NoteTrackAffordanceControls::Draw(TrackPanelDrawingContext& context, const wxRect& rect, unsigned iPass)
103 {
104  if (iPass == TrackArtist::PassBackground) {
105  const auto nt = std::static_pointer_cast<const NoteTrack>(FindTrack()->SubstitutePendingChangedTrack());
106  const auto artist = TrackArtist::Get(context);
107 
109 
110  const auto& zoomInfo = *artist->pZoomInfo;
111  auto left = zoomInfo.TimeToPosition(nt->GetOffset(), rect.x);
112  auto right = zoomInfo.TimeToPosition(nt->GetOffset() + nt->GetSeq().get_real_dur(), rect.x);
113  auto clipRect = wxRect(left, rect.y, right - left + 1, rect.height);
114 
115  auto px = context.lastState.m_x;
116  auto py = context.lastState.m_y;
117 
118  auto selected = IsSelected();
119  auto highlight = selected ||
120  (px >= clipRect.GetLeft() && px <= clipRect.GetRight() &&
121  py >= clipRect.GetTop() && py <= clipRect.GetBottom());
122 
123  {
124  wxDCClipper clipper(context.dc, rect);
125  context.dc.SetTextBackground(wxTransparentColor);
126  context.dc.SetTextForeground(theTheme.Colour(clrClipNameText));
127  context.dc.SetFont(wxFont(wxFontInfo()));
128  TrackArt::DrawClipAffordance(context.dc, clipRect, nt->GetName(), highlight, selected);
129  }
130  }
131 }
132 
134 {
135  if (auto handle = mAffordanceHandle.lock())
136  {
137  return handle->Clicked();
138  }
139  return false;
140 }
NoteTrackAffordanceControls::Draw
void Draw(TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass) override
Definition: NoteTrackAffordanceControls.cpp:102
ProjectHistory::ModifyState
void ModifyState(bool bWantsAutoSave)
Definition: ProjectHistory.cpp:124
ViewInfo::Get
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:241
AColor::labelUnselectedBrush
static wxBrush labelUnselectedBrush
Definition: AColor.h:110
RefreshCode::RefreshAll
@ RefreshAll
Definition: RefreshCode.h:26
ToolCodes::selectTool
@ selectTool
Definition: ProjectSettings.h:40
AllThemeResources.h
TrackList::Lock
std::shared_ptr< Subclass > Lock(const std::weak_ptr< Subclass > &wTrack)
Definition: Track.h:1542
CommonTrackPanelCell::FindTrack
std::shared_ptr< Track > FindTrack()
Definition: CommonTrackPanelCell.h:46
TrackPanelDrawingContext
Definition: TrackPanelDrawingContext.h:22
RefreshCode::Cancelled
@ Cancelled
Definition: RefreshCode.h:23
ProjectSettings::Get
static ProjectSettings & Get(AudacityProject &project)
Definition: ProjectSettings.cpp:44
SelectionState::SelectTrackLength
static void SelectTrackLength(ViewInfo &viewInfo, Track &track, bool syncLocked)
Definition: SelectionState.cpp:34
TrackPanelDrawingContext::dc
wxDC & dc
Definition: TrackPanelDrawingContext.h:23
NoteTrackAffordanceControls::mAffordanceHandle
std::weak_ptr< NoteTrackAffordanceHandle > mAffordanceHandle
Definition: NoteTrackAffordanceControls.h:21
NoteTrackAffordanceControls::HitTest
std::vector< UIHandlePtr > HitTest(const TrackPanelMouseState &state, const AudacityProject *pProject) override
Definition: NoteTrackAffordanceControls.cpp:65
TrackPanelMouseState::rect
const wxRect & rect
Definition: TrackPanelMouseEvent.h:39
NoteTrackAffordanceHandle::SelectAt
UIHandle::Result SelectAt(const TrackPanelMouseEvent &event, AudacityProject *pProject) override
Definition: NoteTrackAffordanceControls.cpp:45
AffordanceHandle
Definition: AffordanceHandle.h:16
NoteTrackAffordanceControls::NoteTrackAffordanceControls
NoteTrackAffordanceControls(const std::shared_ptr< Track > &pTrack)
Definition: NoteTrackAffordanceControls.cpp:59
TrackArt::DrawClipAffordance
AUDACITY_DLL_API void DrawClipAffordance(wxDC &dc, const wxRect &affordanceRect, const wxString &title, bool highlight=false, bool selected=false)
Definition: TrackArtist.cpp:302
TrackArtist::Get
static TrackArtist * Get(TrackPanelDrawingContext &)
Definition: TrackArtist.cpp:79
ToolCodes::multiTool
@ multiTool
Definition: ProjectSettings.h:44
UIHandle::Result
unsigned Result
Definition: UIHandle.h:38
Theme.h
TrackPanelDrawingContext::lastState
wxMouseState lastState
Definition: TrackPanelDrawingContext.h:25
AColor::labelSelectedBrush
static wxBrush labelSelectedBrush
Definition: AColor.h:111
UIHandlePtr
std::shared_ptr< UIHandle > UIHandlePtr
Definition: CellularPanel.h:28
NoteTrackAffordanceControls::IsSelected
bool IsSelected() const
Definition: NoteTrackAffordanceControls.cpp:133
ViewInfo.h
theTheme
THEME_API Theme theTheme
Definition: Theme.cpp:79
NoteTrackAffordanceHandle
Definition: NoteTrackAffordanceControls.cpp:36
TrackArt::DrawBackgroundWithSelection
AUDACITY_DLL_API void DrawBackgroundWithSelection(TrackPanelDrawingContext &context, const wxRect &rect, const Track *track, const wxBrush &selBrush, const wxBrush &unselBrush, bool useSelection=true)
Definition: TrackArtist.cpp:528
TrackList::Get
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:506
Track
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:239
SelectHandle::HitTest
static UIHandlePtr HitTest(std::weak_ptr< SelectHandle > &holder, const TrackPanelMouseState &state, const AudacityProject *pProject, const std::shared_ptr< TrackView > &pTrackView)
Definition: SelectHandle.cpp:362
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:92
NoteTrackAffordanceHandle::NoteTrackAffordanceHandle
NoteTrackAffordanceHandle(const std::shared_ptr< Track > &track)
Definition: NoteTrackAffordanceControls.cpp:38
TrackPanelMouseEvent
Definition: TrackPanelMouseEvent.h:46
TrackPanelMouseState
Definition: TrackPanelMouseEvent.h:28
TimeShiftHandle::GetTrack
std::shared_ptr< Track > GetTrack() const
Definition: TimeShiftHandle.cpp:37
NoteTrackAffordanceControls.h
ThemeBase::Colour
wxColour & Colour(int iIndex)
Definition: Theme.cpp:1189
NoteTrackAffordanceHandle::HitAnywhere
static UIHandlePtr HitAnywhere(std::weak_ptr< NoteTrackAffordanceHandle > &holder, const std::shared_ptr< Track > &pTrack)
Definition: NoteTrackAffordanceControls.cpp:40
AssignUIHandlePtr
std::shared_ptr< Subclass > AssignUIHandlePtr(std::weak_ptr< Subclass > &holder, const std::shared_ptr< Subclass > &pNew)
Definition: UIHandle.h:151
settings
static Settings & settings()
Definition: TrackInfo.cpp:86
TrackArtist::PassBackground
@ PassBackground
Definition: TrackArtist.h:86
AColor.h
TrackPanelMouseState::state
wxMouseState & state
Definition: TrackPanelMouseEvent.h:38
ProjectHistory::Get
static ProjectHistory & Get(AudacityProject &project)
Definition: ProjectHistory.cpp:26
CommonTrackCell
Definition: CommonTrackPanelCell.h:99
NoteTrackAffordanceControls::mSelectHandle
std::weak_ptr< SelectHandle > mSelectHandle
Definition: NoteTrackAffordanceControls.h:22