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  #if 0
56  // Sliding applies in more than one track type.
57  if ( !isMultiTool && currentTool == slideTool ) {
59  mTimeShiftHandle, FindTrack(), false);
60  if (result)
61  results.push_back(result);
62  }
63  #endif
64 
65  // Let the multi-tool right-click handler apply only in default of all
66  // other detailed hits.
67  if ( isMultiTool ) {
68  result = ZoomHandle::HitTest(
69  BackgroundCell::Get( *pProject ).mZoomHandle, st.state);
70  if (result)
71  results.push_back(result);
72  }
73 
74  // Finally, default of all is adjustment of the selection box.
75  if ( isMultiTool || currentTool == selectTool ) {
76  result = SelectHandle::HitTest(
77  mSelectHandle, st, pProject, shared_from_this() );
78  if (result)
79  results.push_back(result);
80  }
81 
82  return results;
83 }
84 
85 std::shared_ptr<TrackPanelCell> CommonTrackView::ContextMenuDelegate()
86 {
87  return TrackControls::Get( *FindTrack() ).shared_from_this();
88 }
89 
91 {
92  auto height = TrackInfo::MinimumTrackHeight();
93  const auto pTrack = FindTrack();
94  auto channels = TrackList::Channels(pTrack->SubstituteOriginalTrack().get());
95  auto nChannels = channels.size();
96  auto begin = channels.begin();
97  auto index =
98  std::distance(begin, std::find(begin, channels.end(), pTrack.get()));
99  return (height * (index + 1) / nChannels) - (height * index / nChannels);
100 }
TimeShiftHandle.h
ToolCodes::selectTool
@ selectTool
Definition: ProjectSettings.h:40
ToolCodes
Definition: ProjectSettings.h:36
CommonTrackView::mTimeShiftHandle
std::weak_ptr< TimeShiftHandle > mTimeShiftHandle
Definition: CommonTrackView.h:48
TrackInfo::MinimumTrackHeight
AUDACITY_DLL_API unsigned MinimumTrackHeight()
Definition: TrackInfo.cpp:195
TrackControls::Get
static TrackControls & Get(Track &track)
Definition: TrackControls.cpp:25
ToolCodes::zoomTool
@ zoomTool
Definition: ProjectSettings.h:43
CommonTrackPanelCell::FindTrack
std::shared_ptr< Track > FindTrack()
Definition: CommonTrackPanelCell.h:46
TrackList::Channels
static auto Channels(TrackType *pTrack) -> TrackIterRange< TrackType >
Definition: Track.h:1484
ProjectSettings::Get
static ProjectSettings & Get(AudacityProject &project)
Definition: ProjectSettings.cpp:44
BackgroundCell::mZoomHandle
std::weak_ptr< ZoomHandle > mZoomHandle
Definition: BackgroundCell.h:67
ZoomHandle.h
CommonTrackView::ContextMenuDelegate
std::shared_ptr< TrackPanelCell > ContextMenuDelegate() override
Definition: CommonTrackView.cpp:85
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:44
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:97
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
TrackControls.h
CommonTrackView.h
CommonTrackView::GetMinimizedHeight
virtual int GetMinimizedHeight() const override
Definition: CommonTrackView.cpp:90
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:92
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:86
AColor.h
TimeShiftHandle::HitAnywhere
static UIHandlePtr HitAnywhere(std::weak_ptr< TimeShiftHandle > &holder, const std::shared_ptr< Track > &pTrack, bool gripHit)
Definition: TimeShiftHandle.cpp:80
TrackPanelMouseState::state
wxMouseState & state
Definition: TrackPanelMouseEvent.h:38