Audacity  2.2.2
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:
UIHandle

Public Member Functions

 TrackPanelResizeHandle (const std::shared_ptr< Track > &pTrack, int y, const AudacityProject *pProject)
 
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, const 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)
 
virtual bool HasRotation () const
 
virtual bool Rotate (bool forward)
 
virtual bool HasEscape () const
 
virtual bool Escape ()
 
virtual void DrawExtras (DrawingPass pass, wxDC *dc, const wxRegion &updateRegion, const wxRect &panelRect)
 
virtual bool StopsOnKeystroke ()
 
virtual void OnProjectChange (AudacityProject *pProject)
 
Result GetChangeHighlight () const
 
void SetChangeHighlight (Result val)
 

Static Public Member Functions

static HitTestPreview HitPreview (bool bLinked)
 
- Static Public Member Functions inherited from UIHandle
static UIHandle::Result NeedChangeHighlight (const UIHandle &, const UIHandle &)
 

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 mInitialActualHeight {}
 
int mInitialUpperTrackHeight {}
 
int mInitialUpperActualHeight {}
 
int mMouseClickY {}
 

Additional Inherited Members

- Public Types inherited from UIHandle
enum  DrawingPass { Cells, Panel }
 
using Result = unsigned
 
using Cell = TrackPanelCell
 
- Protected Attributes inherited from UIHandle
Result mChangeHighlight { 0 }
 

Detailed Description

Definition at line 20 of file TrackPanelResizeHandle.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

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

Definition at line 62 of file TrackPanelResizeHandle.cpp.

63  : mpTrack{ track }
64  , mMouseClickY( y )
65 {
66  auto tracks = pProject->GetTracks();
67  Track *prev = tracks->GetPrev(track.get());
68  Track *next = tracks->GetNext(track.get());
69 
70  //STM: Determine whether we should rescale one or two tracks
71  if (prev && prev->GetLink() == track.get()) {
72  // mpTrack is the lower track
73  mInitialTrackHeight = track->GetHeight();
74  mInitialActualHeight = track->GetActualHeight();
75  mInitialMinimized = track->GetMinimized();
79  }
80  else if (next && track->GetLink() == next) {
81  // mpTrack is the upper track
85  mInitialUpperTrackHeight = track->GetHeight();
86  mInitialUpperActualHeight = track->GetActualHeight();
88  }
89  else {
90  // DM: Save the initial mouse location and the initial height
91  mInitialTrackHeight = track->GetHeight();
92  mInitialActualHeight = track->GetActualHeight();
93  mInitialMinimized = track->GetMinimized();
94  mMode = IsResizing;
95  }
96 }
int GetActualHeight() const
Definition: Track.h:193
bool GetMinimized() const
Definition: Track.cpp:214
std::weak_ptr< Track > mpTrack
Fundamental data object of Audacity, placed in the TrackPanel. Classes derived form it include the Wa...
Definition: Track.h:102
Track * GetLink() const
Definition: Track.cpp:269
TrackList * GetTracks()
Definition: Project.h:192
int GetHeight() const
Definition: Track.cpp:180
TrackPanelResizeHandle::~TrackPanelResizeHandle ( )
virtual

Definition at line 51 of file TrackPanelResizeHandle.cpp.

52 {
53 }

Member Function Documentation

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

Implements UIHandle.

Definition at line 230 of file TrackPanelResizeHandle.cpp.

References RefreshCode::Cancelled, TrackList::GetNext(), TrackList::GetPrev(), AudacityProject::GetTracks(), IsResizing, IsResizingBelowLinkedTracks, IsResizingBetweenLinkedTracks, TrackList::Lock(), mInitialActualHeight, mInitialMinimized, mInitialUpperActualHeight, mMode, mpTrack, RefreshCode::RefreshAll, Track::SetHeight(), and Track::SetMinimized().

