Audacity 3.2.0
TrackVRulerControls.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3Audacity: A Digital Audio Editor
4
5TrackVRulerControls.cpp
6
7Paul Licameli split from TrackPanel.cpp
8
9**********************************************************************/
10
11
12#include "TrackVRulerControls.h"
13
14#include "TrackView.h"
15
16#include "AColor.h"
17#include "Track.h"
18#include "../../TrackArtist.h"
19#include "../../TrackPanelDrawingContext.h"
20#include "ViewInfo.h"
21
22#include <wx/cursor.h>
23#include <wx/dc.h>
24#include <wx/translation.h>
25
27 const std::shared_ptr<TrackView> &pTrackView )
28 : mwTrackView{ pTrackView }
29{
30}
31
33{
34}
35
37{
38 return *trackView.GetVRulerControls();
39}
40
42{
43 return *trackView.GetVRulerControls();
44}
45
46std::shared_ptr<Track> TrackVRulerControls::DoFindTrack()
47{
48 const auto pView = mwTrackView.lock();
49 if ( pView )
50 return pView->FindTrack();
51 return {};
52}
53
54std::vector<UIHandlePtr> TrackVRulerControls::HitTest
56{
57 return std::vector<UIHandlePtr>{};
58}
59
61 ( TrackPanelDrawingContext &context, const wxRect &rect_,
62 int zoomStart, int zoomEnd )
63{
64 // Draw a dashed rectangle, its right side disappearing in the black right
65 // border of the track area, which is not part of this cell but right of it.
66 auto &dc = context.dc;
67
68 dc.SetBrush(*wxTRANSPARENT_BRUSH);
69 dc.SetPen(*wxBLACK_DASHED_PEN);
70
71 wxRect rect {
72 rect_.x,
73 std::min( zoomStart, zoomEnd),
74 rect_.width,
75 1 + abs( zoomEnd - zoomStart)
76 };
77
78 dc.DrawRectangle(rect);
79}
80
82 const wxRect &rect, const wxRect &panelRect )
83{
84 // TODO: Don't use the constant kRightMargin, but somehow discover the
85 // neighboring track rectangle
86 return {
87 // Left edge of the rectangle disappears in the vertical line at
88 // left edge of the ruler
89 rect.x,
90 rect.y,
91 // Extend the dashed rectangle right up to the track border
92 (panelRect.width - kRightMargin + kBorderThickness) - rect.x,
93 rect.height
94 };
95}
96
99 const wxRect &rect_, unsigned iPass )
100{
101 // Common initial part of drawing for all subtypes
102 if ( iPass == TrackArtist::PassMargins ) {
103 auto rect = rect_;
104 --rect.width;
105
106 auto dc = &context.dc;
107
108
109 // Paint the background
110 auto pTrack = FindTrack();
111 AColor::MediumTrackInfo(dc, pTrack && pTrack->GetSelected() );
112 dc->DrawRectangle( rect );
113
114 // Stroke the left border
115 dc->SetPen(*wxBLACK_PEN);
116 {
117 const auto left = rect.GetLeft();
118 AColor::Line( *dc, left, rect.GetTop(), left, rect.GetBottom() );
119 }
120 }
121}
122
125 const wxRect &rect, const wxRect &, unsigned iPass )
126{
127 // Common area change for all subclasses when drawing the controls
128 // A bevel extends below one pixel outside of the hit-test area
129 if ( iPass == TrackArtist::PassControls )
130 return { rect.x, rect.y, rect.width, rect.height + 1 };
131 else
132 return rect;
133}
int min(int a, int b)
declares abstract base class Track, TrackList, and iterators over TrackList
@ kRightMargin
Definition: ZoomInfo.h:28
@ 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
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
std::shared_ptr< Track > FindTrack()
std::weak_ptr< TrackView > mwTrackView
static TrackVRulerControls & Get(TrackView &)
void Draw(TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass) override
TrackVRulerControls(const std::shared_ptr< TrackView > &pTrackView)
static void DrawZooming(TrackPanelDrawingContext &context, const wxRect &rect, int zoomStart, int zoomEnd)
wxRect DrawingArea(TrackPanelDrawingContext &, const wxRect &rect, const wxRect &panelRect, unsigned iPass) override
std::vector< UIHandlePtr > HitTest(const TrackPanelMouseState &state, const AudacityProject *pProject) override
static wxRect ZoomingArea(const wxRect &rect, const wxRect &panelRect)
std::shared_ptr< Track > DoFindTrack() override
std::shared_ptr< TrackVRulerControls > GetVRulerControls()
Definition: TrackView.cpp:146