Audacity 3.2.0
ZoomInfo.h
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 ZoomInfo.h
6
7 Paul Licameli split from ViewInfo.h
8
9**********************************************************************/
10
11#ifndef __AUDACITY_ZOOM_INFO__
12#define __AUDACITY_ZOOM_INFO__
13
14#include <cstdint>
15#include <vector>
16
17class AudacityProject;
18
19// See big pictorial comment in TrackPanel.cpp for explanation of these numbers
20enum : int {
21 // Constants related to x coordinates in the track panel
24
29
31};
32
33// The subset of ViewInfo information (other than selection)
34// that is sufficient for purposes of TrackArtist,
35// and for computing conversions between track times and pixel positions.
36class SCREEN_GEOMETRY_API ZoomInfo /* not final */
37 // Note that ViewInfo inherits from ZoomInfo but there are no virtual functions.
38 // That's okay if we pass always by reference and never copy, suffering "slicing."
39{
40public:
41 using int64 = std::int64_t;
42
46 ZoomInfo(double start, double pixelsPerSecond);
47 ~ZoomInfo();
48
49 // Be sure we don't slice
50 ZoomInfo(const ZoomInfo&) = delete;
51 ZoomInfo& operator= (const ZoomInfo&) = delete;
52
54 double hpos;
55
56protected:
58 double zoom;
59
60public:
61 // do NOT use this once to convert a pixel width to a duration!
62 // Instead, call twice to convert start and end times,
63 // and take the difference.
64 // origin specifies the pixel corresponding to time h
65 double PositionToTime(int64 position,
66 int64 origin = 0
67 , bool ignoreFisheye = false
68 ) const;
69
70 // do NOT use this once to convert a duration to a pixel width!
71 // Instead, call twice to convert start and end positions,
72 // and take the difference.
73 // origin specifies the pixel corresponding to time h
74 int64 TimeToPosition(double time,
75 int64 origin = 0
76 , bool ignoreFisheye = false
77 ) const;
78
79 // This always ignores the fisheye. Use with caution!
80 // You should prefer to call TimeToPosition twice, for endpoints, and take the difference!
81 double TimeRangeToPixelWidth(double timeRange) const;
82
83 double OffsetTimeByPixels(double time, int64 offset, bool ignoreFisheye = false) const
84 {
85 return PositionToTime(offset + TimeToPosition(time, ignoreFisheye), ignoreFisheye);
86 }
87
88 int GetWidth() const { return mWidth; }
89 void SetWidth( int width ) { mWidth = width; }
90
91 int GetVRulerWidth() const { return mVRulerWidth; }
92 void SetVRulerWidth( int width ) { mVRulerWidth = width; }
94
95 // The x-coordinate of the start of the displayed track data
96 int GetLeftOffset() const
97 { return GetVRulerOffset() + GetVRulerWidth() + 1; }
98 // The number of pixel columns for display of track data
100 {
101 return
102 std::max( 0, GetWidth() - ( GetLeftOffset() + kRightMargin ) );
103 }
104
105 // Returns the time corresponding to the pixel column one past the track area
106 // (ignoring any fisheye)
107 double GetScreenEndTime() const
108 {
109 auto width = GetTracksUsableWidth();
110 return PositionToTime(width, 0, true);
111 }
112
113 bool ZoomInAvailable() const;
114 bool ZoomOutAvailable() const;
115
116 static double GetDefaultZoom()
117 { return 44100.0 / 512.0; }
118
119
120 // Limits zoom to certain bounds
121 void SetZoom(double pixelsPerSecond);
122
123 // This function should not be used to convert positions to times and back
124 // Use TimeToPosition and PositionToTime and OffsetTimeByPixels instead
125 double GetZoom() const;
126
130 double GetAbsoluteOffset(double offset) const;
131
132 static double GetMaxZoom( );
133 static double GetMinZoom( );
134
135 // Limits zoom to certain bounds
136 // multipliers above 1.0 zoom in, below out
137 void ZoomBy(double multiplier);
138
139 struct Interval {
140 int64 position; double averageZoom; bool inFisheye;
141 Interval(int64 p, double z, bool i)
142 : position(p), averageZoom(z), inFisheye(i) {}
143 };
144 typedef std::vector<Interval> Intervals;
145
146 // Find an increasing sequence of pixel positions. Each is the start
147 // of an interval, or is the end position.
148 // Each of the disjoint intervals should be drawn
149 // separately.
150 // It is guaranteed that there is at least one entry and the position of the
151 // first entry equals origin.
152 // @param origin specifies the pixel position corresponding to time ViewInfo::h.
153 Intervals FindIntervals(int64 width, int64 origin = 0) const;
154
158
160 };
162 { return HIDDEN; } // stub
163
164 // Return true if the mouse position is anywhere in the fisheye
165 // origin specifies the pixel corresponding to time h
166 bool InFisheye(int64 /*position*/, int64 = 0) const
167 {return false;} // stub
168
169 // These accessors ignore the fisheye hiding state.
170 // Inclusive:
172 {return 0;} // stub
173 // Exclusive:
175 {return 0;} // stub
176
177 int mWidth{ 0 };
178 int mVRulerWidth{ 36 };
179};
180
181#endif
@ kRightMargin
Definition: ZoomInfo.h:28
@ kTrackInfoWidth
Definition: ZoomInfo.h:30
@ kRightInset
Definition: ZoomInfo.h:26
@ kShadowThickness
Definition: ZoomInfo.h:23
@ kBorderThickness
Definition: ZoomInfo.h:22
@ kLeftMargin
Definition: ZoomInfo.h:27
@ kLeftInset
Definition: ZoomInfo.h:25
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
ZoomInfo(const ZoomInfo &)=delete
FisheyeState
Definition: ZoomInfo.h:155
@ PINNED
Definition: ZoomInfo.h:157
@ HIDDEN
Definition: ZoomInfo.h:156
@ NUM_STATES
Definition: ZoomInfo.h:159
static double GetDefaultZoom()
Definition: ZoomInfo.h:116
void SetWidth(int width)
Definition: ZoomInfo.h:89
bool InFisheye(int64, int64=0) const
Definition: ZoomInfo.h:166
int GetWidth() const
Definition: ZoomInfo.h:88
std::vector< Interval > Intervals
Definition: ZoomInfo.h:144
double GetScreenEndTime() const
Definition: ZoomInfo.h:107
double zoom
pixels per second
Definition: ZoomInfo.h:58
int GetVRulerOffset() const
Definition: ZoomInfo.h:93
std::int64_t int64
Definition: ZoomInfo.h:41
double OffsetTimeByPixels(double time, int64 offset, bool ignoreFisheye=false) const
Definition: ZoomInfo.h:83
int64 GetFisheyeRightBoundary(int64=0) const
Definition: ZoomInfo.h:174
void SetVRulerWidth(int width)
Definition: ZoomInfo.h:92
int GetLeftOffset() const
Definition: ZoomInfo.h:96
int GetTracksUsableWidth() const
Definition: ZoomInfo.h:99
int64 GetFisheyeLeftBoundary(int64=0) const
Definition: ZoomInfo.h:171
double hpos
Leftmost visible timeline position in seconds.
Definition: ZoomInfo.h:54
int GetVRulerWidth() const
Definition: ZoomInfo.h:91
FisheyeState GetFisheyeState() const
Definition: ZoomInfo.h:161
Interval(int64 p, double z, bool i)
Definition: ZoomInfo.h:141
double averageZoom
Definition: ZoomInfo.h:140