Audacity  3.0.3
TrackPanelResizerCell.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3 Audacity: A Digital Audio Editor
4 
5 TrackPanelResizeHandle.cpp
6 
7 Paul Licameli split from TrackPanel.cpp
8 
9 **********************************************************************/
10 
11 
12 #include "TrackPanelResizerCell.h"
13 
14 #include "AColor.h"
15 #include "Track.h"
16 #include "TrackArtist.h"
18 #include "TrackPanelResizeHandle.h"
19 #include "TrackPanelMouseEvent.h"
20 #include "HitTestResult.h"
21 #include "ViewInfo.h"
22 #include "widgets/OverlayPanel.h"
23 
24 #include <wx/dc.h>
25 #include <wx/mousestate.h>
26 
28  const std::shared_ptr<Track> &pTrack )
29  : mwTrack{ pTrack }
30 {}
31 
32 std::vector<UIHandlePtr> TrackPanelResizerCell::HitTest
33 (const TrackPanelMouseState &st, const AudacityProject *pProject)
34 {
35  (void)pProject;// Compiler food
36  std::vector<UIHandlePtr> results;
37  auto pTrack = FindTrack();
38  if (pTrack) {
39  auto result = std::make_shared<TrackPanelResizeHandle>(
40  pTrack, st.state.m_y );
41  result = AssignUIHandlePtr(mResizeHandle, result);
42  results.push_back(result);
43  }
44  return results;
45 }
46 
47 std::shared_ptr<Track> TrackPanelResizerCell::DoFindTrack()
48 {
49  return mwTrack.lock();
50 }
51 
53  TrackPanelDrawingContext &context,
54  const wxRect &rect, unsigned iPass )
55 {
56  if ( iPass == TrackArtist::PassMargins ) {
57  auto pTrack = FindTrack();
58  if ( pTrack ) {
59  auto dc = &context.dc;
60  const bool last =
61  pTrack.get() == *TrackList::Channels( pTrack.get() ).rbegin();
62  if ( last ) {
63  // Fill in separator area below a track
64  AColor::TrackPanelBackground( dc, false );
65  dc->DrawRectangle( rect );
66  }
67  else {
68  // Area between channels of a group
69  // Paint the channel separator over (what would be) the lower border
70  // of this channel, down to and including the upper border of the
71  // next channel
72 
73  ADCChanger cleanup{ dc };
74 
75  // Paint the left part of the background
76  const auto artist = TrackArtist::Get( context );
77  auto labelw = artist->pZoomInfo->GetLeftOffset() - 1;
78  AColor::MediumTrackInfo( dc, pTrack->GetSelected() );
79  dc->DrawRectangle(
80  rect.GetX(), rect.GetY(), labelw, rect.GetHeight() );
81 
82  // Stroke the left border
83  dc->SetPen(*wxBLACK_PEN);
84  {
85  const auto left = rect.GetLeft();
86  AColor::Line( *dc, left, rect.GetTop(), left, rect.GetBottom() );
87  }
88 
90 
91  wxRect rec{ rect };
92  rec.width -= labelw - rec.x;
93  rec.x = labelw;
94 
95  dc->DrawRectangle( wxRect( rec ).Inflate( 0, -kBorderThickness ) );
96 
97  // These lines stroke over what is otherwise "border" of each
98  // channel
99  dc->SetBrush(*wxTRANSPARENT_BRUSH);
100  dc->SetPen(*wxBLACK_PEN);
101  const auto left = rec.GetLeft();
102  const auto right = rec.GetRight();
103  const auto top = rec.GetTop();
104  const auto bottom = rec.GetBottom();
105  AColor::Line( *dc, left, top, right, top );
106  AColor::Line( *dc, left, bottom, right, bottom );
107  }
108  }
109  }
110 }
111 
113  []( Track &track ){
114  return std::make_shared<TrackPanelResizerCell>(
115  track.shared_from_this() );
116  }
117 };
118 
120 {
121  return track.AttachedObjects::Get< TrackPanelResizerCell >( key );
122 }
123 
125 {
126  return Get( const_cast< Track & >( track ) );
127 }
TrackPanelResizerCell::DoFindTrack
std::shared_ptr< Track > DoFindTrack() override
Definition: TrackPanelResizerCell.cpp:47
TrackPanelMouseEvent.h
AColor::TrackPanelBackground
static void TrackPanelBackground(wxDC *dc, bool selected)
Definition: AColor.cpp:365
TrackArtist.h
OverlayPanel.h
key
static const AttachedTrackObjects::RegisteredFactory key
Definition: TrackPanelResizerCell.cpp:112
CommonTrackPanelCell::FindTrack
std::shared_ptr< Track > FindTrack()
Definition: CommonTrackPanelCell.h:46
TrackPanelDrawingContext
Definition: TrackPanelDrawingContext.h:22
TrackList::Channels
static auto Channels(TrackType *pTrack) -> TrackIterRange< TrackType >
Definition: Track.h:1484
AColor::Line
static void Line(wxDC &dc, wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
Definition: AColor.cpp:112
kBorderThickness
@ kBorderThickness
Definition: ZoomInfo.h:28
TrackPanelResizerCell::Draw
void Draw(TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass) override
Definition: TrackPanelResizerCell.cpp:52
TrackPanelDrawingContext::dc
wxDC & dc
Definition: TrackPanelDrawingContext.h:23
TrackPanelResizerCell::mResizeHandle
std::weak_ptr< TrackPanelResizeHandle > mResizeHandle
Definition: TrackPanelResizerCell.h:50
HitTestResult.h
ClientData::Site::RegisteredFactory
Client code makes static instance from a factory of attachments; passes it to Get or Find as a retrie...
Definition: ClientData.h:266
TrackPanelResizerCell::TrackPanelResizerCell
TrackPanelResizerCell(const TrackPanelResizerCell &)=delete
TrackArtist::Get
static TrackArtist * Get(TrackPanelDrawingContext &)
Definition: TrackArtist.cpp:79
ADCChanger
Makes temporary drawing context changes that you back out of, RAII style.
Definition: OverlayPanel.h:72
ViewInfo.h
TrackPanelResizerCell::HitTest
std::vector< UIHandlePtr > HitTest(const TrackPanelMouseState &, const AudacityProject *) override
Definition: TrackPanelResizerCell.cpp:33
AColor::MediumTrackInfo
static void MediumTrackInfo(wxDC *dc, bool selected)
Definition: AColor.cpp:344
TrackPanelDrawingContext.h
Track
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:239
TrackPanelResizeHandle.h
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
Track.h
declares abstract base class Track, TrackList, and iterators over TrackList
TrackPanelResizerCell
Definition: TrackPanelResizerCell.h:24
TrackArtist::PassMargins
@ PassMargins
Definition: TrackArtist.h:82
AssignUIHandlePtr
std::shared_ptr< Subclass > AssignUIHandlePtr(std::weak_ptr< Subclass > &holder, const std::shared_ptr< Subclass > &pNew)
Definition: UIHandle.h:151
AColor.h
TrackPanelResizerCell.h
TrackPanelMouseState::state
wxMouseState & state
Definition: TrackPanelMouseEvent.h:38
TrackPanelResizerCell::Get
static TrackPanelResizerCell & Get(Track &track)
Definition: TrackPanelResizerCell.cpp:119
TrackPanelResizerCell::mwTrack
std::weak_ptr< Track > mwTrack
Definition: TrackPanelResizerCell.h:43