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 const std::shared_ptr<Track> &pTrack )
29 : CommonTrackCell{ pTrack }
30{}
31
32std::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
49 const wxRect &rect, unsigned iPass )
50{
51 if ( iPass == TrackArtist::PassMargins ) {
52 auto pTrack = FindTrack();
53 if ( pTrack ) {
54 auto dc = &context.dc;
55 const bool last =
56 pTrack.get() == *TrackList::Channels( pTrack.get() ).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 []( Track &track ){
109 return std::make_shared<TrackPanelResizerCell>(
110 track.shared_from_this() );
111 }
112};
113
115{
116 return track.AttachedObjects::Get< TrackPanelResizerCell >( key );
117}
118
120{
121 return Get( const_cast< Track & >( track ) );
122}
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:151
@ kBorderThickness
Definition: ZoomInfo.h:27
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
Client code makes static instance from a factory of attachments; passes it to Get or Find as a retrie...
Definition: ClientData.h:266
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:225
static auto Channels(TrackType *pTrack) -> TrackIterRange< TrackType >
Definition: Track.h:1541
std::weak_ptr< TrackPanelResizeHandle > mResizeHandle
TrackPanelResizerCell(const TrackPanelResizerCell &)=delete
void Draw(TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass) override
static TrackPanelResizerCell & Get(Track &track)
std::vector< UIHandlePtr > HitTest(const TrackPanelMouseState &, const AudacityProject *) override