Audacity 3.2.0
Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
TrackPanelResizeHandle Class Referencefinal

#include <TrackPanelResizeHandle.h>

Inheritance diagram for TrackPanelResizeHandle:
[legend]
Collaboration diagram for TrackPanelResizeHandle:
[legend]

Public Member Functions

 TrackPanelResizeHandle (const std::shared_ptr< Track > &pTrack, int y)
 
TrackPanelResizeHandleoperator= (const TrackPanelResizeHandle &)=default
 
virtual ~TrackPanelResizeHandle ()
 
std::shared_ptr< TrackGetTrack () const
 
Result Click (const TrackPanelMouseEvent &event, AudacityProject *pProject) override
 
Result Drag (const TrackPanelMouseEvent &event, AudacityProject *pProject) override
 
HitTestPreview Preview (const TrackPanelMouseState &state, AudacityProject *pProject) override
 
Result Release (const TrackPanelMouseEvent &event, AudacityProject *pProject, wxWindow *pParent) override
 
Result Cancel (AudacityProject *pProject) override
 
- Public Member Functions inherited from UIHandle
virtual ~UIHandle ()=0
 
virtual void Enter (bool forward, AudacityProject *pProject)
 
virtual bool HasRotation () const
 
virtual bool Rotate (bool forward)
 
virtual bool HasEscape (AudacityProject *pProject) const
 
virtual bool Escape (AudacityProject *pProject)
 
virtual bool HandlesRightClick ()
 Whether the handle has any special right-button handling. More...
 
virtual Result Click (const TrackPanelMouseEvent &event, AudacityProject *pProject)=0
 
virtual Result Drag (const TrackPanelMouseEvent &event, AudacityProject *pProject)=0
 
virtual HitTestPreview Preview (const TrackPanelMouseState &state, AudacityProject *pProject)=0
 
virtual Result Release (const TrackPanelMouseEvent &event, AudacityProject *pProject, wxWindow *pParent)=0
 
virtual Result Cancel (AudacityProject *pProject)=0
 
virtual bool StopsOnKeystroke ()
 
virtual void OnProjectChange (AudacityProject *pProject)
 
Result GetChangeHighlight () const
 
void SetChangeHighlight (Result val)
 
- Public Member Functions inherited from TrackPanelDrawable
virtual ~TrackPanelDrawable ()=0
 
virtual void Draw (TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass)
 
virtual wxRect DrawingArea (TrackPanelDrawingContext &context, const wxRect &rect, const wxRect &panelRect, unsigned iPass)
 

Static Public Member Functions

static HitTestPreview HitPreview (bool bLinked)
 
- Static Public Member Functions inherited from UIHandle
static UIHandle::Result NeedChangeHighlight (const UIHandle &, const UIHandle &)
 
- Static Public Member Functions inherited from TrackPanelDrawable
static wxRect MaximizeWidth (const wxRect &rect, const wxRect &panelRect)
 
static wxRect MaximizeHeight (const wxRect &rect, const wxRect &panelRect)
 

Private Types

enum  Mode { IsResizing , IsResizingBetweenLinkedTracks , IsResizingBelowLinkedTracks }
 

Private Member Functions

 TrackPanelResizeHandle (const TrackPanelResizeHandle &)=delete
 

Private Attributes

Mode mMode { IsResizing }
 
std::weak_ptr< TrackmpTrack
 
bool mInitialMinimized {}
 
int mInitialTrackHeight {}
 
int mInitialExpandedHeight {}
 
int mInitialUpperTrackHeight {}
 
int mInitialUpperExpandedHeight {}
 
int mMouseClickY {}
 

Additional Inherited Members

- Public Types inherited from UIHandle
using Result = unsigned
 
using Cell = TrackPanelCell
 
- Protected Attributes inherited from UIHandle
Result mChangeHighlight { 0 }
 

Detailed Description

Definition at line 18 of file TrackPanelResizeHandle.h.

Member Enumeration Documentation

◆ Mode

Enumerator
IsResizing 
IsResizingBetweenLinkedTracks 
IsResizingBelowLinkedTracks 

Definition at line 50 of file TrackPanelResizeHandle.h.

