Audacity 3.2.0
Viewport.h
Go to the documentation of this file.
1/**********************************************************************
2
3Audacity: A Digital Audio Editor
4
5Viewport.h
6
7Paul Licameli split from ProjectWindow.h
8
9**********************************************************************/
10
11#ifndef __AUDACITY_VIEWPORT__
12#define __AUDACITY_VIEWPORT__
13
14#include "ClientData.h"
15#include "Observer.h"
16
17class AudacityProject;
18class Track;
19class TrackList;
20
22class VIEWPORT_API ViewportCallbacks {
23public:
25
27 virtual std::pair<int, int> ViewportSize() const = 0;
28
29 virtual unsigned MinimumTrackHeight() = 0;
30 virtual bool IsTrackMinimized(const Track &track) = 0;
31 virtual void SetMinimized(Track &track, bool minimized) = 0;
32 virtual int GetTrackHeight(const Track &track) = 0;
33 virtual void SetChannelHeights(Track &track, unsigned height) = 0;
34 virtual int GetTotalHeight(const TrackList &trackList) = 0;
35
36 virtual int GetHorizontalThumbPosition() const = 0;
37 virtual int GetHorizontalThumbSize() const = 0;
38 virtual int GetHorizontalRange() const = 0;
39 virtual void SetHorizontalThumbPosition(int viewStart) = 0;
40 virtual void SetHorizontalScrollbar(int position, int thumbSize,
41 int range, int pageSize, bool refresh) = 0;
42 virtual void ShowHorizontalScrollbar(bool shown) = 0;
43
44 virtual int GetVerticalThumbPosition() const = 0;
45 virtual int GetVerticalThumbSize() const = 0;
46 virtual int GetVerticalRange() const = 0;
47 virtual void SetVerticalThumbPosition(int viewStart) = 0;
48 virtual void SetVerticalScrollbar(int position, int thumbSize,
49 int range, int pageSize, bool refresh) = 0;
50 virtual void ShowVerticalScrollbar(bool shown) = 0;
51
52 virtual void SetToDefaultSize() = 0;
53};
54
56 const bool rescroll;
58 const bool resize;
59};
60
61class VIEWPORT_API Viewport final
62 : public Observer::Publisher<ViewportMessage>
63 , public ClientData::Base
64 , public std::enable_shared_from_this<Viewport>
65{
66public:
68 static const Viewport &Get(const AudacityProject &project);
69
71 void SetCallbacks(std::unique_ptr<ViewportCallbacks> pCallbacks);
72
73 double ScrollingLowerBoundTime() const;
74
76 void DoScroll();
77
86 void ScrollToStart(bool extend);
87
96 void ScrollToEnd(bool extend);
97
98 void ScrollToTop();
99 void ScrollToBottom();
100
102 void ScrollIntoView(double pos);
103
106 void ScrollIntoView(int x);
107
110 void OnScrollLeft();
111
114 void OnScrollRight();
115
118 void OnScrollLeftButton();
119
122 void OnScrollRightButton();
123
124 void OnScroll();
125
126 // Scroll vertically. A positive argument makes the window
127 // scroll down, while a negative argument scrolls up.
128 bool ScrollUpDown(int delta);
129
130 void SetHorizontalThumb(double scrollto, bool doScroll = true);
131
133 void Zoom(double pixelsPerSecond);
134
136 void ZoomBy(double multiplier);
137
140 void ZoomAboutSelection(double multiplier);
141
143 void ZoomAboutCenter(double multiplier);
144
148 void ZoomFitHorizontallyAndShowTrack(Track *pTrack);
149
150 void ShowTrack(const Track &track);
151
153 double GetZoomOfToFit() const;
154
157 void ZoomFitHorizontally();
158
161 void ZoomFitVertically();
162
163 void ExpandAllTracks();
164 void CollapseAllTracks();
165
168 void UpdateScrollbarsForTracks();
169
170 void HandleResize();
171
172 void ReinitScrollbars() { mbInitializingScrollbar = true; }
173
174 void Redraw();
175
177 void SetToDefaultSize();
178
179private:
180 // How many pixels are covered by the period from lowermost scrollable time, to the given time:
181 // PRL: Bug1197: we seem to need to compute all in double, to avoid differing results on Mac
182 double PixelWidthBeforeTime(double scrollto) const;
183
184 void FinishAutoScroll();
185
186 void OnUndoPushedModified();
187 void OnUndoRedo();
188 void OnUndoReset();
189
191 std::unique_ptr<ViewportCallbacks> mpCallbacks{};
192
196 ;
197
198 double total{ 1.0 }; // total width in secs
199
200 // Current horizontal scroll bar positions, in pixels
201 wxInt64 sbarH{ 0 };
202 wxInt64 sbarScreen{ 1 };
203 wxInt64 sbarTotal{ 1 };
204
205 // Internal wxScrollbar positions are only int in range, so multiply
206 // the above values with the following member to get the actual
207 // scroll bar positions as reported by the horizontal wxScrollbar's members
208 // i.e. units are scroll increments per pixel
209 double sbarScale{ 1.0 };
210
211 // Vertical scroll step
212 int scrollStep{ 16 };
213
214 bool mAutoScrolling{ false };
215 bool mbInitializingScrollbar{ false };
216};
217
218#endif
Utility ClientData::Site to register hooks into a host class that attach client data.
const auto project
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
An object that sends messages to an open-ended list of subscribed callbacks.
Definition: Observer.h:108
A move-only handle representing a connection to a Publisher.
Definition: Observer.h:70
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:110
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
Definition: Track.h:850
A callback facade hiding GUI toolkit details.
Definition: Viewport.h:22
virtual int GetVerticalRange() const =0
virtual int GetHorizontalThumbSize() const =0
virtual int GetHorizontalThumbPosition() const =0
virtual int GetVerticalThumbSize() const =0
virtual void SetVerticalScrollbar(int position, int thumbSize, int range, int pageSize, bool refresh)=0
virtual ~ViewportCallbacks()
virtual int GetHorizontalRange() const =0
virtual void SetHorizontalThumbPosition(int viewStart)=0
virtual bool IsTrackMinimized(const Track &track)=0
virtual void SetVerticalThumbPosition(int viewStart)=0
virtual int GetTrackHeight(const Track &track)=0
virtual void SetToDefaultSize()=0
virtual void SetChannelHeights(Track &track, unsigned height)=0
virtual void ShowHorizontalScrollbar(bool shown)=0
virtual void ShowVerticalScrollbar(bool shown)=0
virtual void SetMinimized(Track &track, bool minimized)=0
virtual int GetVerticalThumbPosition() const =0
virtual unsigned MinimumTrackHeight()=0
virtual int GetTotalHeight(const TrackList &trackList)=0
virtual std::pair< int, int > ViewportSize() const =0
Width and height in pixels of proper viewport area (excluding scrollbars)
virtual void SetHorizontalScrollbar(int position, int thumbSize, int range, int pageSize, bool refresh)=0
AudacityProject & mProject
Definition: Viewport.h:190
void ReinitScrollbars()
Definition: Viewport.h:172
const Observer::Subscription mUndoSubscription
Definition: Viewport.h:196
const Observer::Subscription mSnappingChangedSubscription
Definition: Viewport.h:195
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:202
A convenient default parameter for class template Site.
Definition: ClientData.h:29
const bool resize
Definition: Viewport.h:58
const bool rescroll
Definition: Viewport.h:56
const bool scrollbarVisibilityChanged
Definition: Viewport.h:57