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

#include <Scrubbing.h>

Inheritance diagram for ScrubbingOverlay:
Overlay

Public Member Functions

 ScrubbingOverlay (AudacityProject *project)
 
- 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
 
void OnTimer (wxCommandEvent &event)
 
const ScrubberGetScrubber () const
 
ScrubberGetScrubber ()
 

Private Attributes

AudacityProjectmProject
 
wxRect mLastScrubRect
 
wxRect mNextScrubRect
 
wxString mLastScrubSpeedText
 
wxString mNextScrubSpeedText
 

Detailed Description

Definition at line 208 of file Scrubbing.h.

Constructor & Destructor Documentation

ScrubbingOverlay::ScrubbingOverlay ( AudacityProject project)

Definition at line 722 of file Scrubbing.cpp.

References mProject, and OnTimer().

723  : mProject(project)
724  , mLastScrubRect()
725  , mNextScrubRect()
728 {
729  mProject->Bind(EVT_TRACK_PANEL_TIMER,
731  this);
732 }
wxRect mNextScrubRect
Definition: Scrubbing.h:224
wxString mNextScrubSpeedText
Definition: Scrubbing.h:225
wxString mLastScrubSpeedText
Definition: Scrubbing.h:225
AudacityProject * mProject
Definition: Scrubbing.h:222
void OnTimer(wxCommandEvent &event)
Definition: Scrubbing.cpp:773
wxRect mLastScrubRect
Definition: Scrubbing.h:224

Member Function Documentation

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

Implements Overlay.

Definition at line 734 of file Scrubbing.cpp.

References GetScrubber(), mLastScrubRect, mLastScrubSpeedText, mNextScrubRect, mNextScrubSpeedText, and Scrubber::ShouldDrawScrubSpeed().

735 {
736  wxRect rect(mLastScrubRect);
737  const bool outdated =
739  (!mLastScrubRect.IsEmpty() && !GetScrubber().ShouldDrawScrubSpeed()) ||
741  return std::make_pair(
742  rect,
743  outdated
744  );
745 }
const Scrubber & GetScrubber() const
Definition: Scrubbing.cpp:853
wxRect mNextScrubRect
Definition: Scrubbing.h:224
wxString mNextScrubSpeedText
Definition: Scrubbing.h:225
wxString mLastScrubSpeedText
Definition: Scrubbing.h:225
bool ShouldDrawScrubSpeed()
Definition: Scrubbing.cpp:639
wxRect mLastScrubRect
Definition: Scrubbing.h:224
void ScrubbingOverlay::Draw ( OverlayPanel panel,
wxDC &  dc 
)
overrideprivatevirtual

Implements Overlay.

Definition at line 747 of file Scrubbing.cpp.

References GetScrubber(), Scrubber::IsScrollScrubbing(), mLastScrubRect, mLastScrubSpeedText, mNextScrubRect, mNextScrubSpeedText, and Scrubber::ShouldDrawScrubSpeed().

748 {
751 
752  Scrubber &scrubber = GetScrubber();
753  if (!scrubber.ShouldDrawScrubSpeed())
754  return;
755 
756  static const wxFont labelFont(24, wxSWISS, wxNORMAL, wxNORMAL);
757  dc.SetFont(labelFont);
758 
759  // These two colors were previously saturated red and green. However
760  // we have a rule to try to only use red for reserved purposes of
761  // (a) Recording
762  // (b) Error alerts
763  // So they were changed to 'orange' and 'lime'.
764  static const wxColour clrNoScroll(215, 162, 0), clrScroll(0, 204, 153);
765  if (scrubber.IsScrollScrubbing())
766  dc.SetTextForeground(clrScroll);
767  else
768  dc.SetTextForeground(clrNoScroll);
769 
770  dc.DrawText(mLastScrubSpeedText, mLastScrubRect.GetX(), mLastScrubRect.GetY());
771 }
const Scrubber & GetScrubber() const
Definition: Scrubbing.cpp:853
wxRect mNextScrubRect
Definition: Scrubbing.h:224
wxString mNextScrubSpeedText
Definition: Scrubbing.h:225
wxString mLastScrubSpeedText
Definition: Scrubbing.h:225
bool ShouldDrawScrubSpeed()
Definition: Scrubbing.cpp:639
bool IsScrollScrubbing() const
Definition: Scrubbing.h:98
wxRect mLastScrubRect
Definition: Scrubbing.h:224
const Scrubber & ScrubbingOverlay::GetScrubber ( ) const
private

Definition at line 853 of file Scrubbing.cpp.

References AudacityProject::GetScrubber(), and mProject.

Referenced by DoGetRectangle(), Draw(), and OnTimer().

854 {
855  return mProject->GetScrubber();
856 }
Scrubber & GetScrubber()
Definition: Project.h:785
AudacityProject * mProject
Definition: Scrubbing.h:222
Scrubber & ScrubbingOverlay::GetScrubber ( )
private

Definition at line 858 of file Scrubbing.cpp.

References AudacityProject::GetScrubber(), and mProject.

859 {
860  return mProject->GetScrubber();
861 }
Scrubber & GetScrubber()
Definition: Project.h:785
AudacityProject * mProject
Definition: Scrubbing.h:222
void ScrubbingOverlay::OnTimer ( wxCommandEvent &  event)
private

Definition at line 773 of file Scrubbing.cpp.

References Scrubber::FindScrubSpeed(), format, TrackPanel::GetLeftOffset(), Scrubber::GetMaxScrubSpeed(), AudacityProject::GetRulerPanel(), GetScrubber(), AudacityProject::GetTrackPanel(), AudacityProject::GetViewInfo(), Scrubber::HasStartedScrubbing(), Scrubber::IsScrollScrubbing(), Scrubber::IsScrubbing(), Scrubber::MaybeStartScrubbing(), min(), mNextScrubRect, mNextScrubSpeedText, mProject, ZoomInfo::PositionToTime(), Scrubber::Seeks(), Scrubber::ShouldDrawScrubSpeed(), and Scrubber::TemporarilySeeks().

