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 209 of file Scrubbing.h.

Constructor & Destructor Documentation

ScrubbingOverlay::ScrubbingOverlay ( AudacityProject project)

Definition at line 723 of file Scrubbing.cpp.

References mProject, and OnTimer().

724  : mProject(project)
725  , mLastScrubRect()
726  , mNextScrubRect()
729 {
730  mProject->Bind(EVT_TRACK_PANEL_TIMER,
732  this);
733 }
wxRect mNextScrubRect
Definition: Scrubbing.h:225
wxString mNextScrubSpeedText
Definition: Scrubbing.h:226
wxString mLastScrubSpeedText
Definition: Scrubbing.h:226
AudacityProject * mProject
Definition: Scrubbing.h:223
void OnTimer(wxCommandEvent &event)
Definition: Scrubbing.cpp:774
wxRect mLastScrubRect
Definition: Scrubbing.h:225

Member Function Documentation

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

Implements Overlay.

Definition at line 735 of file Scrubbing.cpp.

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

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

Implements Overlay.

Definition at line 748 of file Scrubbing.cpp.

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

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

Definition at line 854 of file Scrubbing.cpp.

References AudacityProject::GetScrubber(), and mProject.

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

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

Definition at line 859 of file Scrubbing.cpp.

References AudacityProject::GetScrubber(), and mProject.

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

Definition at line 774 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().

775 {
776  // Let other listeners get the notification
777  event.Skip();
778 
779  Scrubber &scrubber = GetScrubber();
780  const auto isScrubbing = scrubber.IsScrubbing();
781  const auto ruler = mProject->GetRulerPanel();
782  auto position = ::wxGetMousePosition();
783 
784  {
785  if(scrubber.HasStartedScrubbing()) {
786  auto xx = ruler->ScreenToClient(position).x;
787  ruler->UpdateQuickPlayPos(xx);
788 
789  if (!isScrubbing)
790  // Really start scrub if motion is far enough
791  scrubber.MaybeStartScrubbing(xx);
792  }
793 
794  if (!isScrubbing) {
795  mNextScrubRect = wxRect();
796  return;
797  }
798  else
799  ruler->ShowQuickPlayIndicator();
800  }
801 
802  if (!scrubber.ShouldDrawScrubSpeed()) {
803  mNextScrubRect = wxRect();
804  }
805  else {
806  TrackPanel *const trackPanel = mProject->GetTrackPanel();
807  int panelWidth, panelHeight;
808  trackPanel->GetSize(&panelWidth, &panelHeight);
809 
810  // Where's the mouse?
811  position = trackPanel->ScreenToClient(position);
812 
813  const bool seeking = scrubber.Seeks() || scrubber.TemporarilySeeks();
814 
815  // Find the text
816  const double maxScrubSpeed = GetScrubber().GetMaxScrubSpeed();
817  const double speed =
818  scrubber.IsScrollScrubbing()
819  ? scrubber.FindScrubSpeed
820  (seeking, mProject->GetViewInfo().PositionToTime(position.x, trackPanel->GetLeftOffset()))
821  : maxScrubSpeed;
822 
823  const wxChar *format =
824  scrubber.IsScrollScrubbing()
825  ? seeking
826  ? wxT("%+.2fX")
827  : wxT("%+.2f")
828  : wxT("%.2f");
829 
830  mNextScrubSpeedText = wxString::Format(format, speed);
831 
832  // Find the origin for drawing text
833  wxCoord width, height;
834  {
835  wxClientDC dc(trackPanel);
836  static const wxFont labelFont(24, wxSWISS, wxNORMAL, wxNORMAL);
837  dc.SetFont(labelFont);
838  dc.GetTextExtent(mNextScrubSpeedText, &width, &height);
839  }
840  const auto xx =
841  std::max(0, std::min(panelWidth - width, position.x - width / 2));
842 
843  // Put the text above the cursor, if it fits.
844  enum { offset = 20 };
845  auto yy = position.y - height + offset;
846  if (yy < 0)
847  yy += height + 2 * offset;
848  yy = std::max(0, std::min(panelHeight - height, yy));
849 
850  mNextScrubRect = wxRect(xx, yy, width, height);
851  }
852 }
const Scrubber & GetScrubber() const
Definition: Scrubbing.cpp:854
bool HasStartedScrubbing() const
Definition: Scrubbing.h:95
wxRect mNextScrubRect
Definition: Scrubbing.h:225
wxString mNextScrubSpeedText
Definition: Scrubbing.h:226
AudacityProject * mProject
Definition: Scrubbing.h:223
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:575
bool TemporarilySeeks() const
Definition: Scrubbing.cpp:622
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:303
AdornedRulerPanel * GetRulerPanel()
Definition: Project.cpp:1439
double FindScrubSpeed(bool seeking, double time) const
Definition: Scrubbing.cpp:651
bool Seeks() const
Definition: Scrubbing.cpp:628
bool ShouldDrawScrubSpeed()
Definition: Scrubbing.cpp:640
int min(int a, int b)
bool IsScrollScrubbing() const
Definition: Scrubbing.h:99
TrackPanel * GetTrackPanel()
Definition: Project.h:307
int GetLeftOffset() const
Definition: TrackPanel.h:287
double GetMaxScrubSpeed() const
Definition: Scrubbing.h:116
const ViewInfo & GetViewInfo() const
Definition: Project.h:207

Member Data Documentation

wxRect ScrubbingOverlay::mLastScrubRect
private

Definition at line 225 of file Scrubbing.h.

Referenced by DoGetRectangle(), and Draw().

wxString ScrubbingOverlay::mLastScrubSpeedText
private

Definition at line 226 of file Scrubbing.h.

Referenced by DoGetRectangle(), and Draw().

wxRect ScrubbingOverlay::mNextScrubRect
private

Definition at line 225 of file Scrubbing.h.

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

wxString ScrubbingOverlay::mNextScrubSpeedText
private

Definition at line 226 of file Scrubbing.h.

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

AudacityProject* ScrubbingOverlay::mProject
private

Definition at line 223 of file Scrubbing.h.

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


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