Audacity 3.2.0
EditCursorOverlay.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3Audacity: A Digital Audio Editor
4
5EditCursorOverlay.cpp
6
7Paul Licameli split from TrackPanel.cpp
8
9**********************************************************************/
10
11
12#include "EditCursorOverlay.h"
13
14#include "ChannelView.h"
15#include "AColor.h"
16#include "../../AdornedRulerPanel.h"
17#include "Project.h"
18#include "../../ProjectWindows.h"
19#include "Track.h" //
20#include "TrackFocus.h"
21#include "../../TrackPanel.h"
22#include "ViewInfo.h"
23
24#include <wx/dc.h>
25
26namespace {
27 template < class LOW, class MID, class HIGH >
28 bool between_incexc(LOW l, MID m, HIGH h)
29 {
30 return (m >= l && m < h);
31 }
32}
33
35 []( AudacityProject &parent ){
36 auto result = std::make_shared< EditCursorOverlay >( &parent );
37 TrackPanel::Get( parent ).AddOverlay( result );
38 return result;
39 }
40};
41
43 : mProject(project)
44 , mIsMaster(isMaster)
45 , mLastCursorX(-1)
46 , mCursorTime(-1)
47 , mNewCursorX(-1)
48{
49}
50
52{
53 return 20;
54}
55
56std::pair<wxRect, bool> EditCursorOverlay::DoGetRectangle(wxSize size)
57{
58 const auto &viewInfo = ViewInfo::Get( *mProject );
59 const auto &selection = viewInfo.selectedRegion;
60 if (!selection.isPoint()) {
61 mCursorTime = -1.0;
62 mNewCursorX = -1;
63 }
64 else {
65 mCursorTime = selection.t0();
66 mNewCursorX = viewInfo.TimeToPosition(
67 mCursorTime, viewInfo.GetLeftOffset());
68 }
69
70 // Excessive height in case of the ruler, but it matters little.
71 return std::make_pair(
72 mLastCursorX == -1
73 ? wxRect()
74 : wxRect(mLastCursorX, 0, 1, size.GetHeight()),
76 );
77}
78
79
81{
82 if (mIsMaster && !mPartner) {
84 mPartner = std::make_shared<EditCursorOverlay>(mProject, false);
85 ruler.AddOverlay( mPartner );
86 }
87
89 if (mLastCursorX == -1)
90 return;
91
92 const auto &viewInfo = ViewInfo::Get( *mProject );
93
94 const bool
95 onScreen = between_incexc(viewInfo.hpos,
97 viewInfo.GetScreenEndTime());
98
99 if (!onScreen)
100 return;
101
102 auto &trackPanel = TrackPanel::Get( *mProject );
103 //NOTE: point selection cursor drawing over tracks moved to TrackPanel.cpp(see also TrackArt::DrawCursor)
104 /*if (auto tp = dynamic_cast<TrackPanel*>(&panel)) {
105 wxASSERT(mIsMaster);
106 AColor::CursorColor(&dc);
107
108 // Draw cursor in all selected tracks
109 tp->VisitCells( [&]( const wxRect &rect, TrackPanelCell &cell ) {
110 const auto pChannelView = dynamic_cast<ChannelView*>(&cell);
111 if (!pChannelView)
112 return;
113 const auto pChannel = pChannelView->FindChannel();
114 const auto pTrack =
115 dynamic_cast<Track *>(&pChannel->GetChannelGroup());
116 if (pChannel && (pTrack->GetSelected() ||
117 TrackFocus::Get( *mProject ).IsFocused(pTrack)))
118 {
119 // AColor::Line includes both endpoints so use GetBottom()
120 AColor::Line(dc, mLastCursorX, rect.GetTop(), mLastCursorX, rect.GetBottom());
121 // ^^^ The whole point of this routine.
122
123 }
124 } );
125 }
126 else if (auto ruler = dynamic_cast<AdornedRulerPanel*>(&panel)) {
127 wxASSERT(!mIsMaster);
128 dc.SetPen(*wxBLACK_PEN);
129 // AColor::Line includes both endpoints so use GetBottom()
130 auto rect = ruler->GetInnerRect();
131 AColor::Line(dc, mLastCursorX, rect.GetTop(), mLastCursorX, rect.GetBottom());
132 }
133 else
134 wxASSERT(false);*/
135 if (auto ruler = dynamic_cast<AdornedRulerPanel*>(&panel)) {
136 wxASSERT(!mIsMaster);
137 dc.SetPen(*wxBLACK_PEN);
138 // AColor::Line includes both endpoints so use GetBottom()
139 auto rect = ruler->GetInnerRect();
140 AColor::Line(dc, mLastCursorX, rect.GetTop(), mLastCursorX, rect.GetBottom());
141 }
142}
static const AudacityProject::AttachedObjects::RegisteredFactory sOverlayKey
const auto project
declares abstract base class Track, TrackList, and iterators over TrackList
static void Line(wxDC &dc, wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
Definition: AColor.cpp:194
This is an Audacity Specific ruler panel which additionally has border, selection markers,...
static AdornedRulerPanel & Get(AudacityProject &project)
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
Client code makes static instance from a factory of attachments; passes it to Get or Find as a retrie...
Definition: ClientData.h:275
std::shared_ptr< EditCursorOverlay > mPartner
unsigned SequenceNumber() const override
This number determines an ordering of overlays, so that those with higher numbers overpaint those wit...
void Draw(OverlayPanel &panel, wxDC &dc) override
EditCursorOverlay(AudacityProject *project, bool isMaster=true)
std::pair< wxRect, bool > DoGetRectangle(wxSize size) override
AudacityProject * mProject
void AddOverlay(const std::weak_ptr< Overlay > &pOverlay)
static TrackPanel & Get(AudacityProject &project)
Definition: TrackPanel.cpp:234
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235