Audacity 3.2.0
AffordanceHandle.cpp
Go to the documentation of this file.
1/*!********************************************************************
2*
3 Audacity: A Digital Audio Editor
4
5 AffordanceHandle.cpp
6
7 Vitaly Sverchinsky
8
9 **********************************************************************/
10
11#include "AffordanceHandle.h"
12
13#include "../../HitTestResult.h"
14#include "../../ProjectAudioIO.h"
15#include "../../RefreshCode.h"
16#include "ViewInfo.h"
17#include "../../SelectionState.h"
18#include "../../TrackPanelMouseEvent.h"
19#include "Track.h"
20#include "../../../images/Cursors.h"
21
22#include <wx/cursor.h>
23
25{
26 static auto disabledCursor =
27 MakeCursor(wxCURSOR_NO_ENTRY, DisabledCursorXpm, 16, 16);
28 static auto handOpenCursor =
29 MakeCursor(wxCURSOR_HAND, RearrangeCursorXpm, 16, 16);
30 static auto handClosedCursor =
31 MakeCursor(wxCURSOR_HAND, RearrangingCursorXpm, 16, 16);
32 // i18n-hint Appears on hovering mouse over clip affordance
33 auto message = XO("Drag clips to reposition them."\
34 " Hold Shift and drag to move all clips on the same track.");
35
36 if (unsafe)
37 return { message, &*disabledCursor };
38 return {
39 message,
40 (moving
41 ? &*handClosedCursor
43 };
44}
45
46void AffordanceHandle::Enter(bool forward, AudacityProject* pProject)
47{
49 TimeShiftHandle::Enter(forward, pProject);
50}
51
53{
54 const bool unsafe = ProjectAudioIO::Get(*pProject).IsAudioActive();
55 return HitPreview(pProject, unsafe, Clicked());
56}
57
58AffordanceHandle::AffordanceHandle(const std::shared_ptr<Track>& track)
59 : TimeShiftHandle(track, false)
60{
61}
62
64{
65 auto result = TimeShiftHandle::Click(evt, pProject);
66 return result | RefreshCode::RefreshCell;
67}
68
70{
71 auto result = TimeShiftHandle::Release(event, pProject, pParent);
72 if (!WasMoved())
73 {
74 auto& trackList = TrackList::Get(*pProject);
75 if(const auto track = trackList.Lock<Track>(GetTrack()))
76 {
77 auto& selectionState = SelectionState::Get(*pProject);
78 selectionState.SelectNone(trackList);
79 selectionState.SelectTrack(*track, true, true);
80
81 result |= SelectAt(event, pProject);
82 }
83 }
84 return result;
85}
static auto handOpenCursor
#define XO(s)
Definition: Internat.h:31
declares abstract base class Track, TrackList, and iterators over TrackList
std::unique_ptr< wxCursor > MakeCursor(int WXUNUSED(CursorId), const char *const pXpm[36], int HotX, int HotY)
Definition: TrackPanel.cpp:185
HitTestPreview Preview(const TrackPanelMouseState &mouseState, AudacityProject *pProject) override
void Enter(bool forward, AudacityProject *pProject) override
AffordanceHandle(const std::shared_ptr< Track > &track)
static HitTestPreview HitPreview(const AudacityProject *, bool unsafe, bool moving)
Result Release(const TrackPanelMouseEvent &event, AudacityProject *pProject, wxWindow *pParent) override
virtual Result SelectAt(const TrackPanelMouseEvent &event, AudacityProject *pProject)=0
Result Click(const TrackPanelMouseEvent &evt, AudacityProject *pProject) override
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:89
bool IsAudioActive() const
static ProjectAudioIO & Get(AudacityProject &project)
static SelectionState & Get(AudacityProject &project)
bool Clicked() const
std::shared_ptr< Track > GetTrack() const
bool WasMoved() const
Result Release(const TrackPanelMouseEvent &event, AudacityProject *pProject, wxWindow *pParent) override
void Enter(bool forward, AudacityProject *) override
Result Click(const TrackPanelMouseEvent &event, AudacityProject *pProject) override
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:225
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:486
unsigned Result
Definition: UIHandle.h:38
void SetChangeHighlight(Result val)
Definition: UIHandle.h:123
@ RefreshLatestCell
Definition: RefreshCode.h:25