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/TrackView.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 "../lib-src/header-substitutes/allegro.h"
28
29
30#include "ProjectHistory.h"
31#include "../../../../SelectionState.h"
32#include "../../../../ProjectSettings.h"
33#include "../../../../RefreshCode.h"
34#include "Theme.h"
35
37{
38public:
39 NoteTrackAffordanceHandle(const std::shared_ptr<Track>& track) : AffordanceHandle(track) { }
40
41 static UIHandlePtr HitAnywhere(std::weak_ptr<NoteTrackAffordanceHandle>& holder, const std::shared_ptr<Track>& pTrack)
42 {
43 return AssignUIHandlePtr(holder, std::make_shared<NoteTrackAffordanceHandle>(pTrack));
44 }
45
47 {
48 auto& viewInfo = ViewInfo::Get(*pProject);
49 const auto& settings = ProjectSettings::Get(*pProject);
50 const auto track = TrackList::Get(*pProject).Lock<Track>(GetTrack());
51
52 SelectionState::SelectTrackLength(viewInfo, *track, settings.IsSyncLocked());
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 = FindTrack();
71 const auto nt = std::static_pointer_cast<const NoteTrack>(track->SubstitutePendingChangedTrack());
72
73 const auto rect = state.rect;
74
75 auto& zoomInfo = ViewInfo::Get(*pProject);
76 auto left = zoomInfo.TimeToPosition(nt->GetOffset(), rect.x);
77 auto right = zoomInfo.TimeToPosition(nt->GetOffset() + nt->GetSeq().get_real_dur(), rect.x);
78 auto headerRect = wxRect(left, rect.y, right - left, rect.height);
79
80 auto px = state.state.m_x;
81 auto py = state.state.m_y;
82
83 if (px >= headerRect.GetLeft() && px <= headerRect.GetRight() &&
84 py >= headerRect.GetTop() && py <= headerRect.GetBottom())
85 {
87 }
88
89 const auto& settings = ProjectSettings::Get(*pProject);
90 const auto currentTool = settings.GetTool();
91 if (currentTool == ToolCodes::multiTool || currentTool == ToolCodes::selectTool)
92 {
93 results.push_back(
95 mSelectHandle, state, pProject,
96 TrackView::Get(*track).shared_from_this()
97 )
98 );
99 }
100
101 return results;
102}
103
104void NoteTrackAffordanceControls::Draw(TrackPanelDrawingContext& context, const wxRect& rect, unsigned iPass)
105{
106 if (iPass == TrackArtist::PassBackground) {
107 const auto nt = std::static_pointer_cast<const NoteTrack>(FindTrack()->SubstitutePendingChangedTrack());
108 const auto artist = TrackArtist::Get(context);
109
111
112 const auto& zoomInfo = *artist->pZoomInfo;
113 auto left = zoomInfo.TimeToPosition(nt->GetOffset(), rect.x);
114 auto right = zoomInfo.TimeToPosition(nt->GetOffset() + nt->GetSeq().get_real_dur(), rect.x);
115 auto clipRect = wxRect(left, rect.y, right - left + 1, rect.height);
116
117 auto px = context.lastState.m_x;
118 auto py = context.lastState.m_y;
119
120 auto selected = IsSelected();
121 auto highlight = selected ||
122 (px >= clipRect.GetLeft() && px <= clipRect.GetRight() &&
123 py >= clipRect.GetTop() && py <= clipRect.GetBottom());
124
125 {
126 wxDCClipper clipper(context.dc, rect);
127 context.dc.SetTextBackground(wxTransparentColor);
128 context.dc.SetTextForeground(theTheme.Colour(clrClipNameText));
129 context.dc.SetFont(wxFont(wxFontInfo()));
130 TrackArt::DrawClipAffordance(context.dc, clipRect, nt->GetName(), highlight, selected);
131 }
132 }
133}
134
136{
137 if (auto handle = mAffordanceHandle.lock())
138 {
139 return handle->Clicked();
140 }
141 return false;
142}
std::shared_ptr< UIHandle > UIHandlePtr
Definition: CellularPanel.h:28
THEME_API Theme theTheme
Definition: Theme.cpp:82
static Settings & settings()
Definition: TrackInfo.cpp:87
std::shared_ptr< Subclass > AssignUIHandlePtr(std::weak_ptr< Subclass > &holder, const std::shared_ptr< Subclass > &pNew)
Definition: UIHandle.h:151
static wxBrush labelSelectedBrush
Definition: AColor.h:122
static wxBrush labelUnselectedBrush
Definition: AColor.h:121
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:89
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
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< TrackView > &pTrackView)
static void SelectTrackLength(ViewInfo &viewInfo, Track &track, bool syncLocked)
wxColour & Colour(int iIndex)
std::shared_ptr< Track > GetTrack() const
static TrackArtist * Get(TrackPanelDrawingContext &)
Definition: TrackArtist.cpp:69
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:225
std::shared_ptr< Subclass > Lock(const std::weak_ptr< Subclass > &wTrack)
Definition: Track.h:1603
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:486
static TrackView & Get(Track &)
Definition: TrackView.cpp:69
unsigned Result
Definition: UIHandle.h:38
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235
AUDACITY_DLL_API void DrawBackgroundWithSelection(TrackPanelDrawingContext &context, const wxRect &rect, const Track *track, const wxBrush &selBrush, const wxBrush &unselBrush, bool useSelection=true)
Definition: TrackArt.cpp:419
AUDACITY_DLL_API wxRect DrawClipAffordance(wxDC &dc, const wxRect &affordanceRect, const wxString &title, bool highlight=false, bool selected=false)
Definition: TrackArt.cpp:191