Audacity  2.2.2
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | List of all members
SliderHandle Class Referenceabstract

#include <SliderHandle.h>

Inheritance diagram for SliderHandle:
UIHandle GainSliderHandle PanSliderHandle

Public Types

using SliderFn = LWSlider *(*)(AudacityProject *, const wxRect &, Track *)
 
- Public Types inherited from UIHandle
enum  DrawingPass { Cells, Panel }
 
using Result = unsigned
 
using Cell = TrackPanelCell
 

Public Member Functions

 SliderHandle (SliderFn sliderFn, const wxRect &rect, const std::shared_ptr< Track > &pTrack)
 
SliderHandleoperator= (const SliderHandle &)=default
 
std::shared_ptr< TrackGetTrack () const
 
bool IsClicked () const
 
- Public Member Functions inherited from UIHandle
virtual ~UIHandle ()=0
 
virtual bool HasRotation () const
 
virtual bool Rotate (bool forward)
 
virtual bool HasEscape () const
 
virtual bool Escape ()
 
virtual void DrawExtras (DrawingPass pass, wxDC *dc, const wxRegion &updateRegion, const wxRect &panelRect)
 
virtual bool StopsOnKeystroke ()
 
virtual void OnProjectChange (AudacityProject *pProject)
 
Result GetChangeHighlight () const
 
void SetChangeHighlight (Result val)
 

Protected Member Functions

virtual ~SliderHandle ()
 
virtual float GetValue ()=0
 
virtual Result SetValue (AudacityProject *pProject, float newValue)=0
 
virtual Result CommitChanges (const wxMouseEvent &event, AudacityProject *pProject)=0
 
void Enter (bool forward) override
 
Result Click (const TrackPanelMouseEvent &event, AudacityProject *pProject) finaloverride
 
Result Drag (const TrackPanelMouseEvent &event, AudacityProject *pProject) finaloverride
 
HitTestPreview Preview (const TrackPanelMouseState &state, const AudacityProject *pProject) finaloverride
 
Result Release (const TrackPanelMouseEvent &event, AudacityProject *pProject, wxWindow *pParent) finaloverride
 
Result Cancel (AudacityProject *pProject) finaloverride
 
LWSliderGetSlider (AudacityProject *pProject)
 

Protected Attributes

std::weak_ptr< TrackmpTrack
 
wxRect mRect {}
 
SliderFn mSliderFn
 
float mStartingValue {}
 
bool mIsClicked {}
 
- Protected Attributes inherited from UIHandle
Result mChangeHighlight { 0 }
 

Private Member Functions

 SliderHandle (const SliderHandle &)=delete
 

Additional Inherited Members

- Static Public Member Functions inherited from UIHandle
static UIHandle::Result NeedChangeHighlight (const UIHandle &, const UIHandle &)
 

Detailed Description

Definition at line 22 of file SliderHandle.h.

Member Typedef Documentation

using SliderHandle::SliderFn = LWSlider *(*)( AudacityProject*, const wxRect&, Track* )

Definition at line 27 of file SliderHandle.h.

Constructor & Destructor Documentation

SliderHandle::SliderHandle ( const SliderHandle )
privatedelete
SliderHandle::SliderHandle ( SliderFn  sliderFn,
const wxRect &  rect,
const std::shared_ptr< Track > &  pTrack 
)
explicit

Definition at line 20 of file SliderHandle.cpp.

21  : mpTrack{ pTrack }
22  , mRect{ rect }
23  , mSliderFn{ sliderFn }
24 {
25 }
std::weak_ptr< Track > mpTrack
Definition: SliderHandle.h:71
SliderFn mSliderFn
Definition: SliderHandle.h:73
wxRect mRect
Definition: SliderHandle.h:72
SliderHandle::~SliderHandle ( )
protectedvirtual

Definition at line 32 of file SliderHandle.cpp.

33 {
34 }