Constructor & Destructor Documentation

◆ TrackPanelResizeHandle() [1/2]

TrackPanelResizeHandle::TrackPanelResizeHandle ( const TrackPanelResizeHandle )
privatedelete

◆ TrackPanelResizeHandle() [2/2]

TrackPanelResizeHandle::TrackPanelResizeHandle ( const std::shared_ptr< Track > &  pTrack,
int  y 
)
explicit

Definition at line 84 of file TrackPanelResizeHandle.cpp.

86 : mpTrack{ track }
87 , mMouseClickY( y )
88{
89 // TODO: more-than-two-channels
90
91 //STM: Determine whether we should rescale one or two tracks
92 auto channels = TrackList::Channels(track.get());
93 auto last = *channels.rbegin();
94 auto &lastView = TrackView::Get( *last );
95 mInitialTrackHeight = lastView.GetHeight();
96 mInitialExpandedHeight = lastView.GetExpandedHeight();
97 mInitialMinimized = lastView.GetMinimized();
98
99 if (channels.size() > 1) {
100 auto first = *channels.begin();
101 auto &firstView = TrackView::Get( *first );
102
103 mInitialUpperTrackHeight = firstView.GetHeight();
104 mInitialUpperExpandedHeight = firstView.GetExpandedHeight();
105
106 if (track.get() == *channels.rbegin())
107 // capturedTrack is the lowest track
109 else
110 // capturedTrack is not the lowest track
112 }
113 else
115}
static auto Channels(TrackType *pTrack) -> TrackIterRange< TrackType >
Definition: Track.h:1541
std::weak_ptr< Track > mpTrack
static TrackView & Get(Track &)
Definition: TrackView.cpp:69

References TrackList::Channels(), TrackView::Get(), IsResizing, IsResizingBelowLinkedTracks, IsResizingBetweenLinkedTracks, mInitialExpandedHeight, mInitialMinimized, mInitialTrackHeight, mInitialUpperExpandedHeight, mInitialUpperTrackHeight, and mMode.

Here is the call graph for this function:

◆ ~TrackPanelResizeHandle()

TrackPanelResizeHandle::~TrackPanelResizeHandle ( )
virtual

Definition at line 52 of file TrackPanelResizeHandle.cpp.

53{
54}

Member Function Documentation

◆ Cancel()

UIHandle::Result TrackPanelResizeHandle::Cancel ( AudacityProject pProject)
overridevirtual

Implements UIHandle.

Definition at line 260 of file TrackPanelResizeHandle.cpp.

261{
262 auto &tracks = TrackList::Get( *pProject );
263 auto pTrack = tracks.Lock(mpTrack);
264 if ( !pTrack )
266
267
268 switch (mMode) {
269 case IsResizing:
270 {
271 auto &view = TrackView::Get( *pTrack );
272 view.SetExpandedHeight(mInitialExpandedHeight);
273 view.SetMinimized( mInitialMinimized );
274 }
275 break;
277 {
278 Track *const next = * ++ tracks.Find(pTrack.get());
279 auto
280 &view = TrackView::Get( *pTrack ), &nextView = TrackView::Get( *next );
281 view.SetExpandedHeight(mInitialUpperExpandedHeight);
282 view.SetMinimized( mInitialMinimized );
283 nextView.SetExpandedHeight(mInitialExpandedHeight);
284 nextView.SetMinimized( mInitialMinimized );
285 }
286 break;
288 {
289 Track *const prev = * -- tracks.Find(pTrack.get());
290 auto
291 &view = TrackView::Get( *pTrack ), &prevView = TrackView::Get( *prev );
292 view.SetExpandedHeight(mInitialExpandedHeight);
293 view.SetMinimized( mInitialMinimized );
294 prevView.SetExpandedHeight(mInitialUpperExpandedHeight);
295 prevView.SetMinimized(mInitialMinimized);
296 }
297 break;
298 }
299
301}
Subclass * Find(const RegisteredFactory &key)
Get a (bare) pointer to an attachment, or null, down-cast it to Subclass *; will not create on demand...
Definition: ClientData.h:333
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:225
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:486

