1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-11-14 17:14:07 +01:00

Reimplement the cursor mark in the ruler as an overlay

This commit is contained in:
Paul Licameli
2016-05-08 16:44:45 -04:00
parent 3466e91ed1
commit d8e42b0af4
5 changed files with 61 additions and 49 deletions

View File

@@ -15,7 +15,6 @@ Paul Licameli split from TrackPanel.cpp
#include "../../AColor.h"
#include "../../widgets/Ruler.h"
#include "../../Project.h"
//#include "../../TrackPanel.h"
#include "../../TrackPanelCell.h"
#include "../../TrackPanelCellIterator.h"
#include "../../TrackPanelAx.h"
@@ -31,8 +30,9 @@ namespace {
}
}
EditCursorOverlay::EditCursorOverlay(AudacityProject *project)
EditCursorOverlay::EditCursorOverlay(AudacityProject *project, bool isMaster)
: mProject(project)
, mIsMaster(isMaster)
, mLastCursorX(-1)
, mCursorTime(-1)
, mNewCursorX(-1)
@@ -41,6 +41,11 @@ EditCursorOverlay::EditCursorOverlay(AudacityProject *project)
EditCursorOverlay::~EditCursorOverlay()
{
if (mIsMaster && mPartner) {
auto ruler = mProject->GetRulerPanel();
if (ruler)
ruler->RemoveOverlay(mPartner.get());
}
}
std::pair<wxRect, bool> EditCursorOverlay::DoGetRectangle(wxSize size)
@@ -56,6 +61,7 @@ std::pair<wxRect, bool> EditCursorOverlay::DoGetRectangle(wxSize size)
(mCursorTime, mProject->GetTrackPanel()->GetLeftOffset());
}
// Excessive height in case of the ruler, but it matters little.
return std::make_pair(
mLastCursorX == -1
? wxRect()
@@ -67,9 +73,13 @@ std::pair<wxRect, bool> EditCursorOverlay::DoGetRectangle(wxSize size)
void EditCursorOverlay::Draw(OverlayPanel &panel, wxDC &dc)
{
TrackPanel &tp = static_cast<TrackPanel&>(panel);
TrackPanelCellIterator begin(&tp, true);
TrackPanelCellIterator end(&tp, false);
if (mIsMaster && !mPartner) {
auto ruler = mProject->GetRulerPanel();
if (ruler) {
mPartner = std::make_unique<EditCursorOverlay>(mProject, false);
ruler->AddOverlay(mPartner.get());
}
}
mLastCursorX = mNewCursorX;
if (mLastCursorX == -1)
@@ -78,44 +88,56 @@ void EditCursorOverlay::Draw(OverlayPanel &panel, wxDC &dc)
const ZoomInfo &viewInfo = mProject->GetZoomInfo();
const bool
onScreen = between_incexc(viewInfo.h,
mCursorTime,
mProject->GetScreenEndTime());
onScreen = between_incexc(viewInfo.h,
mCursorTime,
mProject->GetScreenEndTime());
if (!onScreen)
return;
AColor::CursorColor(&dc);
if (auto tp = dynamic_cast<TrackPanel*>(&panel)) {
wxASSERT(mIsMaster);
AColor::CursorColor(&dc);
TrackPanelCellIterator begin(tp, true);
TrackPanelCellIterator end(tp, false);
// Draw cursor in all selected tracks
for (; begin != end; ++begin)
{
TrackPanelCellIterator::value_type data(*begin);
Track *const pTrack = data.first;
if (!pTrack)
continue;
if (pTrack->GetSelected() ||
mProject->GetTrackPanel()->GetAx().IsFocused(pTrack))
// Draw cursor in all selected tracks
for (; begin != end; ++begin)
{
const wxRect &rect = data.second;
// AColor::Line includes both endpoints so use GetBottom()
AColor::Line(dc, mLastCursorX, rect.GetTop(), mLastCursorX, rect.GetBottom()); // <-- The whole point of this routine.
TrackPanelCellIterator::value_type data(*begin);
Track *const pTrack = data.first;
if (!pTrack)
continue;
if (pTrack->GetSelected() ||
mProject->GetTrackPanel()->GetAx().IsFocused(pTrack))
{
const wxRect &rect = data.second;
// AColor::Line includes both endpoints so use GetBottom()
AColor::Line(dc, mLastCursorX, rect.GetTop(), mLastCursorX, rect.GetBottom());
// ^^^ The whole point of this routine.
#ifdef EXPERIMENTAL_OUTPUT_DISPLAY
if (MONO_WAVE_PAN(t)){
y = t->GetY(true) - mViewInfo->vpos + 1;
top = y + kTopInset;
bottom = y + t->GetHeight(true) - kTopInset;
AColor::Line(dc, mLastCursorX, top, mLastCursorX, bottom);
}
if (MONO_WAVE_PAN(t)){
y = t->GetY(true) - mViewInfo->vpos + 1;
top = y + kTopInset;
bottom = y + t->GetHeight(true) - kTopInset;
AColor::Line(dc, mLastCursorX, top, mLastCursorX, bottom);
}
#endif
}
}
// This updates related displays such as numbers on the status bar
mProject->TP_DisplaySelection();
}
// AS: Ah, no, this is where we draw the blinky thing in the ruler.
mProject->GetRulerPanel()->Refresh();
// This updates related displays such as numbers on the status bar
mProject->TP_DisplaySelection();
else if (auto ruler = dynamic_cast<AdornedRulerPanel*>(&panel)) {
wxASSERT(!mIsMaster);
dc.SetPen(*wxBLACK_PEN);
// AColor::Line includes both endpoints so use GetBottom()
auto rect = ruler->GetInnerRect();
AColor::Line(dc, mLastCursorX, rect.GetTop(), mLastCursorX, rect.GetBottom());
}
else
wxASSERT(false);
}

View File

@@ -11,6 +11,7 @@ Paul Licameli split from TrackPanel.cpp
#ifndef __AUDACITY_EDIT_CURSOR_OVERLAY__
#define __AUDACITY_EDIT_CURSOR_OVERLAY__
#include "../../MemoryX.h"
#include "../../widgets/Overlay.h"
class AudacityProject;
@@ -18,7 +19,7 @@ class AudacityProject;
class EditCursorOverlay final : public Overlay
{
public:
EditCursorOverlay(AudacityProject *project);
EditCursorOverlay(AudacityProject *project, bool isMaster = true);
virtual ~EditCursorOverlay();
private:
@@ -26,6 +27,8 @@ private:
void Draw(OverlayPanel &panel, wxDC &dc) override;
AudacityProject *mProject;
bool mIsMaster;
std::unique_ptr<EditCursorOverlay> mPartner;
int mLastCursorX;
double mCursorTime;