Member Function Documentation

UIHandle::Result SliderHandle::Cancel ( AudacityProject pProject)
finaloverrideprotectedvirtual

Implements UIHandle.

Definition at line 101 of file SliderHandle.cpp.

References GetSlider(), mpTrack, mStartingValue, LWSlider::OnMouseEvent(), RefreshCode::RefreshCell, and SetValue().

102 {
103  wxMouseEvent event(wxEVT_LEFT_UP);
104  GetSlider( pProject )->OnMouseEvent(event);
105 
106  // Undo un-committed changes to project data:
107  auto result = SetValue(pProject, mStartingValue);
108  mpTrack.reset();
109  return RefreshCode::RefreshCell | result;
110 }
void OnMouseEvent(wxMouseEvent &event)
Definition: ASlider.cpp:984
LWSlider * GetSlider(AudacityProject *pProject)
std::weak_ptr< Track > mpTrack
Definition: SliderHandle.h:71
virtual Result SetValue(AudacityProject *pProject, float newValue)=0
float mStartingValue
Definition: SliderHandle.h:76
UIHandle::Result SliderHandle::Click ( const TrackPanelMouseEvent event,
AudacityProject pProject 
)
finaloverrideprotectedvirtual

Implements UIHandle.

Definition at line 37 of file SliderHandle.cpp.

References RefreshCode::Cancelled, TrackPanelMouseEvent::event, and RefreshCode::RefreshCell.

38 {
39  wxMouseEvent &event = evt.event;
40  using namespace RefreshCode;
41  if (!event.Button(wxMOUSE_BTN_LEFT))
42  return Cancelled;
43 
44  // Come here for left click or double click
46  auto slider = GetSlider( pProject );
47  slider->OnMouseEvent(event);
48  const float newValue = slider->Get();
49 
50  // Make a non-permanent change to the project data:
51  auto result = SetValue(pProject, newValue);
52 
53  if (event.ButtonDClick())
54  // Just did a modal dialog in OnMouseEvent
55  // Do not start a drag
56  return result | RefreshCell | Cancelled;
57  else {
58  mIsClicked = true;
59  return result | RefreshCell;
60  }
61 }
LWSlider * GetSlider(AudacityProject *pProject)
virtual Result SetValue(AudacityProject *pProject, float newValue)=0
float mStartingValue
Definition: SliderHandle.h:76
virtual float GetValue()=0
virtual Result SliderHandle::CommitChanges ( const wxMouseEvent &  event,
AudacityProject pProject 
)
protectedpure virtual

Implemented in PanSliderHandle, and GainSliderHandle.

UIHandle::Result SliderHandle::Drag ( const TrackPanelMouseEvent event,
AudacityProject pProject 
)
finaloverrideprotectedvirtual

Implements UIHandle.

Definition at line 64 of file SliderHandle.cpp.

References TrackPanelMouseEvent::event, and RefreshCode::RefreshCell.

65 {
66  wxMouseEvent &event = evt.event;
67  using namespace RefreshCode;
68  GetSlider( pProject )->OnMouseEvent(event);
69  const float newValue = GetSlider( pProject )->Get();
70 
71  // Make a non-permanent change to the project data:
72  return RefreshCell | SetValue(pProject, newValue);
73 }
void OnMouseEvent(wxMouseEvent &event)
Definition: ASlider.cpp:984
LWSlider * GetSlider(AudacityProject *pProject)
virtual Result SetValue(AudacityProject *pProject, float newValue)=0
float Get(bool convert=true)
Definition: ASlider.cpp:1313
void SliderHandle::Enter ( bool  forward)
overrideprotectedvirtual

Reimplemented from UIHandle.

Definition at line 27 of file SliderHandle.cpp.

References UIHandle::mChangeHighlight, and RefreshCode::RefreshCell.

LWSlider * SliderHandle::GetSlider ( AudacityProject pProject)
protected

