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
37namespace {
39 {
40 static Ruler theRuler{
42 };
43 return theRuler;
44 }
45}
46
47std::vector<UIHandlePtr> TimeTrackVRulerControls::HitTest(
48 const TrackPanelMouseState &st,
49 const AudacityProject *pProject)
50{
51 std::vector<UIHandlePtr> results;
52
53 if ( st.state.GetX() <= st.rect.GetRight() - kGuard ) {
54 auto pTrack = FindTrack()->SharedPointer<TimeTrack>( );
55 if (pTrack) {
56 auto result = std::make_shared<TimeTrackVZoomHandle>(
57 pTrack, st.rect, st.state.m_y );
58 result = AssignUIHandlePtr(mVZoomHandle, result);
59 results.push_back(result);
60 }
61 }
62
63 auto more = ChannelVRulerControls::HitTest(st, pProject);
64 std::copy(more.begin(), more.end(), std::back_inserter(results));
65
66 return results;
67}
68
71 const wxRect &rect_, unsigned iPass)
72{
73 ChannelVRulerControls::Draw(context, rect_, iPass);
74
75 // Draw on a later pass because the bevel overpaints one pixel
76 // out of bounds on the bottom
77
78 if (iPass == TrackArtist::PassControls) {
79 auto t = FindTrack();
80 if (!t)
81 return;
82
83 auto rect = rect_;
84 --rect.width;
85 --rect.height;
86
87 auto dc = &context.dc;
88 wxRect bev = rect;
89 bev.Inflate(-1, 0);
90 bev.width += 1;
91 AColor::BevelTrackInfo(*dc, true, bev);
92
93 // Right align the ruler
94 wxRect rr = rect;
95 rr.width--;
96 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 = std::static_pointer_cast<TimeTrack>(FindTrack());
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:159
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:90
std::vector< UIHandlePtr > HitTest(const TrackPanelMouseState &state, const AudacityProject *pProject) override
void Draw(TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass) override
static ChannelView & Get(Channel &channel)
std::pair< int, int > vrulerSize
Definition: ChannelView.h:128
std::shared_ptr< Track > FindTrack()
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
void copy(const T *src, T *dst, int32_t n)
Definition: VectorOps.h:40