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 "../../ui/ChannelView.h"
20#include "ProjectHistory.h"
21#include "../../../RefreshCode.h"
22#include "Theme.h"
23#include "TimeTrack.h"
24#include "../../../TrackArtist.h"
25#include "../../../TrackPanelDrawingContext.h"
26#include "../../../TrackPanelMouseEvent.h"
27#include "../../../UIHandle.h"
28#include "../../../widgets/Ruler.h"
29#include "../../../widgets/LinearUpdater.h"
30#include "../../../widgets/LogarithmicUpdater.h"
31#include "../../../widgets/RealFormat.h"
32
34{
35}
36
37std::shared_ptr<TimeTrack> TimeTrackVRulerControls::FindTimeTrack()
38{
39 return FindChannel<TimeTrack>();
40}
41
42namespace {
44 {
45 static Ruler theRuler{
47 };
48 return theRuler;
49 }
50}
51
52std::vector<UIHandlePtr> TimeTrackVRulerControls::HitTest(
53 const TrackPanelMouseState &st,
54 const AudacityProject *pProject)
55{
56 std::vector<UIHandlePtr> results;
57
58 if ( st.state.GetX() <= st.rect.GetRight() - kGuard ) {
59 if (const auto pTrack = FindTimeTrack()) {
60 auto result = std::make_shared<TimeTrackVZoomHandle>(
61 pTrack, st.rect, st.state.m_y );
62 result = AssignUIHandlePtr(mVZoomHandle, result);
63 results.push_back(result);
64 }
65 }
66
67 auto more = ChannelVRulerControls::HitTest(st, pProject);
68 std::copy(more.begin(), more.end(), std::back_inserter(results));
69
70 return results;
71}
72
75 const wxRect &rect_, unsigned iPass)
76{
77 ChannelVRulerControls::Draw(context, rect_, iPass);
78
79 // Draw on a later pass because the bevel overpaints one pixel
80 // out of bounds on the bottom
81
82 if (iPass == TrackArtist::PassControls) {
83 auto t = FindTimeTrack();
84 if (!t)
85 return;
86
87 auto rect = rect_;
88 --rect.width;
89 --rect.height;
90
91 auto dc = &context.dc;
92
93 // Right align the ruler
94 wxRect rr = rect;
95 rr.width--;
96 const auto &size =
97 ChannelView::Get(*static_cast<TimeTrack*>(t.get())).vrulerSize;
98 if (size.first < rect.GetWidth()) {
99 int adj = rr.GetWidth() - size.first;
100 rr.x += adj;
101 rr.width -= adj;
102 }
103
104 UpdateRuler(rr);
105
106 auto vruler = &ruler();
107
108 vruler->SetTickColour(theTheme.Colour(clrTrackPanelText));
109 vruler->Draw(*dc);
110 }
111}
112
114{
115 const auto tt = FindTimeTrack();
116 if (!tt)
117 return;
118 auto vruler = &ruler();
119
120 float min, max;
121 min = tt->GetRangeLower() * 100.0;
122 max = tt->GetRangeUpper() * 100.0;
123
124 vruler->SetDbMirrorValue( 0.0 );
125 vruler->SetBounds(
126 rect.x, rect.y, rect.x + rect.width, rect.y + rect.height - 1);
127 vruler->SetOrientation(wxVERTICAL);
128 vruler->SetRange(max, min);
129 vruler->SetFormat(tt->GetDisplayLog()
132 vruler->SetUnits({});
133 vruler->SetLabelEdges(false);
134 if (tt->GetDisplayLog())
135 vruler->SetUpdater(&LogarithmicUpdater::Instance());
136 else
137 vruler->SetUpdater(&LinearUpdater::Instance());
138
139 auto &size = ChannelView::Get(*tt).vrulerSize;
140 vruler->GetMaxSize(&size.first, &size.second);
141}
const int kGuard
int min(int a, int b)
THEME_API Theme theTheme
Definition: Theme.cpp:82
std::shared_ptr< Subclass > AssignUIHandlePtr(std::weak_ptr< Subclass > &holder, const std::shared_ptr< Subclass > &pNew)
Definition: UIHandle.h:164
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::vector< UIHandlePtr > HitTest(const TrackPanelMouseState &state, const AudacityProject *pProject) override
static ChannelView & Get(Channel &channel)
std::pair< int, int > vrulerSize
Definition: ChannelView.h:129
static const LinearUpdater & Instance()
static const LogarithmicUpdater & Instance()
static const RealFormat & LinearInstance()
Definition: RealFormat.cpp:14
static const RealFormat & LogInstance()
Definition: RealFormat.cpp:20
Used to display a Ruler.
Definition: Ruler.h:34
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
std::shared_ptr< TimeTrack > FindTimeTrack()
virtual void Draw(TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass)
void copy(const T *src, T *dst, int32_t n)
Definition: VectorOps.h:40