231 {
232  auto pTrack = pProject->GetTracks()->Lock(mpTrack);
233  if ( !pTrack )
234  return RefreshCode::Cancelled;
235 
236  TrackList *const tracks = pProject->GetTracks();
237 
238  switch (mMode) {
239  case IsResizing:
240  {
241  pTrack->SetHeight(mInitialActualHeight);
242  pTrack->SetMinimized(mInitialMinimized);
243  }
244  break;
246  {
247  Track *const next = tracks->GetNext(pTrack.get());
249  pTrack->SetMinimized(mInitialMinimized);
252  }
253  break;
255  {
256  Track *const prev = tracks->GetPrev(pTrack.get());
258  pTrack->SetMinimized(mInitialMinimized);
261  }
262  break;
263  }
264 
266 }
A list of TrackListNode items.
Definition: Track.h:619
void SetHeight(int h)
Definition: Track.cpp:189
void SetMinimized(bool isMinimized)
Definition: Track.cpp:219
std::weak_ptr< Track > mpTrack
Track * GetNext(Track *t, bool linked=false) const
Return a track in the list that comes after Track t.
Definition: Track.cpp:1048
Fundamental data object of Audacity, placed in the TrackPanel. Classes derived form it include the Wa...
Definition: Track.h:102
std::shared_ptr< Subclass > Lock(const std::weak_ptr< Subclass > &wTrack)
Definition: Track.h:734
Track * GetPrev(Track *t, bool linked=false) const
Definition: Track.cpp:1067
TrackList * GetTracks()
Definition: Project.h:192
UIHandle::Result TrackPanelResizeHandle::Click ( const TrackPanelMouseEvent event,
AudacityProject pProject 
)
overridevirtual

Implements UIHandle.

Definition at line 56 of file TrackPanelResizeHandle.cpp.

References RefreshCode::RefreshNone.

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

Implements UIHandle.

Definition at line 99 of file TrackPanelResizeHandle.cpp.

References RefreshCode::Cancelled, TrackPanelMouseEvent::event, Track::GetHeight(), Track::GetLink(), Track::GetMinimizedHeight(), TrackList::GetNext(), TrackList::GetPrev(), AudacityProject::GetTracks(), TrackList::Lock(), RefreshCode::RefreshAll, RefreshCode::RefreshNone, Track::SetHeight(), and Track::SetMinimized().

100 {
101  auto pTrack = pProject->GetTracks()->Lock(mpTrack);
102  if ( !pTrack )
103  return RefreshCode::Cancelled;
104 
105  const wxMouseEvent &event = evt.event;
106  TrackList *const tracks = pProject->GetTracks();
107 
108  int delta = (event.m_y - mMouseClickY);
109 
110  // On first drag, jump out of minimized mode. Initial height
111  // will be height of minimized track.
112  //
113  // This used to be in HandleResizeClick(), but simply clicking
114  // on a resize border would switch the minimized state.
115  if (pTrack->GetMinimized()) {
116  Track *link = pTrack->GetLink();
117 
118  pTrack->SetHeight(pTrack->GetHeight());
119  pTrack->SetMinimized(false);
120 
121  if (link) {
122  link->SetHeight(link->GetHeight());
123  link->SetMinimized(false);
124  // Initial values must be reset since they weren't based on the
125  // minimized heights.
127  mInitialTrackHeight = pTrack->GetHeight();
128  }
129  }
130 
131  // Common pieces of code for MONO_WAVE_PAN and otherwise.
132  auto doResizeBelow = [&] (Track *prev, bool WXUNUSED(vStereo)) {
133  double proportion = static_cast < double >(mInitialTrackHeight)
135 
136  int newTrackHeight = static_cast < int >
137  (mInitialTrackHeight + delta * proportion);
138 
139  int newUpperTrackHeight = static_cast < int >
140  (mInitialUpperTrackHeight + delta * (1.0 - proportion));
141 
142  //make sure neither track is smaller than its minimum height
143  if (newTrackHeight < pTrack->GetMinimizedHeight())
144  newTrackHeight = pTrack->GetMinimizedHeight();
145  if (newUpperTrackHeight < prev->GetMinimizedHeight())
146  newUpperTrackHeight = prev->GetMinimizedHeight();
147 
148  pTrack->SetHeight(newTrackHeight);
149  prev->SetHeight(newUpperTrackHeight);
150  };
151 
152  auto doResizeBetween = [&] (Track *next, bool WXUNUSED(vStereo)) {
153  int newUpperTrackHeight = mInitialUpperTrackHeight + delta;
154  int newTrackHeight = mInitialTrackHeight - delta;
155 
156  // make sure neither track is smaller than its minimum height
157  if (newTrackHeight < next->GetMinimizedHeight()) {
158  newTrackHeight = next->GetMinimizedHeight();
159  newUpperTrackHeight =
161  }
162  if (newUpperTrackHeight < pTrack->GetMinimizedHeight()) {
163  newUpperTrackHeight = pTrack->GetMinimizedHeight();
164  newTrackHeight =
165  mInitialUpperTrackHeight + mInitialTrackHeight - pTrack->GetMinimizedHeight();
166  }
167 
168  pTrack->SetHeight(newUpperTrackHeight);
169  next->SetHeight(newTrackHeight);
170  };
171 
172  auto doResize = [&] {
173  int newTrackHeight = mInitialTrackHeight + delta;
174  if (newTrackHeight < pTrack->GetMinimizedHeight())
175  newTrackHeight = pTrack->GetMinimizedHeight();
176  pTrack->SetHeight(newTrackHeight);
177  };
178 
179  //STM: We may be dragging one or two (stereo) tracks.
180  // If two, resize proportionally if we are dragging the lower track, and
181  // adjust compensatively if we are dragging the upper track.
182 
183  switch( mMode )
184  {
186  {
187  Track *prev = tracks->GetPrev(pTrack.get());
188  doResizeBelow(prev, false);
189  break;
190  }
192  {
193  Track *next = tracks->GetNext(pTrack.get());
194  doResizeBetween(next, false);
195  break;
196  }
197  case IsResizing:
198  {
199  doResize();
200  break;
201  }
202  default:
203  // don't refresh in this case.
205  }
206 
208 }
A list of TrackListNode items.
Definition: Track.h:619
void SetHeight(int h)
Definition: Track.cpp:189
virtual int GetMinimizedHeight() const
Definition: Track.cpp:129
void SetMinimized(bool isMinimized)
Definition: Track.cpp:219
std::weak_ptr< Track > mpTrack
Track * GetNext(Track *t, bool linked=false) const
Return a track in the list that comes after Track t.
Definition: Track.cpp:1048
Fundamental data object of Audacity, placed in the TrackPanel. Classes derived form it include the Wa...
Definition: Track.h:102
std::shared_ptr< Subclass > Lock(const std::weak_ptr< Subclass > &wTrack)
Definition: Track.h:734
Track * GetPrev(Track *t, bool linked=false) const
Definition: Track.cpp:1067
Track * GetLink() const
Definition: Track.cpp:269
TrackList * GetTracks()
Definition: Project.h:192
int GetHeight() const
Definition: Track.cpp:180
std::shared_ptr<Track> TrackPanelResizeHandle::GetTrack ( ) const
inline

