Audacity 3.2.0
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/ChannelView.h"
18#include "AllThemeResources.h"
19#include "AColor.h"
20#include "NoteTrack.h"
21#include "ViewInfo.h"
22#include "../../../../TrackArt.h"
23#include "../../../../TrackArtist.h"
24#include "../../../../TrackPanelMouseEvent.h"
25#include "../../../../TrackPanelDrawingContext.h"
26
27#include "WrapAllegro.h"
28
29#include "PendingTracks.h"
30#include "ProjectHistory.h"
31#include "SelectionState.h"
32#include "../../../../ProjectSettings.h"
33#include "../../../../RefreshCode.h"
34#include "SyncLock.h"
35#include "Theme.h"
36
38{
39public:
40 NoteTrackAffordanceHandle(const std::shared_ptr<Track>& track) : AffordanceHandle(track) { }
41
42 static UIHandlePtr HitAnywhere(std::weak_ptr<NoteTrackAffordanceHandle>& holder, const std::shared_ptr<Track>& pTrack)
43 {
44 return AssignUIHandlePtr(holder, std::make_shared<NoteTrackAffordanceHandle>(pTrack));
45 }
46
48 {
49 auto& viewInfo = ViewInfo::Get(*pProject);
50 const auto track = TrackList::Get(*pProject).Lock<Track>(GetTrack());
51
53
54 ProjectHistory::Get(*pProject).ModifyState(false);
55
57 }
58};
59
61 : CommonTrackCell{ pTrack }
62{
63
64}
65
66std::vector<UIHandlePtr> NoteTrackAffordanceControls::HitTest(const TrackPanelMouseState& state, const AudacityProject* pProject)
67{
68 std::vector<UIHandlePtr> results;
69
70 auto track = std::static_pointer_cast<NoteTrack>(FindTrack());
71 if (!track)
72 return {};
73 const auto &nt = static_cast<const NoteTrack&>(
75
76 const auto rect = state.rect;
77
78 auto& zoomInfo = ViewInfo::Get(*pProject);
79 auto left = zoomInfo.TimeToPosition(nt.GetStartTime(), rect.x);
80 auto right = zoomInfo.TimeToPosition(
81 nt.GetStartTime() + nt.GetSeq().get_real_dur(), rect.x);
82 auto headerRect = wxRect(left, rect.y, right - left, rect.height);
83
84 auto px = state.state.m_x;
85 auto py = state.state.m_y;
86
87 if (px >= headerRect.GetLeft() && px <= headerRect.GetRight() &&
88 py >= headerRect.GetTop() && py <= headerRect.GetBottom())
89 {
91 }
92
93 const auto& settings = ProjectSettings::Get(*pProject);
94 const auto currentTool = settings.GetTool();
95 if (currentTool == ToolCodes::multiTool || currentTool == ToolCodes::selectTool)
96 {
97 results.push_back(
99 mSelectHandle, state, pProject,
100 ChannelView::Get(*track).shared_from_this()
101 )
102 );
103 }
104
105 return results;
106}
107
108void NoteTrackAffordanceControls::Draw(TrackPanelDrawingContext& context, const wxRect& rect, unsigned iPass)
109{
110
111 if (iPass == TrackArtist::PassBackground) {
112 const auto artist = TrackArtist::Get(context);
113 const auto &pendingTracks = *artist->pPendingTracks;
114
115 const auto track = FindTrack();
116 if (!track)
117 return;
118 const auto &nt = static_cast<const NoteTrack&>(
119 pendingTracks.SubstitutePendingChangedTrack(*track));
120
123
124 const auto& zoomInfo = *artist->pZoomInfo;
125 auto left = zoomInfo.TimeToPosition(nt.GetStartTime(), rect.x);
126 auto right = zoomInfo.TimeToPosition(
127 nt.GetStartTime() + nt.GetSeq().get_real_dur(), rect.x);
128 auto clipRect = wxRect(left, rect.y, right - left + 1, rect.height);
129
130 auto px = context.lastState.m_x;
131 auto py = context.lastState.m_y;
132
133 auto selected = IsSelected();
134 auto highlight = selected ||
135 (px >= clipRect.GetLeft() && px <= clipRect.GetRight() &&
136 py >= clipRect.GetTop() && py <= clipRect.GetBottom());
137
138 {
139 wxDCClipper clipper(context.dc, rect);
140 context.dc.SetTextBackground(wxTransparentColor);
141 context.dc.SetTextForeground(theTheme.Colour(clrClipNameText));
142 context.dc.SetFont(wxFont(wxFontInfo()));
143 const auto titleRect = TrackArt::DrawClipAffordance(context.dc, clipRect, highlight, selected);
144 TrackArt::DrawClipTitle(context.dc, titleRect, nt.GetName());
145 }
146 }
147}
148
150{
151 if (auto handle = mAffordanceHandle.lock())
152 {
153 return handle->Clicked();
154 }
155 return false;
156}
std::shared_ptr< UIHandle > UIHandlePtr
Definition: CellularPanel.h:28
THEME_API Theme theTheme
Definition: Theme.cpp:82
static Settings & settings()
Definition: TrackInfo.cpp:51
std::shared_ptr< Subclass > AssignUIHandlePtr(std::weak_ptr< Subclass > &holder, const std::shared_ptr< Subclass > &pNew)
Definition: UIHandle.h:164
static wxBrush labelSelectedBrush
Definition: AColor.h:123
static wxBrush labelUnselectedBrush
Definition: AColor.h:122
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
static ChannelView & Get(Channel &channel)
std::shared_ptr< Track > FindTrack()
NoteTrackAffordanceControls(const std::shared_ptr< Track > &pTrack)
std::weak_ptr< NoteTrackAffordanceHandle > mAffordanceHandle
void Draw(TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass) override
std::weak_ptr< SelectHandle > mSelectHandle
std::vector< UIHandlePtr > HitTest(const TrackPanelMouseState &state, const AudacityProject *pProject) override
NoteTrackAffordanceHandle(const std::shared_ptr< Track > &track)
static UIHandlePtr HitAnywhere(std::weak_ptr< NoteTrackAffordanceHandle > &holder, const std::shared_ptr< Track > &pTrack)
UIHandle::Result SelectAt(const TrackPanelMouseEvent &event, AudacityProject *pProject) override
A Track that is used for Midi notes. (Somewhat old code).
Definition: NoteTrack.h:78
Track & SubstitutePendingChangedTrack(Track &track) const
static PendingTracks & Get(AudacityProject &project)
void ModifyState(bool bWantsAutoSave)
static ProjectHistory & Get(AudacityProject &project)
static ProjectSettings & Get(AudacityProject &project)
static UIHandlePtr HitTest(std::weak_ptr< SelectHandle > &holder, const TrackPanelMouseState &state, const AudacityProject *pProject, const std::shared_ptr< ChannelView > &pChannelView)
static void SelectTrackLength(ViewInfo &viewInfo, Track &track, bool syncLocked)
bool IsSyncLocked() const
Definition: SyncLock.cpp:44
static SyncLockState & Get(AudacityProject &project)
Definition: SyncLock.cpp:27
wxColour & Colour(int iIndex)
std::shared_ptr< Track > GetTrack() const
static TrackArtist * Get(TrackPanelDrawingContext &)
Definition: TrackArtist.cpp:81
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:110
std::shared_ptr< Subclass > Lock(const std::weak_ptr< Subclass > &wTrack)
Definition: Track.h:1079
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:314
unsigned Result
Definition: UIHandle.h:40
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235
AUDACITY_DLL_API void DrawBackgroundWithSelection(TrackPanelDrawingContext &context, const wxRect &rect, const Channel &channel, const wxBrush &selBrush, const wxBrush &unselBrush, bool useSelection=true, bool useBeatsAlternateColor=false)
Helper: draws background with selection rect.
Definition: TrackArt.cpp:648
AUDACITY_DLL_API bool DrawClipTitle(wxDC &dc, const wxRect &affordanceRect, const wxString &title)
Definition: TrackArt.cpp:289
AUDACITY_DLL_API wxRect DrawClipAffordance(wxDC &dc, const wxRect &clipRect, bool highlight=false, bool selected=false)
Definition: TrackArt.cpp:223