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
153 void ShowTrack(const Track &track);
154
156 double GetZoomOfToFit() const;
157
160 void ZoomFitHorizontally();
161
164 void ZoomFitVertically();
165
166 void ExpandAllTracks();
167 void CollapseAllTracks();
168
171 void UpdateScrollbarsForTracks();
172
173 void HandleResize();
174
175 void ReinitScrollbars() { mbInitializingScrollbar = true; }
176
177 void Redraw();
178
180 void SetToDefaultSize();
181
182private:
183 // How many pixels are covered by the period from lowermost scrollable time, to the given time:
184 // PRL: Bug1197: we seem to need to compute all in double, to avoid differing results on Mac
185 double PixelWidthBeforeTime(double scrollto) const;
186
187 void FinishAutoScroll();
188
189 void OnUndoPushedModified();
190 void OnUndoRedo();
191 void OnUndoReset();
192
194 std::unique_ptr<ViewportCallbacks> mpCallbacks{};
195
199 ;
200
201 double total{ 1.0 }; // total width in secs
202
203 // Current horizontal scroll bar positions, in pixels
204 wxInt64 sbarH{ 0 };
205 wxInt64 sbarScreen{ 1 };
206 wxInt64 sbarTotal{ 1 };
207
208 // Internal wxScrollbar positions are only int in range, so multiply
209 // the above values with the following member to get the actual
210 // scroll bar positions as reported by the horizontal wxScrollbar's members
211 // i.e. units are scroll increments per pixel
212 double sbarScale{ 1.0 };
213
214 // Vertical scroll step
215 int scrollStep{ 16 };
216
217 bool mAutoScrolling{ false };
218 bool mbInitializingScrollbar{ false };
219};
220
221#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:122
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
Definition: Track.h:993
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:193
void ReinitScrollbars()
Definition: Viewport.h:175
const Observer::Subscription mUndoSubscription
Definition: Viewport.h:199
const Observer::Subscription mSnappingChangedSubscription
Definition: Viewport.h:198
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:196
A convenient default parameter for class template Site.
Definition: ClientData.h:28
const bool resize
Definition: Viewport.h:58
const bool rescroll
Definition: Viewport.h:56
const bool scrollbarVisibilityChanged
Definition: Viewport.h:57