References RefreshCode::Cancelled, ClientData::Site< Host, ClientData, ObjectCopyingPolicy, Pointer, ObjectLockingPolicy, RegistryLockingPolicy >::Find(), TrackList::Get(), TrackView::Get(), IsResizing, IsResizingBelowLinkedTracks, IsResizingBetweenLinkedTracks, mInitialExpandedHeight, mInitialMinimized, mInitialUpperExpandedHeight, mMode, mpTrack, and RefreshCode::RefreshAll.

Here is the call graph for this function:

◆ Click()

UIHandle::Result TrackPanelResizeHandle::Click ( const TrackPanelMouseEvent event,
AudacityProject pProject 
)
overridevirtual

Implements UIHandle.

Definition at line 56 of file TrackPanelResizeHandle.cpp.

58{
59 using namespace RefreshCode;
60 if ( evt.event.LeftDClick() && mMode == IsResizingBetweenLinkedTracks ) {
61 auto &tracks = TrackList::Get( *pProject );
62 auto pTrack = tracks.Lock(mpTrack);
63 if (pTrack &&
64 !TrackView::Get(*pTrack).GetMinimized()) {
65 auto range = TrackList::Channels( pTrack.get() );
66 auto size = range.size();
67 auto height = range.sum( [](const Track *pTrack){
68 return TrackView::Get(*pTrack).GetHeight(); } );
69 int ii = 1;
70 int coord = 0;
71 for ( const auto channel : range ) {
72 int newCoord = ((double)ii++ /size) * height;
73 TrackView::Get(*channel).SetExpandedHeight( newCoord - coord );
74 coord = newCoord;
75 }
76 ProjectHistory::Get( *pProject ).ModifyState(false);
77 // Do not start a drag
78 return Cancelled | RefreshAll;
79 }
80 }
81 return RefreshNone;
82}
void ModifyState(bool bWantsAutoSave)
static ProjectHistory & Get(AudacityProject &project)
int GetHeight() const
Definition: TrackView.cpp:164
bool GetMinimized() const
Definition: TrackView.h:52
void SetExpandedHeight(int height)
Definition: TrackView.cpp:172
Namespace containing an enum 'what to do on a refresh?'.
Definition: RefreshCode.h:16

References RefreshCode::Cancelled, TrackList::Channels(), TrackPanelMouseEvent::event, ProjectHistory::Get(), TrackList::Get(), TrackView::Get(), TrackView::GetHeight(), TrackView::GetMinimized(), IsResizingBetweenLinkedTracks, mMode, ProjectHistory::ModifyState(), mpTrack, RefreshCode::RefreshAll, RefreshCode::RefreshNone, TrackView::SetExpandedHeight(), and size.

Here is the call graph for this function:

◆ Drag()

UIHandle::Result TrackPanelResizeHandle::Drag ( const TrackPanelMouseEvent event,
AudacityProject pProject 
)
overridevirtual

Implements UIHandle.

Definition at line 117 of file TrackPanelResizeHandle.cpp.

