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**********************************************************************/
11
12#include "AColor.h"
13#include "ChannelAttachments.h"
14#include "TrackArtist.h"
18#include "HitTestResult.h"
19#include "ViewInfo.h"
21
22#include <wx/dc.h>
23#include <wx/mousestate.h>
24
26 const std::shared_ptr<Channel> &channel
27) : CommonChannelCell{ channel }
28{}
29
30std::vector<UIHandlePtr> TrackPanelResizerCell::HitTest
31(const TrackPanelMouseState &st, const AudacityProject *pProject)
32{
33 (void)pProject;// Compiler food
34 std::vector<UIHandlePtr> results;
35 if (const auto pChannel = FindChannel()) {
36 auto result =
37 std::make_shared<TrackPanelResizeHandle>(pChannel, st.state.m_y);
38 result = AssignUIHandlePtr(mResizeHandle, result);
39 results.push_back(result);
40 }
41 return results;
42}
43
46 const wxRect &rect, unsigned iPass )
47{
48 if (iPass == TrackArtist::PassMargins) {
49 if (const auto pChannel = FindChannel()) {
50 const auto pTrack =
51 dynamic_cast<Track *>(&pChannel->GetChannelGroup());
52 if (!pTrack)
53 return;
54 auto dc = &context.dc;
55 const auto &channels = pTrack->Channels();
56 const bool last = (pChannel == *channels.rbegin());
57 if (last) {
58 // Fill in separator area below a track
60 dc->DrawRectangle( rect );
61 }
62 else {
63 // Area between channels of a group
64 // Paint the channel separator over (what would be) the lower border
65 // of this channel, down to and including the upper border of the
66 // next channel
67
68 ADCChanger cleanup{ dc };
69
70 // Paint the left part of the background
71 const auto artist = TrackArtist::Get(context);
72 auto labelw = artist->pZoomInfo->GetLeftOffset() - 1;
73 AColor::MediumTrackInfo( dc, pTrack->GetSelected() );
74 dc->DrawRectangle(
75 rect.GetX(), rect.GetY(), labelw, rect.GetHeight() );
76
77 // Stroke the left border
78 dc->SetPen(*wxBLACK_PEN);
79 {
80 const auto left = rect.GetLeft();
81 AColor::Line( *dc, left, rect.GetTop(), left, rect.GetBottom() );
82 }
83
85
86 wxRect rec{ rect };
87 rec.width -= labelw - rec.x;
88 rec.x = labelw;
89
90 dc->DrawRectangle( wxRect( rec ).Inflate( 0, -kBorderThickness ) );
91
92 // These lines stroke over what is otherwise "border" of each
93 // channel
94 dc->SetBrush(*wxTRANSPARENT_BRUSH);
95 dc->SetPen(*wxBLACK_PEN);
96 const auto left = rec.GetLeft();
97 const auto right = rec.GetRight();
98 const auto top = rec.GetTop();
99 const auto bottom = rec.GetBottom();
100 AColor::Line( *dc, left, top, right, top );
101 AColor::Line( *dc, left, bottom, right, bottom );
102 }
103 }
104 }
105}
106
108
110 [](Track &track){
111 return std::make_shared<ResizerCellAttachments>(track,
112 [](Track &track, size_t iChannel) {
113 // ChannelAttachments promises this precondition
114 assert(iChannel <= track.NChannels());
115 return std::make_shared<TrackPanelResizerCell>(
116 track.GetChannel(iChannel));
117 }
118 );
119 }
120};
121
123 ChannelGroup &group, size_t iChannel)
124{
125 auto &track = static_cast<Track&>(group);
127}
128
130{
131 return GetFromChannelGroup(channel.GetChannelGroup(),
132 channel.GetChannelIndex());
133}
134
136{
137 return Get(const_cast<Channel &>(channel));
138}
Adapts TrackAttachment interface with extra channel index argument.
static const AttachedTrackObjects::RegisteredFactory key
std::shared_ptr< Subclass > AssignUIHandlePtr(std::weak_ptr< Subclass > &holder, const std::shared_ptr< Subclass > &pNew)
Definition: UIHandle.h:164
@ 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:429
static void TrackPanelBackground(wxDC *dc, bool selected)
Definition: AColor.cpp:446
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.
static Attachment & Get(const AttachedTrackObjects::RegisteredFactory &key, Track &track, size_t iChannel)
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:320
ChannelGroup & GetChannelGroup()
Channel object's lifetime is assumed to be nested in its Track's.
Definition: Channel.cpp:43
size_t GetChannelIndex() const
Definition: Channel.cpp:25
Client code makes static instance from a factory of attachments; passes it to Get or Find as a retrie...
Definition: ClientData.h:275
auto FindChannel() -> std::shared_ptr< Subtype >
May return null.
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:110
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
static TrackPanelResizerCell & GetFromChannelGroup(ChannelGroup &group, size_t iChannel)