Audacity 3.2.0
SliderHandle.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3Audacity: A Digital Audio Editor
4
5SliderHandle.cpp
6
7Paul Licameli
8
9**********************************************************************/
10
11
12#include "SliderHandle.h"
13
14#include "../../widgets/ASlider.h"
15#include "../../HitTestResult.h"
16#include "../../RefreshCode.h"
17#include "Track.h"
18#include "../../TrackPanelMouseEvent.h"
19
21( SliderFn sliderFn, const wxRect &rect, const std::shared_ptr<Track> &pTrack )
22 : mpTrack{ pTrack }
23 , mRect{ rect }
24 , mSliderFn{ sliderFn }
25{
26}
27
29{
31}
32
34{
35}
36
37std::shared_ptr<const Track> SliderHandle::FindTrack() const
38{
39 return mpTrack.lock();
40}
41
43{
44 return mIsDragging;
45}
46
48(const TrackPanelMouseEvent &evt, AudacityProject *pProject)
49{
50 wxMouseEvent &event = evt.event;
51 using namespace RefreshCode;
52 if (!event.Button(wxMOUSE_BTN_LEFT))
53 return Cancelled;
54
55 // Come here for left click or double click
57 auto slider = GetSlider( pProject );
58 slider->OnMouseEvent(event);
59 const float newValue = slider->Get();
60
61 // Make a non-permanent change to the project data:
62 auto result = SetValue(pProject, newValue);
63
64 if (event.ButtonDClick())
65 // Just did a modal dialog in OnMouseEvent
66 // Do not start a drag
67 return result | RefreshCell | Cancelled;
68 else {
69 mIsDragging = true;
70 return result | RefreshCell;
71 }
72}
73
75(const TrackPanelMouseEvent &evt, AudacityProject *pProject)
76{
77 wxMouseEvent &event = evt.event;
78 using namespace RefreshCode;
79 GetSlider( pProject )->OnMouseEvent(event);
80 const float newValue = GetSlider( pProject )->Get();
81
82 // Make a non-permanent change to the project data:
83 return RefreshCell | SetValue(pProject, newValue);
84}
85
88{
89 // No special cursor
90 TranslatableString message;
91 if (project)
92 message = Tip(st.state, *project);
93 return { message, {}, message };
94}
95
97(const TrackPanelMouseEvent &evt, AudacityProject *pProject,
98 wxWindow *)
99{
100 using namespace RefreshCode;
101 wxMouseEvent &event = evt.event;
102 GetSlider( pProject )->OnMouseEvent(event);
103 const float newValue = GetSlider( pProject )->Get();
104
105 Result result = RefreshCell;
106
107 // Commit changes to the project data:
108 result |= SetValue(pProject, newValue);
109 result |= CommitChanges(event, pProject);
110
111 mpTrack.reset();
112 return result;
113}
114
116{
117 wxMouseEvent event(wxEVT_LEFT_UP);
118 GetSlider( pProject )->OnMouseEvent(event);
119
120 // Undo un-committed changes to project data:
121 auto result = SetValue(pProject, mStartingValue);
122 mpTrack.reset();
123 return RefreshCode::RefreshCell | result;
124}
125
127{
128 auto pTrack = TrackList::Get( *pProject ).Lock(mpTrack);
129 return mSliderFn( pProject, mRect, pTrack.get() );
130}
const auto project
declares abstract base class Track, TrackList, and iterators over TrackList
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
Lightweight version of ASlider. In other words it does not have a window permanently associated with ...
Definition: ASlider.h:64
void OnMouseEvent(wxMouseEvent &event)
Definition: ASlider.cpp:1185
float Get(bool convert=true)
Definition: ASlider.cpp:1569
Result Drag(const TrackPanelMouseEvent &event, AudacityProject *pProject) final override
wxRect mRect
Definition: SliderHandle.h:77
virtual Result SetValue(AudacityProject *pProject, float newValue)=0
LWSlider *(*)(AudacityProject *, const wxRect &, Track *) SliderFn
Definition: SliderHandle.h:27
SliderFn mSliderFn
Definition: SliderHandle.h:78
bool mIsDragging
Definition: SliderHandle.h:83
HitTestPreview Preview(const TrackPanelMouseState &state, AudacityProject *pProject) final override
Result Click(const TrackPanelMouseEvent &event, AudacityProject *pProject) final override
bool IsDragging() const override
Result Cancel(AudacityProject *pProject) final override
SliderHandle(const SliderHandle &)=delete
float mStartingValue
Definition: SliderHandle.h:81
virtual TranslatableString Tip(const wxMouseState &state, AudacityProject &project) const =0
virtual ~SliderHandle()
LWSlider * GetSlider(AudacityProject *pProject)
void Enter(bool forward, AudacityProject *) override
virtual Result CommitChanges(const wxMouseEvent &event, AudacityProject *pProject)=0
virtual float GetValue()=0
Result Release(const TrackPanelMouseEvent &event, AudacityProject *pProject, wxWindow *pParent) final override
std::shared_ptr< const Track > FindTrack() const override
std::weak_ptr< Track > mpTrack
Definition: SliderHandle.h:76
std::shared_ptr< Subclass > Lock(const std::weak_ptr< Subclass > &wTrack)
Definition: Track.h:1079
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:314
Holds a msgid for the translation catalog; may also bind format arguments.
Result mChangeHighlight
Definition: UIHandle.h:152
unsigned Result
Definition: UIHandle.h:40
Namespace containing an enum 'what to do on a refresh?'.
Definition: RefreshCode.h:16