Audacity  3.0.3
CommonTrackView.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3 Audacity: A Digital Audio Editor
4 
5 CommonTrackView.cpp
6 
7 Paul Licameli split from class TrackView
8 
9 **********************************************************************/
10 
11 #include "CommonTrackView.h"
12 
13 #include "BackgroundCell.h"
14 #include "TimeShiftHandle.h"
15 #include "TrackControls.h"
16 #include "ZoomHandle.h"
17 #include "../ui/SelectHandle.h"
18 #include "../../AColor.h"
19 #include "../../ProjectSettings.h"
20 #include "../../Track.h"
21 #include "../../TrackArtist.h"
22 #include "../../TrackInfo.h"
23 #include "../../TrackPanelDrawingContext.h"
24 #include "../../TrackPanelMouseEvent.h"
25 
26 #include <wx/dc.h>
27 #include <wx/graphics.h>
28 
29 std::vector<UIHandlePtr> CommonTrackView::HitTest
30 (const TrackPanelMouseState &st,
31  const AudacityProject *pProject)
32 {
33  UIHandlePtr result;
34  using namespace ToolCodes;
35  std::vector<UIHandlePtr> results;
36  const auto &settings = ProjectSettings::Get( *pProject );
37  const auto currentTool = settings.GetTool();
38  const bool isMultiTool = ( currentTool == multiTool );
39 
40  if ( !isMultiTool && currentTool == zoomTool ) {
41  // Zoom tool is a non-selecting tool that takes precedence in all tracks
42  // over all other tools, no matter what detail you point at.
43  result = ZoomHandle::HitAnywhere(
44  BackgroundCell::Get( *pProject ).mZoomHandle );
45  results.push_back(result);
46  return results;
47  }
48 
49  // In other tools, let subclasses determine detailed hits.
50  results =
51  DetailedHitTest( st, pProject, currentTool, isMultiTool );
52 
53  // There are still some general cases.
54 
55  // Sliding applies in more than one track type.
56  if ( !isMultiTool && currentTool == slideTool ) {
58  mTimeShiftHandle, FindTrack(), false);
59  if (result)
60  results.push_back(result);
61  }
62 
63  // Let the multi-tool right-click handler apply only in default of all
64  // other detailed hits.
65  if ( isMultiTool ) {
66  result = ZoomHandle::HitTest(
67  BackgroundCell::Get( *pProject ).mZoomHandle, st.state);
68  if (result)
69  results.push_back(result);
70  }
71 
72  // Finally, default of all is adjustment of the selection box.
73  if ( isMultiTool || currentTool == selectTool ) {
74  result = SelectHandle::HitTest(
75  mSelectHandle, st, pProject, shared_from_this() );
76  if (result)
77  results.push_back(result);
78  }
79 
80  return results;
81 }
82 
83 std::shared_ptr<TrackPanelCell> CommonTrackView::ContextMenuDelegate()
84 {
85  return TrackControls::Get( *FindTrack() ).shared_from_this();
86 }
87 
89 {
90  auto height = TrackInfo::MinimumTrackHeight();
91  const auto pTrack = FindTrack();
92  auto channels = TrackList::Channels(pTrack->SubstituteOriginalTrack().get());
93  auto nChannels = channels.size();
94  auto begin = channels.begin();
95  auto index =
96  std::distance(begin, std::find(begin, channels.end(), pTrack.get()));
97  return (height * (index + 1) / nChannels) - (height * index / nChannels);
98 }
TimeShiftHandle.h
ToolCodes::selectTool
@ selectTool
Definition: ProjectSettings.h:35
ToolCodes
Definition: ProjectSettings.h:33
CommonTrackView::mTimeShiftHandle
std::weak_ptr< TimeShiftHandle > mTimeShiftHandle
Definition: CommonTrackView.h:48
TrackInfo::MinimumTrackHeight
AUDACITY_DLL_API unsigned MinimumTrackHeight()
Definition: TrackInfo.cpp:196
TrackControls::Get
static TrackControls & Get(Track &track)
Definition: TrackControls.cpp:25
ToolCodes::zoomTool
@ zoomTool
Definition: ProjectSettings.h:38
CommonTrackPanelCell::FindTrack
std::shared_ptr< Track > FindTrack()
Definition: CommonTrackPanelCell.h:44
TrackList::Channels
static auto Channels(TrackType *pTrack) -> TrackIterRange< TrackType >
Definition: Track.h:1467
ProjectSettings::Get
static ProjectSettings & Get(AudacityProject &project)
Definition: ProjectSettings.cpp:40
BackgroundCell::mZoomHandle
std::weak_ptr< ZoomHandle > mZoomHandle
Definition: BackgroundCell.h:63
ZoomHandle.h
CommonTrackView::ContextMenuDelegate
std::shared_ptr< TrackPanelCell > ContextMenuDelegate() override
Definition: CommonTrackView.cpp:83
ZoomHandle::HitAnywhere
static UIHandlePtr HitAnywhere(std::weak_ptr< ZoomHandle > &holder)
Definition: ZoomHandle.cpp:65
CommonTrackView::mSelectHandle
std::weak_ptr< SelectHandle > mSelectHandle
Definition: CommonTrackView.h:45
ToolCodes::multiTool
@ multiTool
Definition: ProjectSettings.h:40
ZoomHandle::HitTest
static UIHandlePtr HitTest(std::weak_ptr< ZoomHandle > &holder, const wxMouseState &state)
Definition: ZoomHandle.cpp:73
BackgroundCell::Get
static BackgroundCell & Get(AudacityProject &project)
Definition: BackgroundCell.cpp:93
CommonTrackView::HitTest
std::vector< UIHandlePtr > HitTest(const TrackPanelMouseState &, const AudacityProject *pProject) final override
Definition: CommonTrackView.cpp:30
UIHandlePtr
std::shared_ptr< UIHandle > UIHandlePtr
Definition: CellularPanel.h:28
ToolCodes::slideTool
@ slideTool
Definition: ProjectSettings.h:39
TrackControls.h
CommonTrackView.h
CommonTrackView::GetMinimizedHeight
virtual int GetMinimizedHeight() const override
Definition: CommonTrackView.cpp:88
SelectHandle::HitTest
static UIHandlePtr HitTest(std::weak_ptr< SelectHandle > &holder, const TrackPanelMouseState &state, const AudacityProject *pProject, const std::shared_ptr< TrackView > &pTrackView)
Definition: SelectHandle.cpp:362
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:112
TrackPanelMouseState
Definition: TrackPanelMouseEvent.h:28
BackgroundCell.h
CommonTrackView::DetailedHitTest
virtual std::vector< UIHandlePtr > DetailedHitTest(const TrackPanelMouseState &, const AudacityProject *pProject, int currentTool, bool bMultiTool)=0
settings
static Settings & settings()
Definition: TrackInfo.cpp:87
TimeShiftHandle::HitAnywhere
static UIHandlePtr HitAnywhere(std::weak_ptr< TimeShiftHandle > &holder, const std::shared_ptr< Track > &pTrack, bool gripHit)
Definition: TimeShiftHandle.cpp:65
TrackPanelMouseState::state
wxMouseState & state
Definition: TrackPanelMouseEvent.h:38