119{
120 auto &tracks = TrackList::Get( *pProject );
121 auto pTrack = tracks.Lock(mpTrack);
122 if ( !pTrack )
124
125 auto &view = TrackView::Get( *pTrack );
126
127 const wxMouseEvent &event = evt.event;
128
129 int delta = (event.m_y - mMouseClickY);
130
131 // On first drag, jump out of minimized mode. Initial height
132 // will be height of minimized track.
133 //
134 // This used to be in HandleResizeClick(), but simply clicking
135 // on a resize border would switch the minimized state.
136 auto &data = TrackView::Get( *pTrack );
137 if (data.GetMinimized()) {
138 auto channels = TrackList::Channels( pTrack.get() );
139 for (auto channel : channels) {
140 auto &channelView = TrackView::Get( *channel );
141 channelView.SetExpandedHeight(channelView.GetHeight());
142 channelView.SetMinimized( false );
143 }
144
145 if (channels.size() > 1) {
146 // Initial values must be reset since they weren't based on the
147 // minimized heights.
148 auto &channelView = TrackView::Get( **channels.begin() );
149 mInitialUpperTrackHeight = channelView.GetHeight();
150 mInitialTrackHeight = channelView.GetHeight();
151 }
152 }
153
154 // Common pieces of code for MONO_WAVE_PAN and otherwise.
155 auto doResizeBelow = [&] (Track *prev, bool WXUNUSED(vStereo)) {
156 // TODO: more-than-two-channels
157
158 auto &prevView = TrackView::Get( *prev );
159
160 double proportion = static_cast < double >(mInitialTrackHeight)
162
163 int newTrackHeight = static_cast < int >
164 (mInitialTrackHeight + delta * proportion);
165
166 int newUpperTrackHeight = static_cast < int >
167 (mInitialUpperTrackHeight + delta * (1.0 - proportion));
168
169 //make sure neither track is smaller than its minimum height
170 if (newTrackHeight < view.GetMinimizedHeight())
171 newTrackHeight = view.GetMinimizedHeight();
172 if (newUpperTrackHeight < prevView.GetMinimizedHeight())
173 newUpperTrackHeight = prevView.GetMinimizedHeight();
174
175 view.SetExpandedHeight(newTrackHeight);
176 prevView.SetExpandedHeight(newUpperTrackHeight);
177 };
178
179 auto doResizeBetween = [&] (Track *next, bool WXUNUSED(vStereo)) {
180 // TODO: more-than-two-channels
181
182 auto &nextView = TrackView::Get( *next );
183 int newUpperTrackHeight = mInitialUpperTrackHeight + delta;
184 int newTrackHeight = mInitialTrackHeight - delta;
185
186 // make sure neither track is smaller than its minimum height
187 if (newTrackHeight < nextView.GetMinimizedHeight()) {
188 newTrackHeight = nextView.GetMinimizedHeight();
189 newUpperTrackHeight =
190 mInitialUpperTrackHeight + mInitialTrackHeight - nextView.GetMinimizedHeight();
191 }
192 if (newUpperTrackHeight < view.GetMinimizedHeight()) {
193 newUpperTrackHeight = view.GetMinimizedHeight();
194 newTrackHeight =
195 mInitialUpperTrackHeight + mInitialTrackHeight - view.GetMinimizedHeight();
196 }
197
198 view.SetExpandedHeight(newUpperTrackHeight);
199 nextView.SetExpandedHeight(newTrackHeight);
200 };
201
202 auto doResize = [&] {
203 int newTrackHeight = mInitialTrackHeight + delta;
204 if (newTrackHeight < view.GetMinimizedHeight())
205 newTrackHeight = view.GetMinimizedHeight();
206 view.SetExpandedHeight(newTrackHeight);
207 };
208
209 //STM: We may be dragging one or two (stereo) tracks.
210 // If two, resize proportionally if we are dragging the lower track, and
211 // adjust compensatively if we are dragging the upper track.
212
213 switch( mMode )
214 {
216 {
217 auto prev = * -- tracks.Find(pTrack.get());
218 doResizeBelow(prev, false);
219 break;
220 }
222 {
223 auto next = * ++ tracks.Find(pTrack.get());
224 doResizeBetween(next, false);
225 break;
226 }
227 case IsResizing:
228 {
229 doResize();
230 break;
231 }
232 default:
233 // don't refresh in this case.
235 }
236
238}

References RefreshCode::Cancelled, TrackList::Channels(), TrackPanelMouseEvent::event, ClientData::Site< Host, ClientData, ObjectCopyingPolicy, Pointer, ObjectLockingPolicy, RegistryLockingPolicy >::Find(), TrackList::Get(), TrackView::Get(), IsResizing, IsResizingBelowLinkedTracks, IsResizingBetweenLinkedTracks, mInitialTrackHeight, mInitialUpperTrackHeight, mMode, mMouseClickY, mpTrack, RefreshCode::RefreshAll, and RefreshCode::RefreshNone.

Here is the call graph for this function:

◆ GetTrack()

std::shared_ptr< Track > TrackPanelResizeHandle::GetTrack ( ) const
inline

Definition at line 31 of file TrackPanelResizeHandle.h.

31{ return mpTrack.lock(); }

References mpTrack.

◆ HitPreview()

HitTestPreview TrackPanelResizeHandle::HitPreview ( bool  bLinked)
static

When in the resize area we can adjust size or relative size.

