Audacity  3.0.3
EditCursorOverlay.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3 Audacity: A Digital Audio Editor
4 
5 EditCursorOverlay.cpp
6 
7 Paul Licameli split from TrackPanel.cpp
8 
9 **********************************************************************/
10 
11 
12 #include "EditCursorOverlay.h"
13 
14 #include "TrackView.h"
15 #include "AColor.h"
16 #include "../../AdornedRulerPanel.h"
17 #include "Project.h"
18 #include "../../ProjectWindows.h"
19 #include "../../Track.h" //
20 #include "../../TrackPanelAx.h"
21 #include "../../TrackPanel.h"
22 #include "ViewInfo.h"
23 
24 #include <wx/dc.h>
25 
26 namespace {
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 
56 std::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 
80 void EditCursorOverlay::Draw(OverlayPanel &panel, wxDC &dc)
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.h,
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 pTrackView = dynamic_cast<TrackView*>(&cell);
111  if (!pTrackView)
112  return;
113  const auto pTrack = pTrackView->FindTrack();
114  if (pTrack->GetSelected() ||
115  TrackFocus::Get( *mProject ).IsFocused( pTrack.get() ))
116  {
117  // AColor::Line includes both endpoints so use GetBottom()
118  AColor::Line(dc, mLastCursorX, rect.GetTop(), mLastCursorX, rect.GetBottom());
119  // ^^^ The whole point of this routine.
120 
121  }
122  } );
123  }
124  else if (auto ruler = dynamic_cast<AdornedRulerPanel*>(&panel)) {
125  wxASSERT(!mIsMaster);
126  dc.SetPen(*wxBLACK_PEN);
127  // AColor::Line includes both endpoints so use GetBottom()
128  auto rect = ruler->GetInnerRect();
129  AColor::Line(dc, mLastCursorX, rect.GetTop(), mLastCursorX, rect.GetBottom());
130  }
131  else
132  wxASSERT(false);*/
133  if (auto ruler = dynamic_cast<AdornedRulerPanel*>(&panel)) {
134  wxASSERT(!mIsMaster);
135  dc.SetPen(*wxBLACK_PEN);
136  // AColor::Line includes both endpoints so use GetBottom()
137  auto rect = ruler->GetInnerRect();
138  AColor::Line(dc, mLastCursorX, rect.GetTop(), mLastCursorX, rect.GetBottom());
139  }
140 }
size
size_t size
Definition: ffmpeg-2.3.6-single-header.h:412
ViewInfo::Get
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:241
AdornedRulerPanel
This is an Audacity Specific ruler panel which additionally has border, selection markers,...
Definition: AdornedRulerPanel.h:27
TrackView.h
EditCursorOverlay::Draw
void Draw(OverlayPanel &panel, wxDC &dc) override
Definition: EditCursorOverlay.cpp:80
Project.h
AColor::Line
static void Line(wxDC &dc, wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
Definition: AColor.cpp:109
EditCursorOverlay::mNewCursorX
int mNewCursorX
Definition: EditCursorOverlay.h:39
TrackPanel::Get
static TrackPanel & Get(AudacityProject &project)
Definition: TrackPanel.cpp:227
EditCursorOverlay::EditCursorOverlay
EditCursorOverlay(AudacityProject *project, bool isMaster=true)
Definition: EditCursorOverlay.cpp:42
anonymous_namespace{TimeTrackVRulerControls.cpp}::ruler
Ruler & ruler()
Definition: TimeTrackVRulerControls.cpp:34
anonymous_namespace{EditCursorOverlay.cpp}::between_incexc
bool between_incexc(LOW l, MID m, HIGH h)
Definition: EditCursorOverlay.cpp:28
ClientData::Site::RegisteredFactory
Client code makes static instance from a factory of attachments; passes it to Get or Find as a retrie...
Definition: ClientData.h:266
EditCursorOverlay::SequenceNumber
unsigned SequenceNumber() const override
This number determines an ordering of overlays, so that those with higher numbers overpaint those wit...
Definition: EditCursorOverlay.cpp:51
AdornedRulerPanel::Get
static AdornedRulerPanel & Get(AudacityProject &project)
Definition: AdornedRulerPanel.cpp:899
EditCursorOverlay::mIsMaster
bool mIsMaster
Definition: EditCursorOverlay.h:34
EditCursorOverlay::mLastCursorX
int mLastCursorX
Definition: EditCursorOverlay.h:37
EditCursorOverlay::mPartner
std::shared_ptr< EditCursorOverlay > mPartner
Definition: EditCursorOverlay.h:35
EditCursorOverlay::mCursorTime
double mCursorTime
Definition: EditCursorOverlay.h:38
ViewInfo.h
EditCursorOverlay::mProject
AudacityProject * mProject
Definition: EditCursorOverlay.h:33
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
EditCursorOverlay.h
OverlayPanel
Definition: OverlayPanel.h:18
OverlayPanel::AddOverlay
void AddOverlay(const std::weak_ptr< Overlay > &pOverlay)
Definition: OverlayPanel.cpp:24
sOverlayKey
static const AudacityProject::AttachedObjects::RegisteredFactory sOverlayKey
Definition: EditCursorOverlay.cpp:34
AColor.h
EditCursorOverlay::DoGetRectangle
std::pair< wxRect, bool > DoGetRectangle(wxSize size) override
Definition: EditCursorOverlay.cpp:56