Audacity  2.2.2
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 #include "../../Audacity.h"
12 #include "EditCursorOverlay.h"
13 #include "../../Experimental.h"
14 
15 #include "../../AColor.h"
16 #include "../../widgets/Ruler.h"
17 #include "../../Project.h"
18 #include "../../TrackPanelCell.h"
19 #include "../../TrackPanelCellIterator.h"
20 #include "../../TrackPanelAx.h"
21 #include "../../ViewInfo.h"
22 
23 #include <wx/dc.h>
24 
25 namespace {
26  template < class LOW, class MID, class HIGH >
27  bool between_incexc(LOW l, MID m, HIGH h)
28  {
29  return (m >= l && m < h);
30  }
31 }
32 
34  : mProject(project)
35  , mIsMaster(isMaster)
36  , mLastCursorX(-1)
37  , mCursorTime(-1)
38  , mNewCursorX(-1)
39 {
40 }
41 
43 {
44  if (mIsMaster && mPartner) {
45  auto ruler = mProject->GetRulerPanel();
46  if (ruler)
47  ruler->RemoveOverlay(mPartner.get());
48  }
49 }
50 
51 std::pair<wxRect, bool> EditCursorOverlay::DoGetRectangle(wxSize size)
52 {
53  const SelectedRegion &selection = mProject->GetSelection();
54  if (!selection.isPoint()) {
55  mCursorTime = -1.0;
56  mNewCursorX = -1;
57  }
58  else {
59  mCursorTime = selection.t0();
62  }
63 
64  // Excessive height in case of the ruler, but it matters little.
65  return std::make_pair(
66  mLastCursorX == -1
67  ? wxRect()
68  : wxRect(mLastCursorX, 0, 1, size.GetHeight()),
70  );
71 }
72 
73 
74 void EditCursorOverlay::Draw(OverlayPanel &panel, wxDC &dc)
75 {
76  if (mIsMaster && !mPartner) {
77  auto ruler = mProject->GetRulerPanel();
78  if (ruler) {
79  mPartner = std::make_unique<EditCursorOverlay>(mProject, false);
80  ruler->AddOverlay(mPartner.get());
81  }
82  }
83 
85  if (mLastCursorX == -1)
86  return;
87 
88  const ZoomInfo &viewInfo = mProject->GetZoomInfo();
89 
90  const bool
91  onScreen = between_incexc(viewInfo.h,
94 
95  if (!onScreen)
96  return;
97 
98  if (auto tp = dynamic_cast<TrackPanel*>(&panel)) {
99  wxASSERT(mIsMaster);
100  AColor::CursorColor(&dc);
101 
102  // Draw cursor in all selected tracks
103  for ( const auto &data : tp->Cells() )
104  {
105  Track *const pTrack = dynamic_cast<Track*>(data.first.get());
106  if (!pTrack)
107  continue;
108  if (pTrack->GetSelected() ||
109  mProject->GetTrackPanel()->GetAx().IsFocused(pTrack))
110  {
111  const wxRect &rect = data.second;
112  // AColor::Line includes both endpoints so use GetBottom()
113  AColor::Line(dc, mLastCursorX, rect.GetTop(), mLastCursorX, rect.GetBottom());
114  // ^^^ The whole point of this routine.
115 
116  }
117  }
118  }
119  else if (auto ruler = dynamic_cast<AdornedRulerPanel*>(&panel)) {
120  wxASSERT(!mIsMaster);
121  dc.SetPen(*wxBLACK_PEN);
122  // AColor::Line includes both endpoints so use GetBottom()
123  auto rect = ruler->GetInnerRect();
124  AColor::Line(dc, mLastCursorX, rect.GetTop(), mLastCursorX, rect.GetBottom());
125  }
126  else
127  wxASSERT(false);
128 }
double t0() const
bool isPoint() const
static void CursorColor(wxDC *dc)
Definition: AColor.cpp:358
bool GetSelected() const
Definition: Track.h:268
bool RemoveOverlay(Overlay *pOverlay)
double h
Definition: ViewInfo.h:47
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:158
bool IsFocused(Track *track)
void Draw(OverlayPanel &panel, wxDC &dc) override
Defines a selected portion of a project.
AudacityProject * mProject
AdornedRulerPanel * GetRulerPanel()
Definition: Project.cpp:1408
const SelectedRegion & GetSelection() const
Definition: Project.h:184
std::pair< wxRect, bool > DoGetRectangle(wxSize size) override
Fundamental data object of Audacity, placed in the TrackPanel. Classes derived form it include the Wa...
Definition: Track.h:94
TrackPanelAx & GetAx()
Definition: TrackPanel.h:499
wxInt64 TimeToPosition(double time, wxInt64 origin=0, bool ignoreFisheye=false) const
STM: Converts a project time to screen x position.
Definition: ViewInfo.cpp:59
const ZoomInfo & GetZoomInfo() const
Definition: Project.h:188
static void Line(wxDC &dc, wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
Definition: AColor.cpp:122
std::unique_ptr< EditCursorOverlay > mPartner
double GetScreenEndTime() const
Definition: Menus.cpp:6443
TrackPanel * GetTrackPanel()
Definition: Project.h:289
int GetLeftOffset() const
Definition: TrackPanel.h:287
EditCursorOverlay(AudacityProject *project, bool isMaster=true)