Definition at line 25 of file TrackPanelResizeHandle.cpp.

26{
27 // TODO: more-than-two-channels-message
28
29 static wxCursor resizeCursor{ wxCURSOR_SIZENS };
30
32 // Check to see whether it is the first channel of a stereo track
33 if (bLinked) {
34 // If we are in the label we got here 'by mistake' and we're
35 // not actually in the resize area at all. (The resize area
36 // is shorter when it is between stereo tracks).
37
38 return {
39 XO(
40"Click and drag to adjust relative size of stereo tracks, double-click to make heights equal"),
41 &resizeCursor
42 };
43 }
44 else {
45 return {
46 XO("Click and drag to resize the track."),
47 &resizeCursor
48 };
49 }
50}
#define XO(s)
Definition: Internat.h:31

References XO.

Referenced by Preview().

Here is the caller graph for this function:

◆ operator=()

TrackPanelResizeHandle & TrackPanelResizeHandle::operator= ( const TrackPanelResizeHandle )
default

◆ Preview()

HitTestPreview TrackPanelResizeHandle::Preview ( const TrackPanelMouseState state,
AudacityProject pProject 
)
overridevirtual

Implements UIHandle.

Definition at line 240 of file TrackPanelResizeHandle.cpp.

242{
244}
static HitTestPreview HitPreview(bool bLinked)

References HitPreview(), IsResizingBetweenLinkedTracks, and mMode.

Here is the call graph for this function:

◆ Release()

UIHandle::Result TrackPanelResizeHandle::Release ( const TrackPanelMouseEvent event,
AudacityProject pProject,
wxWindow *  pParent 
)
overridevirtual

This happens when the button is released from a drag. Since we actually took care of resizing the track when we got drag events, all we have to do here is clean up. We also modify the undo state (the action doesn't become undo-able, but it gets merged with the previous undo-able event).

Implements UIHandle.

Definition at line 246 of file TrackPanelResizeHandle.cpp.

249{
256 ProjectHistory::Get( *pProject ).ModifyState(false);
258}

References RefreshCode::FixScrollbars, ProjectHistory::Get(), and ProjectHistory::ModifyState().

Here is the call graph for this function:

Member Data Documentation

◆ mInitialExpandedHeight

int TrackPanelResizeHandle::mInitialExpandedHeight {}
private

Definition at line 61 of file TrackPanelResizeHandle.h.

Referenced by Cancel(), and TrackPanelResizeHandle().

◆ mInitialMinimized

bool TrackPanelResizeHandle::mInitialMinimized {}
private

Definition at line 59 of file TrackPanelResizeHandle.h.

Referenced by Cancel(), and TrackPanelResizeHandle().

◆ mInitialTrackHeight

int TrackPanelResizeHandle::mInitialTrackHeight {}
private

Definition at line 60 of file TrackPanelResizeHandle.h.

Referenced by Drag(), and TrackPanelResizeHandle().

◆ mInitialUpperExpandedHeight

int TrackPanelResizeHandle::mInitialUpperExpandedHeight {}
private

Definition at line 63 of file TrackPanelResizeHandle.h.

Referenced by Cancel(), and TrackPanelResizeHandle().

◆ mInitialUpperTrackHeight

int TrackPanelResizeHandle::mInitialUpperTrackHeight {}
private

Definition at line 62 of file TrackPanelResizeHandle.h.

Referenced by Drag(), and TrackPanelResizeHandle().

◆ mMode

Mode TrackPanelResizeHandle::mMode { IsResizing }
private

Definition at line 55 of file TrackPanelResizeHandle.h.

Referenced by Cancel(), Click(), Drag(), Preview(), and TrackPanelResizeHandle().

◆ mMouseClickY

int TrackPanelResizeHandle::mMouseClickY {}
private

Definition at line 65 of file TrackPanelResizeHandle.h.

Referenced by Drag().

◆ mpTrack

std::weak_ptr<Track> TrackPanelResizeHandle::mpTrack
private

Definition at line 57 of file TrackPanelResizeHandle.h.

Referenced by Cancel(), Click(), Drag(), and GetTrack().


The documentation for this class was generated from the following files: