Audacity  2.2.2
Public Member Functions | Private Member Functions | Private Attributes | List of all members
EditCursorOverlay Class Referencefinal

#include <EditCursorOverlay.h>

Inheritance diagram for EditCursorOverlay:
Overlay

Public Member Functions

 EditCursorOverlay (AudacityProject *project, bool isMaster=true)
 
virtual ~EditCursorOverlay ()
 
- Public Member Functions inherited from Overlay
virtual ~Overlay ()=0
 
std::pair< wxRect, bool > GetRectangle (wxSize size)
 
virtual void Erase (wxDC &dc, wxDC &src)
 

Private Member Functions

std::pair< wxRect, bool > DoGetRectangle (wxSize size) override
 
void Draw (OverlayPanel &panel, wxDC &dc) override
 

Private Attributes

AudacityProjectmProject
 
bool mIsMaster
 
std::unique_ptr
< EditCursorOverlay
mPartner
 
int mLastCursorX
 
double mCursorTime
 
int mNewCursorX
 

Detailed Description

Definition at line 19 of file EditCursorOverlay.h.

Constructor & Destructor Documentation

EditCursorOverlay::EditCursorOverlay ( AudacityProject project,
bool  isMaster = true 
)

Definition at line 33 of file EditCursorOverlay.cpp.

34  : mProject(project)
35  , mIsMaster(isMaster)
36  , mLastCursorX(-1)
37  , mCursorTime(-1)
38  , mNewCursorX(-1)
39 {
40 }
AudacityProject * mProject
EditCursorOverlay::~EditCursorOverlay ( )
virtual

Definition at line 42 of file EditCursorOverlay.cpp.

References AudacityProject::GetRulerPanel(), mIsMaster, mPartner, mProject, and OverlayPanel::RemoveOverlay().

43 {
44  if (mIsMaster && mPartner) {
45  auto ruler = mProject->GetRulerPanel();
46  if (ruler)
47  ruler->RemoveOverlay(mPartner.get());
48  }
49 }
bool RemoveOverlay(Overlay *pOverlay)
AudacityProject * mProject
AdornedRulerPanel * GetRulerPanel()
Definition: Project.cpp:1432
std::unique_ptr< EditCursorOverlay > mPartner

Member Function Documentation

std::pair< wxRect, bool > EditCursorOverlay::DoGetRectangle ( wxSize  size)
overrideprivatevirtual

Implements Overlay.

Definition at line 51 of file EditCursorOverlay.cpp.

References TrackPanel::GetLeftOffset(), AudacityProject::GetSelection(), AudacityProject::GetTrackPanel(), AudacityProject::GetZoomInfo(), SelectedRegion::isPoint(), mCursorTime, mLastCursorX, mNewCursorX, mProject, SelectedRegion::t0(), and ZoomInfo::TimeToPosition().

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 }
double t0() const
bool isPoint() const
Defines a selected portion of a project.
AudacityProject * mProject
const SelectedRegion & GetSelection() const
Definition: Project.h:202
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:206
TrackPanel * GetTrackPanel()
Definition: Project.h:307
int GetLeftOffset() const
Definition: TrackPanel.h:287
void EditCursorOverlay::Draw ( OverlayPanel panel,
wxDC &  dc 
)
overrideprivatevirtual

Implements Overlay.

Definition at line 74 of file EditCursorOverlay.cpp.

References AColor::CursorColor(), TrackPanel::GetAx(), AudacityProject::GetRulerPanel(), AudacityProject::GetScreenEndTime(), Track::GetSelected(), AudacityProject::GetTrackPanel(), AudacityProject::GetZoomInfo(), ZoomInfo::h, TrackPanelAx::IsFocused(), AColor::Line(), mCursorTime, mIsMaster, mLastCursorX, mNewCursorX, mPartner, and mProject.

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 }
static void CursorColor(wxDC *dc)
Definition: AColor.cpp:358
bool GetSelected() const
Definition: Track.h:275
double h
Definition: ViewInfo.h:47
bool IsFocused(Track *track)
AudacityProject * mProject
AdornedRulerPanel * GetRulerPanel()
Definition: Project.cpp:1432
Fundamental data object of Audacity, placed in the TrackPanel. Classes derived form it include the Wa...
Definition: Track.h:101
TrackPanelAx & GetAx()
Definition: TrackPanel.h:499
const ZoomInfo & GetZoomInfo() const
Definition: Project.h:206
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:6715
TrackPanel * GetTrackPanel()
Definition: Project.h:307

Member Data Documentation

double EditCursorOverlay::mCursorTime
private

Definition at line 34 of file EditCursorOverlay.h.

Referenced by DoGetRectangle(), and Draw().

bool EditCursorOverlay::mIsMaster
private

Definition at line 30 of file EditCursorOverlay.h.

Referenced by Draw(), and ~EditCursorOverlay().

int EditCursorOverlay::mLastCursorX
private

Definition at line 33 of file EditCursorOverlay.h.

Referenced by DoGetRectangle(), and Draw().

int EditCursorOverlay::mNewCursorX
private

Definition at line 35 of file EditCursorOverlay.h.

Referenced by DoGetRectangle(), and Draw().

std::unique_ptr<EditCursorOverlay> EditCursorOverlay::mPartner
private

Definition at line 31 of file EditCursorOverlay.h.

Referenced by Draw(), and ~EditCursorOverlay().

AudacityProject* EditCursorOverlay::mProject
private

Definition at line 29 of file EditCursorOverlay.h.

Referenced by DoGetRectangle(), Draw(), and ~EditCursorOverlay().


The documentation for this class was generated from the following files: