Audacity 3.2.0
TimeTrackVRulerControls.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3Audacity: A Digital Audio Editor
4
5TimeTrackVRulerControls.cpp
6
7Paul Licameli split from TrackPanel.cpp
8
9**********************************************************************/
10
11
14
15#include "../../../HitTestResult.h"
16
17#include "AColor.h"
18#include "AllThemeResources.h"
19#include "ProjectHistory.h"
20#include "../../../RefreshCode.h"
21#include "Theme.h"
22#include "../../../TimeTrack.h"
23#include "../../../TrackArtist.h"
24#include "../../../TrackPanelDrawingContext.h"
25#include "../../../TrackPanelMouseEvent.h"
26#include "../../../UIHandle.h"
27#include "../../../widgets/Ruler.h"
28
30{
31}
32
33namespace {
35 {
36 static Ruler theRuler;
37 return theRuler;
38 }
39}
40
41std::vector<UIHandlePtr> TimeTrackVRulerControls::HitTest(
42 const TrackPanelMouseState &st,
43 const AudacityProject *pProject)
44{
45 std::vector<UIHandlePtr> results;
46
47 if ( st.state.GetX() <= st.rect.GetRight() - kGuard ) {
48 auto pTrack = FindTrack()->SharedPointer<TimeTrack>( );
49 if (pTrack) {
50 auto result = std::make_shared<TimeTrackVZoomHandle>(
51 pTrack, st.rect, st.state.m_y );
52 result = AssignUIHandlePtr(mVZoomHandle, result);
53 results.push_back(result);
54 }
55 }
56
57 auto more = TrackVRulerControls::HitTest(st, pProject);
58 std::copy(more.begin(), more.end(), std::back_inserter(results));
59
60 return results;
61}
62
65 const wxRect &rect_, unsigned iPass )
66{
67 TrackVRulerControls::Draw( context, rect_, iPass );
68
69 // Draw on a later pass because the bevel overpaints one pixel
70 // out of bounds on the bottom
71
72 if ( iPass == TrackArtist::PassControls ) {
73 auto t = FindTrack();
74 if ( !t )
75 return;
76
77 auto rect = rect_;
78 --rect.width;
79 --rect.height;
80
81 auto dc = &context.dc;
82 wxRect bev = rect;
83 bev.Inflate(-1, 0);
84 bev.width += 1;
85 AColor::BevelTrackInfo(*dc, true, bev);
86
87 // Right align the ruler
88 wxRect rr = rect;
89 rr.width--;
90 if (t && t->vrulerSize.first < rect.GetWidth()) {
91 int adj = rr.GetWidth() - t->vrulerSize.first;
92 rr.x += adj;
93 rr.width -= adj;
94 }
95
96 UpdateRuler(rr);
97
98 auto vruler = &ruler();
99
100 vruler->SetTickColour( theTheme.Colour( clrTrackPanelText ));
101 vruler->Draw(*dc);
102 }
103}
104
105void TimeTrackVRulerControls::UpdateRuler( const wxRect &rect )
106{
107 const auto tt = std::static_pointer_cast< TimeTrack >( FindTrack() );
108 if (!tt)
109 return;
110 auto vruler = &ruler();
111
112 float min, max;
113 min = tt->GetRangeLower() * 100.0;
114 max = tt->GetRangeUpper() * 100.0;
115
116 vruler->SetDbMirrorValue( 0.0 );
117 vruler->SetBounds(rect.x, rect.y, rect.x + rect.width, rect.y + rect.height-1);
118 vruler->SetOrientation(wxVERTICAL);
119 vruler->SetRange(max, min);
120 vruler->SetFormat((tt->GetDisplayLog()) ? Ruler::RealLogFormat : Ruler::RealFormat);
121 vruler->SetUnits({});
122 vruler->SetLabelEdges(false);
123 vruler->SetLog(tt->GetDisplayLog());
124
125 vruler->GetMaxSize( &tt->vrulerSize.first, &tt->vrulerSize.second );
126}
int min(int a, int b)
THEME_API Theme theTheme
Definition: Theme.cpp:82
const int kGuard
std::shared_ptr< Subclass > AssignUIHandlePtr(std::weak_ptr< Subclass > &holder, const std::shared_ptr< Subclass > &pNew)
Definition: UIHandle.h:151
static void BevelTrackInfo(wxDC &dc, bool up, const wxRect &r, bool highlight=false)
Definition: AColor.cpp:340
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:89
std::shared_ptr< Track > FindTrack()
Used to display a Ruler.
Definition: Ruler.h:26
@ RealFormat
Definition: Ruler.h:31
@ RealLogFormat
Definition: Ruler.h:32
wxColour & Colour(int iIndex)
A kind of Track used to 'warp time'.
Definition: TimeTrack.h:24
void Draw(TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass) override
std::weak_ptr< TimeTrackVZoomHandle > mVZoomHandle
void UpdateRuler(const wxRect &rect) override
std::vector< UIHandlePtr > HitTest(const TrackPanelMouseState &state, const AudacityProject *) override
void Draw(TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass) override
std::vector< UIHandlePtr > HitTest(const TrackPanelMouseState &state, const AudacityProject *pProject) override