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
43 ZoomInfo(double start, double pixelsPerSecond);
44 ~ZoomInfo();
45
46 // Be sure we don't slice
47 ZoomInfo(const ZoomInfo&) PROHIBITED;
48 ZoomInfo& operator= (const ZoomInfo&) PROHIBITED;
49
50 int vpos; // vertical scroll pos
51
52 double h; // h pos in secs
53
54protected:
55 double zoom; // pixels per second
56
57public:
58 // do NOT use this once to convert a pixel width to a duration!
59 // Instead, call twice to convert start and end times,
60 // and take the difference.
61 // origin specifies the pixel corresponding to time h
62 double PositionToTime(int64 position,
63 int64 origin = 0
64 , bool ignoreFisheye = false
65 ) const;
66
67 // do NOT use this once to convert a duration to a pixel width!
68 // Instead, call twice to convert start and end positions,
69 // and take the difference.
70 // origin specifies the pixel corresponding to time h
71 int64 TimeToPosition(double time,
72 int64 origin = 0
73 , bool ignoreFisheye = false
74 ) const;
75
76 // This always ignores the fisheye. Use with caution!
77 // You should prefer to call TimeToPosition twice, for endpoints, and take the difference!
78 double TimeRangeToPixelWidth(double timeRange) const;
79
80 double OffsetTimeByPixels(double time, int64 offset, bool ignoreFisheye = false) const
81 {
82 return PositionToTime(offset + TimeToPosition(time, ignoreFisheye), ignoreFisheye);
83 }
84
85 int GetWidth() const { return mWidth; }
86 void SetWidth( int width ) { mWidth = width; }
87
88 int GetVRulerWidth() const { return mVRulerWidth; }
89 void SetVRulerWidth( int width ) { mVRulerWidth = width; }
91
92 // The x-coordinate of the start of the displayed track data
93 int GetLeftOffset() const
94 { return GetVRulerOffset() + GetVRulerWidth() + 1; }
95 // The number of pixel columns for display of track data
97 {
98 return
99 std::max( 0, GetWidth() - ( GetLeftOffset() + kRightMargin ) );
100 }
101
102 // Returns the time corresponding to the pixel column one past the track area
103 // (ignoring any fisheye)
104 double GetScreenEndTime() const
105 {
106 auto width = GetTracksUsableWidth();
107 return PositionToTime(width, 0, true);
108 }
109
110 bool ZoomInAvailable() const;
111 bool ZoomOutAvailable() const;
112
113 static double GetDefaultZoom()
114 { return 44100.0 / 512.0; }
115
116
117 // Limits zoom to certain bounds
118 void SetZoom(double pixelsPerSecond);
119
120 // This function should not be used to convert positions to times and back
121 // Use TimeToPosition and PositionToTime and OffsetTimeByPixels instead
122 double GetZoom() const;
123
124 static double GetMaxZoom( );
125 static double GetMinZoom( );
126
127 // Limits zoom to certain bounds
128 // multipliers above 1.0 zoom in, below out
129 void ZoomBy(double multiplier);
130
131 struct Interval {
132 int64 position; double averageZoom; bool inFisheye;
133 Interval(int64 p, double z, bool i)
134 : position(p), averageZoom(z), inFisheye(i) {}
135 };
136 typedef std::vector<Interval> Intervals;
137
138 // Find an increasing sequence of pixel positions. Each is the start
139 // of an interval, or is the end position.
140 // Each of the disjoint intervals should be drawn
141 // separately.
142 // It is guaranteed that there is at least one entry and the position of the
143 // first entry equals origin.
144 // @param origin specifies the pixel position corresponding to time ViewInfo::h.
145 void FindIntervals
146 (double rate, Intervals &results, int64 width, int64 origin = 0) const;
147
151
153 };
155 { return HIDDEN; } // stub
156
157 // Return true if the mouse position is anywhere in the fisheye
158 // origin specifies the pixel corresponding to time h
159 bool InFisheye(int64 /*position*/, int64 = 0) const
160 {return false;} // stub
161
162 // These accessors ignore the fisheye hiding state.
163 // Inclusive:
165 {return 0;} // stub
166 // Exclusive:
168 {return 0;} // stub
169
170 int mWidth{ 0 };
171 int mVRulerWidth{ 36 };
172};
173
174#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
FisheyeState
Definition: ZoomInfo.h:148
@ PINNED
Definition: ZoomInfo.h:150
@ HIDDEN
Definition: ZoomInfo.h:149
@ NUM_STATES
Definition: ZoomInfo.h:152
static double GetDefaultZoom()
Definition: ZoomInfo.h:113
void SetWidth(int width)
Definition: ZoomInfo.h:86
bool InFisheye(int64, int64=0) const
Definition: ZoomInfo.h:159
int GetWidth() const
Definition: ZoomInfo.h:85
std::vector< Interval > Intervals
Definition: ZoomInfo.h:136
double GetScreenEndTime() const
Definition: ZoomInfo.h:104
double zoom
Definition: ZoomInfo.h:55
int GetVRulerOffset() const
Definition: ZoomInfo.h:90
std::int64_t int64
Definition: ZoomInfo.h:41
double OffsetTimeByPixels(double time, int64 offset, bool ignoreFisheye=false) const
Definition: ZoomInfo.h:80
int64 GetFisheyeRightBoundary(int64=0) const
Definition: ZoomInfo.h:167
ZoomInfo(const ZoomInfo &) PROHIBITED
double h
Definition: ZoomInfo.h:52
void SetVRulerWidth(int width)
Definition: ZoomInfo.h:89
int GetLeftOffset() const
Definition: ZoomInfo.h:93
int GetTracksUsableWidth() const
Definition: ZoomInfo.h:96
int64 GetFisheyeLeftBoundary(int64=0) const
Definition: ZoomInfo.h:164
int GetVRulerWidth() const
Definition: ZoomInfo.h:88
FisheyeState GetFisheyeState() const
Definition: ZoomInfo.h:154
int vpos
Definition: ZoomInfo.h:50
Interval(int64 p, double z, bool i)
Definition: ZoomInfo.h:133
double averageZoom
Definition: ZoomInfo.h:132