Audacity  3.0.3
TrackVRulerControls.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3 Audacity: A Digital Audio Editor
4 
5 TrackVRulerControls.cpp
6 
7 Paul 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 
46 std::shared_ptr<Track> TrackVRulerControls::DoFindTrack()
47 {
48  const auto pView = mwTrackView.lock();
49  if ( pView )
50  return pView->FindTrack();
51  return {};
52 }
53 
54 std::vector<UIHandlePtr> TrackVRulerControls::HitTest
55 (const TrackPanelMouseState &, const AudacityProject *)
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 
98  TrackPanelDrawingContext &context,
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 }
TrackVRulerControls.h
TrackView.h
TrackVRulerControls::DoFindTrack
std::shared_ptr< Track > DoFindTrack() override
Definition: TrackVRulerControls.cpp:46
TrackVRulerControls::TrackVRulerControls
TrackVRulerControls(const std::shared_ptr< TrackView > &pTrackView)
Definition: TrackVRulerControls.cpp:26
CommonTrackPanelCell::FindTrack
std::shared_ptr< Track > FindTrack()
Definition: CommonTrackPanelCell.h:46
TrackPanelDrawingContext
Definition: TrackPanelDrawingContext.h:22
AColor::Line
static void Line(wxDC &dc, wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
Definition: AColor.cpp:109
kBorderThickness
@ kBorderThickness
Definition: ZoomInfo.h:28
TrackPanelDrawingContext::dc
wxDC & dc
Definition: TrackPanelDrawingContext.h:23
TrackVRulerControls::DrawingArea
wxRect DrawingArea(TrackPanelDrawingContext &, const wxRect &rect, const wxRect &panelRect, unsigned iPass) override
Definition: TrackVRulerControls.cpp:123
TrackVRulerControls
Definition: TrackVRulerControls.h:25
TrackVRulerControls::ZoomingArea
static wxRect ZoomingArea(const wxRect &rect, const wxRect &panelRect)
Definition: TrackVRulerControls.cpp:81
TrackVRulerControls::mwTrackView
std::weak_ptr< TrackView > mwTrackView
Definition: TrackVRulerControls.h:64
TrackVRulerControls::Get
static TrackVRulerControls & Get(TrackView &)
Definition: TrackVRulerControls.cpp:36
TrackView::GetVRulerControls
std::shared_ptr< TrackVRulerControls > GetVRulerControls()
Definition: TrackView.cpp:131
TrackArtist::PassControls
@ PassControls
Definition: TrackArtist.h:84
TrackVRulerControls::HitTest
std::vector< UIHandlePtr > HitTest(const TrackPanelMouseState &state, const AudacityProject *pProject) override
Definition: TrackVRulerControls.cpp:55
ViewInfo.h
AColor::MediumTrackInfo
static void MediumTrackInfo(wxDC *dc, bool selected)
Definition: AColor.cpp:341
min
int min(int a, int b)
Definition: CompareAudioCommand.cpp:106
TrackView
Definition: TrackView.h:24
TrackVRulerControls::DrawZooming
static void DrawZooming(TrackPanelDrawingContext &context, const wxRect &rect, int zoomStart, int zoomEnd)
Definition: TrackVRulerControls.cpp:61
TrackVRulerControls::Draw
void Draw(TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass) override
Definition: TrackVRulerControls.cpp:97
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
kRightMargin
@ kRightMargin
Definition: ZoomInfo.h:34
TrackArtist::PassMargins
@ PassMargins
Definition: TrackArtist.h:82
AColor.h
TrackVRulerControls::~TrackVRulerControls
virtual ~TrackVRulerControls()=0
Definition: TrackVRulerControls.cpp:32