Referenced by ScrubbingOverlay().

774 {
775  // Let other listeners get the notification
776  event.Skip();
777 
778  Scrubber &scrubber = GetScrubber();
779  const auto isScrubbing = scrubber.IsScrubbing();
780  const auto ruler = mProject->GetRulerPanel();
781  auto position = ::wxGetMousePosition();
782 
783  {
784  if(scrubber.HasStartedScrubbing()) {
785  auto xx = ruler->ScreenToClient(position).x;
786  ruler->UpdateQuickPlayPos(xx);
787 
788  if (!isScrubbing)
789  // Really start scrub if motion is far enough
790  scrubber.MaybeStartScrubbing(xx);
791  }
792 
793  if (!isScrubbing) {
794  mNextScrubRect = wxRect();
795  return;
796  }
797  else
798  ruler->ShowQuickPlayIndicator();
799  }
800 
801  if (!scrubber.ShouldDrawScrubSpeed()) {
802  mNextScrubRect = wxRect();
803  }
804  else {
805  TrackPanel *const trackPanel = mProject->GetTrackPanel();
806  int panelWidth, panelHeight;
807  trackPanel->GetSize(&panelWidth, &panelHeight);
808 
809  // Where's the mouse?
810  position = trackPanel->ScreenToClient(position);
811 
812  const bool seeking = scrubber.Seeks() || scrubber.TemporarilySeeks();
813 
814  // Find the text
815  const double maxScrubSpeed = GetScrubber().GetMaxScrubSpeed();
816  const double speed =
817  scrubber.IsScrollScrubbing()
818  ? scrubber.FindScrubSpeed
819  (seeking, mProject->GetViewInfo().PositionToTime(position.x, trackPanel->GetLeftOffset()))
820  : maxScrubSpeed;
821 
822  const wxChar *format =
823  scrubber.IsScrollScrubbing()
824  ? seeking
825  ? wxT("%+.2fX")
826  : wxT("%+.2f")
827  : wxT("%.2f");
828 
829  mNextScrubSpeedText = wxString::Format(format, speed);
830 
831  // Find the origin for drawing text
832  wxCoord width, height;
833  {
834  wxClientDC dc(trackPanel);
835  static const wxFont labelFont(24, wxSWISS, wxNORMAL, wxNORMAL);
836  dc.SetFont(labelFont);
837  dc.GetTextExtent(mNextScrubSpeedText, &width, &height);
838  }
839  const auto xx =
840  std::max(0, std::min(panelWidth - width, position.x - width / 2));
841 
842  // Put the text above the cursor, if it fits.
843  enum { offset = 20 };
844  auto yy = position.y - height + offset;
845  if (yy < 0)
846  yy += height + 2 * offset;
847  yy = std::max(0, std::min(panelHeight - height, yy));
848 
849  mNextScrubRect = wxRect(xx, yy, width, height);
850  }
851 }
const Scrubber & GetScrubber() const
Definition: Scrubbing.cpp:853
bool HasStartedScrubbing() const
Definition: Scrubbing.h:94
wxRect mNextScrubRect
Definition: Scrubbing.h:224
wxString mNextScrubSpeedText
Definition: Scrubbing.h:225
AudacityProject * mProject
Definition: Scrubbing.h:222
double PositionToTime(wxInt64 position, wxInt64 origin=0, bool ignoreFisheye=false) const
Definition: ViewInfo.cpp:49
int format
Definition: ExportPCM.cpp:56
bool IsScrubbing() const
Definition: Scrubbing.cpp:574
bool TemporarilySeeks() const
Definition: Scrubbing.cpp:621
The TrackPanel class coordinates updates and operations on the main part of the screen which contains...
Definition: TrackPanel.h:245
bool MaybeStartScrubbing(wxCoord xx)
Definition: Scrubbing.cpp:302
AdornedRulerPanel * GetRulerPanel()
Definition: Project.cpp:1408
double FindScrubSpeed(bool seeking, double time) const
Definition: Scrubbing.cpp:650
bool Seeks() const
Definition: Scrubbing.cpp:627
bool ShouldDrawScrubSpeed()
Definition: Scrubbing.cpp:639
int min(int a, int b)
bool IsScrollScrubbing() const
Definition: Scrubbing.h:98
TrackPanel * GetTrackPanel()
Definition: Project.h:289
int GetLeftOffset() const
Definition: TrackPanel.h:287
double GetMaxScrubSpeed() const
Definition: Scrubbing.h:115
const ViewInfo & GetViewInfo() const
Definition: Project.h:189

Member Data Documentation

wxRect ScrubbingOverlay::mLastScrubRect
private

Definition at line 224 of file Scrubbing.h.

Referenced by DoGetRectangle(), and Draw().

wxString ScrubbingOverlay::mLastScrubSpeedText
private

Definition at line 225 of file Scrubbing.h.

Referenced by DoGetRectangle(), and Draw().

wxRect ScrubbingOverlay::mNextScrubRect
private

Definition at line 224 of file Scrubbing.h.

Referenced by DoGetRectangle(), Draw(), and OnTimer().

wxString ScrubbingOverlay::mNextScrubSpeedText
private

Definition at line 225 of file Scrubbing.h.

Referenced by DoGetRectangle(), Draw(), and OnTimer().

AudacityProject* ScrubbingOverlay::mProject
private

Definition at line 222 of file Scrubbing.h.

Referenced by GetScrubber(), OnTimer(), and ScrubbingOverlay().


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