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#include <wx/event.h>
24
26{
27 static wxCursor arrowCursor{ wxCURSOR_ARROW };
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, &arrowCursor };
38 return {
39 message,
40 (moving
41 ? &*handClosedCursor
43 };
44}
45
46void AffordanceHandle::Enter(bool forward, AudacityProject* pProject)
47{
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 mClickPosition = evt.event.GetPosition();
67 return result | RefreshCode::RefreshCell;
68}
69
71{
72 if(!mMoving)
73 {
74 if(std::abs(mClickPosition.x - event.event.m_x) >= MoveThreshold ||
75 std::abs(mClickPosition.y - event.event.m_y) >= MoveThreshold)
76 {
77 mMoving = true;
78 }
79 else
81 }
82 return TimeShiftHandle::Drag(event, pProject);
83}
84
86{
87 auto result = TimeShiftHandle::Release(event, pProject, pParent);
88 if (!WasMoved())
89 result |= UpdateTrackSelection(event, pProject);
90 return result;
91}
92
94{
95 auto& trackList = TrackList::Get(*pProject);
96
97 if(const auto track = trackList.Lock<Track>(GetTrack()))
98 {
99 auto& selectionState = SelectionState::Get(*pProject);
100 selectionState.SelectNone(trackList);
101 selectionState.SelectTrack(*track, true, true);
102
103 return SelectAt(event, pProject);
104 }
105
107}
static std::unique_ptr< wxCursor > handOpenCursor
XO("Cut/Copy/Paste")
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:189
Result UpdateTrackSelection(const TrackPanelMouseEvent &event, AudacityProject *pProject)
HitTestPreview Preview(const TrackPanelMouseState &mouseState, AudacityProject *pProject) override
void Enter(bool forward, AudacityProject *pProject) override
AffordanceHandle(const std::shared_ptr< Track > &track)
Result Drag(const TrackPanelMouseEvent &event, AudacityProject *pProject) override
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
static constexpr double MoveThreshold
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
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 Drag(const TrackPanelMouseEvent &event, AudacityProject *pProject) override
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:110
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:314
unsigned Result
Definition: UIHandle.h:40
void SetChangeHighlight(Result val)
Definition: UIHandle.h:132
@ RefreshLatestCell
Definition: RefreshCode.h:25