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