Definition at line 35 of file TrackPanelResizeHandle.h.

References mpTrack.

35 { return mpTrack.lock(); }
std::weak_ptr< Track > mpTrack
HitTestPreview TrackPanelResizeHandle::HitPreview ( bool  bLinked)
static

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

Definition at line 27 of file TrackPanelResizeHandle.cpp.

References _().

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  _("Click and drag to adjust relative size of stereo tracks."),
40  &resizeCursor
41  };
42  }
43  else {
44  return {
45  _("Click and drag to resize the track."),
46  &resizeCursor
47  };
48  }
49 }
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
TrackPanelResizeHandle& TrackPanelResizeHandle::operator= ( const TrackPanelResizeHandle )
default
HitTestPreview TrackPanelResizeHandle::Preview ( const TrackPanelMouseState state,
const AudacityProject pProject 
)
overridevirtual
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 217 of file TrackPanelResizeHandle.cpp.

References RefreshCode::FixScrollbars, and AudacityProject::ModifyState().

219 {
226  pProject->ModifyState(false);
228 }
void ModifyState(bool bWantsAutoSave)
Definition: Project.cpp:4747

Member Data Documentation

int TrackPanelResizeHandle::mInitialActualHeight {}
private

Definition at line 65 of file TrackPanelResizeHandle.h.

Referenced by Cancel().

bool TrackPanelResizeHandle::mInitialMinimized {}
private

Definition at line 63 of file TrackPanelResizeHandle.h.

Referenced by Cancel().

int TrackPanelResizeHandle::mInitialTrackHeight {}
private

Definition at line 64 of file TrackPanelResizeHandle.h.

int TrackPanelResizeHandle::mInitialUpperActualHeight {}
private

Definition at line 67 of file TrackPanelResizeHandle.h.

Referenced by Cancel().

int TrackPanelResizeHandle::mInitialUpperTrackHeight {}
private

Definition at line 66 of file TrackPanelResizeHandle.h.

Mode TrackPanelResizeHandle::mMode { IsResizing }
private

Definition at line 59 of file TrackPanelResizeHandle.h.

Referenced by Cancel().

int TrackPanelResizeHandle::mMouseClickY {}
private

Definition at line 69 of file TrackPanelResizeHandle.h.

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

Definition at line 61 of file TrackPanelResizeHandle.h.

Referenced by Cancel(), and GetTrack().


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