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
38(const TrackPanelMouseEvent &evt, AudacityProject *pProject)
39{
40 wxMouseEvent &event = evt.event;
41 using namespace RefreshCode;
42 if (!event.Button(wxMOUSE_BTN_LEFT))
43 return Cancelled;
44
45 // Come here for left click or double click
47 auto slider = GetSlider( pProject );
48 slider->OnMouseEvent(event);
49 const float newValue = slider->Get();
50
51 // Make a non-permanent change to the project data:
52 auto result = SetValue(pProject, newValue);
53
54 if (event.ButtonDClick())
55 // Just did a modal dialog in OnMouseEvent
56 // Do not start a drag
57 return result | RefreshCell | Cancelled;
58 else {
59 mIsClicked = true;
60 return result | RefreshCell;
61 }
62}
63
65(const TrackPanelMouseEvent &evt, AudacityProject *pProject)
66{
67 wxMouseEvent &event = evt.event;
68 using namespace RefreshCode;
69 GetSlider( pProject )->OnMouseEvent(event);
70 const float newValue = GetSlider( pProject )->Get();
71
72 // Make a non-permanent change to the project data:
73 return RefreshCell | SetValue(pProject, newValue);
74}
75
77(const TrackPanelMouseState &st, AudacityProject *project)
78{
79 // No special cursor
80 TranslatableString message;
81 if (project)
82 message = Tip(st.state, *project);
83 return { message, {}, message };
84}
85
87(const TrackPanelMouseEvent &evt, AudacityProject *pProject,
88 wxWindow *)
89{
90 using namespace RefreshCode;
91 wxMouseEvent &event = evt.event;
92 GetSlider( pProject )->OnMouseEvent(event);
93 const float newValue = GetSlider( pProject )->Get();
94
95 Result result = RefreshCell;
96
97 // Commit changes to the project data:
98 result |= SetValue(pProject, newValue);
99 result |= CommitChanges(event, pProject);
100
101 mpTrack.reset();
102 return result;
103}
104
106{
107 wxMouseEvent event(wxEVT_LEFT_UP);
108 GetSlider( pProject )->OnMouseEvent(event);
109
110 // Undo un-committed changes to project data:
111 auto result = SetValue(pProject, mStartingValue);
112 mpTrack.reset();
113 return RefreshCode::RefreshCell | result;
114}
115
117{
118 auto pTrack = TrackList::Get( *pProject ).Lock(mpTrack);
119 return mSliderFn( pProject, mRect, pTrack.get() );
120}
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:1169
float Get(bool convert=true)
Definition: ASlider.cpp:1555
Result Drag(const TrackPanelMouseEvent &event, AudacityProject *pProject) final override
wxRect mRect
Definition: SliderHandle.h:76
virtual Result SetValue(AudacityProject *pProject, float newValue)=0
LWSlider *(*)(AudacityProject *, const wxRect &, Track *) SliderFn
Definition: SliderHandle.h:27
SliderFn mSliderFn
Definition: SliderHandle.h:77
HitTestPreview Preview(const TrackPanelMouseState &state, AudacityProject *pProject) final override
Result Click(const TrackPanelMouseEvent &event, AudacityProject *pProject) final override
Result Cancel(AudacityProject *pProject) final override
SliderHandle(const SliderHandle &)=delete
float mStartingValue
Definition: SliderHandle.h:80
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::weak_ptr< Track > mpTrack
Definition: SliderHandle.h:75
std::shared_ptr< Subclass > Lock(const std::weak_ptr< Subclass > &wTrack)
Definition: Track.h:1603
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:486
Holds a msgid for the translation catalog; may also bind format arguments.
Result mChangeHighlight
Definition: UIHandle.h:139
unsigned Result
Definition: UIHandle.h:38
Namespace containing an enum 'what to do on a refresh?'.
Definition: RefreshCode.h:16