Definition at line 112 of file SliderHandle.cpp.

References AudacityProject::GetTracks(), TrackList::Lock(), mpTrack, mRect, and mSliderFn.

Referenced by Cancel().

113 {
114  auto pTrack = pProject->GetTracks()->Lock(mpTrack);
115  return mSliderFn( pProject, mRect, pTrack.get() );
116 }
std::weak_ptr< Track > mpTrack
Definition: SliderHandle.h:71
SliderFn mSliderFn
Definition: SliderHandle.h:73
std::shared_ptr< Subclass > Lock(const std::weak_ptr< Subclass > &wTrack)
Definition: Track.h:734
wxRect mRect
Definition: SliderHandle.h:72
TrackList * GetTracks()
Definition: Project.h:192
std::shared_ptr<Track> SliderHandle::GetTrack ( ) const
inline

Definition at line 35 of file SliderHandle.h.

References mpTrack.

35 { return mpTrack.lock(); }
std::weak_ptr< Track > mpTrack
Definition: SliderHandle.h:71
virtual float SliderHandle::GetValue ( )
protectedpure virtual

Implemented in PanSliderHandle, and GainSliderHandle.

bool SliderHandle::IsClicked ( ) const
inline

Definition at line 36 of file SliderHandle.h.

References mIsClicked.

36 { return mIsClicked; }
SliderHandle& SliderHandle::operator= ( const SliderHandle )
default
HitTestPreview SliderHandle::Preview ( const TrackPanelMouseState state,
const AudacityProject pProject 
)
finaloverrideprotectedvirtual

Implements UIHandle.

Definition at line 76 of file SliderHandle.cpp.

77 {
78  // No special message or cursor
79  return {};
80 }
UIHandle::Result SliderHandle::Release ( const TrackPanelMouseEvent event,
AudacityProject pProject,
wxWindow *  pParent 
)
finaloverrideprotectedvirtual

Implements UIHandle.

Definition at line 83 of file SliderHandle.cpp.

References TrackPanelMouseEvent::event, and RefreshCode::RefreshCell.

85 {
86  using namespace RefreshCode;
87  wxMouseEvent &event = evt.event;
88  GetSlider( pProject )->OnMouseEvent(event);
89  const float newValue = GetSlider( pProject )->Get();
90 
91  Result result = RefreshCell;
92 
93  // Commit changes to the project data:
94  result |= SetValue(pProject, newValue);
95  result |= CommitChanges(event, pProject);
96 
97  mpTrack.reset();
98  return result;
99 }
void OnMouseEvent(wxMouseEvent &event)
Definition: ASlider.cpp:984
LWSlider * GetSlider(AudacityProject *pProject)
std::weak_ptr< Track > mpTrack
Definition: SliderHandle.h:71
virtual Result SetValue(AudacityProject *pProject, float newValue)=0
unsigned Result
Definition: UIHandle.h:37
float Get(bool convert=true)
Definition: ASlider.cpp:1313
virtual Result CommitChanges(const wxMouseEvent &event, AudacityProject *pProject)=0
virtual Result SliderHandle::SetValue ( AudacityProject pProject,
float  newValue 
)
protectedpure virtual

Implemented in PanSliderHandle, and GainSliderHandle.

Referenced by Cancel().

Member Data Documentation

bool SliderHandle::mIsClicked {}
protected

Definition at line 78 of file SliderHandle.h.

Referenced by IsClicked().

std::weak_ptr<Track> SliderHandle::mpTrack
protected
wxRect SliderHandle::mRect {}
protected

Definition at line 72 of file SliderHandle.h.

Referenced by GetSlider().

SliderFn SliderHandle::mSliderFn
protected

Definition at line 73 of file SliderHandle.h.

Referenced by GetSlider().

float SliderHandle::mStartingValue {}
protected

Definition at line 76 of file SliderHandle.h.

Referenced by Cancel().


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