Audacity 3.2.0
TrackPanelResizerCell.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3Audacity: A Digital Audio Editor
4
5TrackPanelResizeHandle.cpp
6
7Paul Licameli split from TrackPanel.cpp
8
9**********************************************************************/
10
11
13
14#include "AColor.h"
15#include "Track.h"
16#include "TrackArtist.h"
20#include "HitTestResult.h"
21#include "ViewInfo.h"
23
24#include <wx/dc.h>
25#include <wx/mousestate.h>
26
28 : CommonTrackCell{ channel.GetChannelGroup(), channel.GetChannelIndex() }
29{}
30
31std::vector<UIHandlePtr> TrackPanelResizerCell::HitTest
32(const TrackPanelMouseState &st, const AudacityProject *pProject)
33{
34 (void)pProject;// Compiler food
35 std::vector<UIHandlePtr> results;
36 auto pTrack = FindTrack();
37 if (pTrack) {
38 auto result = std::make_shared<TrackPanelResizeHandle>(
39 pTrack->GetChannel(0), st.state.m_y );
40 result = AssignUIHandlePtr(mResizeHandle, result);
41 results.push_back(result);
42 }
43 return results;
44}
45
48 const wxRect &rect, unsigned iPass )
49{
50 if ( iPass == TrackArtist::PassMargins ) {
51 auto pTrack = FindTrack();
52 if ( pTrack ) {
53 auto dc = &context.dc;
54 const bool last =
55 pTrack.get() == *TrackList::Channels( pTrack.get() ).rbegin();
56 if ( last ) {
57 // Fill in separator area below a track
59 dc->DrawRectangle( rect );
60 }
61 else {
62 // Area between channels of a group
63 // Paint the channel separator over (what would be) the lower border
64 // of this channel, down to and including the upper border of the
65 // next channel
66
67 ADCChanger cleanup{ dc };
68
69 // Paint the left part of the background
70 const auto artist = TrackArtist::Get( context );
71 auto labelw = artist->pZoomInfo->GetLeftOffset() - 1;
72 AColor::MediumTrackInfo( dc, pTrack->GetSelected() );
73 dc->DrawRectangle(
74 rect.GetX(), rect.GetY(), labelw, rect.GetHeight() );
75
76 // Stroke the left border
77 dc->SetPen(*wxBLACK_PEN);
78 {
79 const auto left = rect.GetLeft();
80 AColor::Line( *dc, left, rect.GetTop(), left, rect.GetBottom() );
81 }
82
84
85 wxRect rec{ rect };
86 rec.width -= labelw - rec.x;
87 rec.x = labelw;
88
89 dc->DrawRectangle( wxRect( rec ).Inflate( 0, -kBorderThickness ) );
90
91 // These lines stroke over what is otherwise "border" of each
92 // channel
93 dc->SetBrush(*wxTRANSPARENT_BRUSH);
94 dc->SetPen(*wxBLACK_PEN);
95 const auto left = rec.GetLeft();
96 const auto right = rec.GetRight();
97 const auto top = rec.GetTop();
98 const auto bottom = rec.GetBottom();
99 AColor::Line( *dc, left, top, right, top );
100 AColor::Line( *dc, left, bottom, right, bottom );
101 }
102 }
103 }
104}
105
107
109 [](Track &track){
110 return std::make_shared<ResizerCellAttachments>(track,
111 [](Track &track, size_t iChannel) {
112 // ChannelAttachments promises this precondition
113 assert(iChannel <= track.NChannels());
114 return std::make_shared<TrackPanelResizerCell>(
115 *track.GetChannel(iChannel));
116 }
117 );
118 }
119};
120
122{
124 static_cast<Track &>(channel.GetChannelGroup()),
125 channel.GetChannelIndex());
126}
127
129{
130 return Get(const_cast<Channel &>(channel));
131}
declares abstract base class Track, TrackList, and iterators over TrackList
static const AttachedTrackObjects::RegisteredFactory key
std::shared_ptr< Subclass > AssignUIHandlePtr(std::weak_ptr< Subclass > &holder, const std::shared_ptr< Subclass > &pNew)
Definition: UIHandle.h:159
@ kBorderThickness
Definition: ZoomInfo.h:22
static void Line(wxDC &dc, wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
Definition: AColor.cpp:187
static void MediumTrackInfo(wxDC *dc, bool selected)
Definition: AColor.cpp:433
static void TrackPanelBackground(wxDC *dc, bool selected)
Definition: AColor.cpp:454
Makes temporary drawing context changes that you back out of, RAII style.
Definition: OverlayPanel.h:72
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
Holds multiple objects of the parameter type as a single attachment to Track.
Definition: Track.h:550
static Attachment & Get(const AttachedTrackObjects::RegisteredFactory &key, Track &track, size_t iChannel)
Definition: Track.h:558
virtual size_t NChannels() const =0
Report the number of channels.
std::shared_ptr< ChannelType > GetChannel(size_t iChannel)
Retrieve a channel, cast to the given type.
Definition: Channel.h:344
ChannelGroup & GetChannelGroup()
Channel object's lifetime is assumed to be nested in its Track's.
Definition: Channel.cpp:71
size_t GetChannelIndex() const
Definition: Channel.cpp:77
Client code makes static instance from a factory of attachments; passes it to Get or Find as a retrie...
Definition: ClientData.h:274
std::shared_ptr< Track > FindTrack()
static TrackArtist * Get(TrackPanelDrawingContext &)
Definition: TrackArtist.cpp:69
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:122
static auto Channels(TrackType *pTrack) -> TrackIterRange< TrackType >
Definition: Track.h:1146
std::weak_ptr< TrackPanelResizeHandle > mResizeHandle
TrackPanelResizerCell(const TrackPanelResizerCell &)=delete
void Draw(TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass) override
static TrackPanelResizerCell & Get(Channel &channel)
std::vector< UIHandlePtr > HitTest(const TrackPanelMouseState &, const AudacityProject *) override