Audacity  3.0.3
Public Types | Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjustHandle Class Reference
Inheritance diagram for anonymous_namespace{WaveTrackView.cpp}::SubViewAdjustHandle:
[legend]
Collaboration diagram for anonymous_namespace{WaveTrackView.cpp}::SubViewAdjustHandle:
[legend]

Public Types

enum  { MinHeight = SubViewAdjuster::HotZoneSize }
 
- Public Types inherited from UIHandle
using Result = unsigned
 
using Cell = TrackPanelCell
 

Public Member Functions

 SubViewAdjustHandle (SubViewAdjuster &&adjuster, size_t subViewIndex, wxCoord viewHeight, bool top)
 
Result Click (const TrackPanelMouseEvent &event, AudacityProject *pProject) override
 
Result Drag (const TrackPanelMouseEvent &event, AudacityProject *) override
 
HitTestPreview Preview (const TrackPanelMouseState &state, AudacityProject *) override
 
Result Release (const TrackPanelMouseEvent &event, AudacityProject *pProject, wxWindow *pParent) override
 
Result Cancel (AudacityProject *) 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 () const
 
virtual bool Escape (AudacityProject *pProject)
 
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 UIHandlePtr HitTest (std::weak_ptr< UIHandle > &holder, WaveTrackView &view, WaveTrackSubView &subView, const TrackPanelMouseState &state)
 
- 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 Attributes

SubViewAdjuster mAdjuster
 
std::vector< wxCoord > mOrigHeights
 
size_t mMySubView {}
 
wxCoord mYMin {}
 
wxCoord mYMax {}
 
wxCoord mViewHeight {}
 
wxCoord mTotalHeight {}
 
wxCoord mOrigHeight {}
 
wxCoord mOrigY {}
 
bool mTop {}
 

Additional Inherited Members

- Protected Attributes inherited from UIHandle
Result mChangeHighlight { 0 }
 

Detailed Description

Definition at line 208 of file WaveTrackView.cpp.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
MinHeight 

Definition at line 211 of file WaveTrackView.cpp.

Constructor & Destructor Documentation

◆ SubViewAdjustHandle()

anonymous_namespace{WaveTrackView.cpp}::SubViewAdjustHandle::SubViewAdjustHandle ( SubViewAdjuster &&  adjuster,
size_t  subViewIndex,
wxCoord  viewHeight,
bool  top 
)
inline

Definition at line 237 of file WaveTrackView.cpp.

240  : mAdjuster{ std::move( adjuster ) }
241  , mMySubView{ subViewIndex }
242  , mViewHeight{ viewHeight }
243  , mTop{ top }
244  {
245  if ( mAdjuster.ModifyPermutation( top ) )
246  --mMySubView;
247  }

Member Function Documentation

◆ Cancel()

Result anonymous_namespace{WaveTrackView.cpp}::SubViewAdjustHandle::Cancel ( AudacityProject )
inlineoverridevirtual

Implements UIHandle.

Definition at line 395 of file WaveTrackView.cpp.

396  {
397  mAdjuster.UpdateViews( true );
399  }

References RefreshCode::RefreshAll.

◆ Click()

Result anonymous_namespace{WaveTrackView.cpp}::SubViewAdjustHandle::Click ( const TrackPanelMouseEvent event,
AudacityProject pProject 
)
inlineoverridevirtual

Implements UIHandle.

Definition at line 249 of file WaveTrackView.cpp.

251  {
252  using namespace RefreshCode;
253  const auto &permutation = mAdjuster.mPermutation;
254  const auto size = permutation.size();
255  if ( mMySubView >= size )
256  return Cancelled;
257 
258  if (event.event.LeftDClick()) {
259  for ( auto &placement : mAdjuster.mNewPlacements ) {
260  if ( placement.index >= 0 )
261  placement.fraction = 1.0f;
262  else
263  placement.fraction = 0.0f;
264  }
265  mAdjuster.UpdateViews( false );
266  ProjectHistory::Get( *pProject ).ModifyState( false );
267 
268  // Do not start a drag
269  return Cancelled | RefreshAll;
270  }
271 
272  const auto &rect = event.rect;
273  const auto height = rect.GetHeight();
274  mOrigHeight = height;
275 
277 
278  // Find the total height of the sub-views that may resize
279  mTotalHeight = 0;
280  auto index = ( mTop ? mAdjuster.mFirstSubView : mMySubView );
281  const auto end = ( mTop ? mMySubView + 1 : permutation.size() );
282  for (; index != end; ++index)
283  mTotalHeight += mOrigHeights[ index ];
284 
285  wxASSERT( height == mOrigHeights[ mMySubView ] );
286 
287  // Compute the maximum and minimum Y coordinates for drag effect
288  if ( mTop ) {
289  mOrigY = rect.GetTop();
290  mYMax = rect.GetBottom();
291  mYMin = mYMax - mTotalHeight + 1;
292  }
293  else {
294  mOrigY = rect.GetBottom();
295  mYMin = rect.GetTop();
296  mYMax = mYMin + mTotalHeight - 1;
297  }
298 
299  return RefreshNone;
300  }

References Cancelled, TrackPanelMouseEvent::event, ProjectHistory::Get(), ProjectHistory::ModifyState(), RefreshCode::RefreshAll, and RefreshCode::RefreshNone.

Here is the call graph for this function:

◆ Drag()

Result anonymous_namespace{WaveTrackView.cpp}::SubViewAdjustHandle::Drag ( const TrackPanelMouseEvent event,
AudacityProject  
)
inlineoverridevirtual

Implements UIHandle.

Definition at line 302 of file WaveTrackView.cpp.

303  {
304  using namespace RefreshCode;
305  auto pView = mAdjuster.mwView.lock();
306  if ( !pView )
307  return Cancelled;
308 
309  // Find new height for the dragged sub-view
310  auto newY = std::max( mYMin, std::min( mYMax, event.event.GetY() ) );
311  const auto delta = newY - mOrigY;
312  wxCoord newHeight = mTop
313  ? mOrigHeight - delta
314  : mOrigHeight + delta
315  ;
316  wxASSERT( newHeight >= 0 && newHeight <= mTotalHeight );
317  if ( newHeight < MinHeight )
318  // Snap the dragged sub-view to nothing
319  newHeight = 0;
320 
321  // Reassign height for the dragged sub-view
322  auto &myPlacement =
324  myPlacement.fraction = newHeight;
325 
326  // Grow or shrink other sub-views
327  auto excess = newHeight - mOrigHeight; // maybe negative
328  const auto adjustHeight = [&](size_t ii) {
329  if (excess == 0)
330  return true;
331 
332  const auto oldFraction = mOrigHeights[ ii ];
333 
334  auto index = mAdjuster.mPermutation[ ii ];
335  auto &placement = mAdjuster.mNewPlacements[ index ];
336  auto &fraction = placement.fraction;
337 
338  if (excess > oldFraction) {
339  excess -= oldFraction, fraction = 0;
340  return false;
341  }
342  else {
343  auto newFraction = oldFraction - excess;
344  if ( newFraction < MinHeight ) {
345  // This snaps very short sub-views to nothing
346  myPlacement.fraction += newFraction;
347  fraction = 0;
348  }
349  else
350  fraction = newFraction;
351  return true;
352  }
353  };
354  if ( mTop ) {
355  for ( size_t ii = mMySubView; ii > 0; ) {
356  --ii;
357  if ( adjustHeight( ii ) )
358  break;
359  }
360  }
361  else {
362  for ( size_t ii = mMySubView + 1, size = mAdjuster.mPermutation.size();
363  ii < size; ++ii
364  ) {
365  if ( adjustHeight( ii ) )
366  break;
367  }
368  }
369 
370  // Save adjustment to the track and request a redraw
371  mAdjuster.UpdateViews( false );
372  return RefreshAll;
373  }

References Cancelled, TrackPanelMouseEvent::event, min(), and RefreshCode::RefreshAll.

Here is the call graph for this function:

◆ HitTest()

static UIHandlePtr anonymous_namespace{WaveTrackView.cpp}::SubViewAdjustHandle::HitTest ( std::weak_ptr< UIHandle > &  holder,
WaveTrackView view,
WaveTrackSubView subView,
const TrackPanelMouseState state 
)
inlinestatic

Definition at line 213 of file WaveTrackView.cpp.

217  {
218  if ( !view.GetMultiView() )
219  return {};
220 
221  SubViewAdjuster adjuster{ view };
222  auto hit = adjuster.HitTest( subView,
223  state.state.GetY(), state.rect.GetTop(), state.rect.GetHeight() );
224  auto index = hit.first;
225 
226  if ( index < adjuster.mPermutation.size() ) {
227  UIHandlePtr result = std::make_shared< SubViewAdjustHandle >(
228  std::move( adjuster ), index, view.GetLastHeight(), hit.second
229  );
230  result = AssignUIHandlePtr( holder, result );
231  return result;
232  }
233  else
234  return {};
235  }

References AssignUIHandlePtr(), WaveTrackView::GetLastHeight(), WaveTrackView::GetMultiView(), CommonTrackView::HitTest(), TrackPanelMouseState::rect, and TrackPanelMouseState::state.

Here is the call graph for this function:

◆ Preview()

HitTestPreview anonymous_namespace{WaveTrackView.cpp}::SubViewAdjustHandle::Preview ( const TrackPanelMouseState state,
AudacityProject  
)
inlineoverridevirtual

Implements UIHandle.

Definition at line 375 of file WaveTrackView.cpp.

377  {
378  static auto resizeCursor =
379  ::MakeCursor(wxCURSOR_ARROW, SubViewsCursorXpm, 16, 16);
380  return {
381  XO(
382 "Click and drag to adjust sizes of sub-views, double-click to split evenly"),
383  &*resizeCursor
384  };
385  }

References MakeCursor(), and XO.

Here is the call graph for this function:

◆ Release()

Result anonymous_namespace{WaveTrackView.cpp}::SubViewAdjustHandle::Release ( const TrackPanelMouseEvent event,
AudacityProject pProject,
wxWindow *  pParent 
)
inlineoverridevirtual

Implements UIHandle.

Definition at line 387 of file WaveTrackView.cpp.

390  {
391  ProjectHistory::Get( *pProject ).ModifyState( false );
393  }

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

Here is the call graph for this function:

Member Data Documentation

◆ mAdjuster

SubViewAdjuster anonymous_namespace{WaveTrackView.cpp}::SubViewAdjustHandle::mAdjuster
private

Definition at line 403 of file WaveTrackView.cpp.

◆ mMySubView

size_t anonymous_namespace{WaveTrackView.cpp}::SubViewAdjustHandle::mMySubView {}
private

Definition at line 407 of file WaveTrackView.cpp.

◆ mOrigHeight

wxCoord anonymous_namespace{WaveTrackView.cpp}::SubViewAdjustHandle::mOrigHeight {}
private

Definition at line 412 of file WaveTrackView.cpp.

◆ mOrigHeights

std::vector<wxCoord> anonymous_namespace{WaveTrackView.cpp}::SubViewAdjustHandle::mOrigHeights
private

Definition at line 404 of file WaveTrackView.cpp.

◆ mOrigY

wxCoord anonymous_namespace{WaveTrackView.cpp}::SubViewAdjustHandle::mOrigY {}
private

Definition at line 413 of file WaveTrackView.cpp.

◆ mTop

bool anonymous_namespace{WaveTrackView.cpp}::SubViewAdjustHandle::mTop {}
private

Definition at line 416 of file WaveTrackView.cpp.

◆ mTotalHeight

wxCoord anonymous_namespace{WaveTrackView.cpp}::SubViewAdjustHandle::mTotalHeight {}
private

Definition at line 411 of file WaveTrackView.cpp.

◆ mViewHeight

wxCoord anonymous_namespace{WaveTrackView.cpp}::SubViewAdjustHandle::mViewHeight {}
private

Definition at line 410 of file WaveTrackView.cpp.

◆ mYMax

wxCoord anonymous_namespace{WaveTrackView.cpp}::SubViewAdjustHandle::mYMax {}
private

Definition at line 409 of file WaveTrackView.cpp.

◆ mYMin

wxCoord anonymous_namespace{WaveTrackView.cpp}::SubViewAdjustHandle::mYMin {}
private

Definition at line 409 of file WaveTrackView.cpp.


The documentation for this class was generated from the following file:
ProjectHistory::ModifyState
void ModifyState(bool bWantsAutoSave)
Definition: ProjectHistory.cpp:124
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjustHandle::mTotalHeight
wxCoord mTotalHeight
Definition: WaveTrackView.cpp:411
RefreshCode::RefreshAll
@ RefreshAll
Definition: RefreshCode.h:26
RefreshCode::RefreshNone
@ RefreshNone
Definition: RefreshCode.h:21
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjustHandle::mViewHeight
wxCoord mViewHeight
Definition: WaveTrackView.cpp:410
MakeCursor
std::unique_ptr< wxCursor > MakeCursor(int WXUNUSED(CursorId), const char *const pXpm[36], int HotX, int HotY)
Definition: TrackPanel.cpp:177
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjuster::UpdateViews
void UpdateViews(bool rollback)
Definition: WaveTrackView.cpp:188
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjuster::mFirstSubView
size_t mFirstSubView
Definition: WaveTrackView.cpp:205
RefreshCode::Cancelled
@ Cancelled
Definition: RefreshCode.h:23
XO
#define XO(s)
Definition: Internat.h:31
WaveTrackView::GetMultiView
bool GetMultiView() const
Definition: WaveTrackView.h:122
WaveTrackView::GetLastHeight
wxCoord GetLastHeight() const
Definition: WaveTrackView.h:120
TrackPanelMouseState::rect
const wxRect & rect
Definition: TrackPanelMouseEvent.h:39
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjuster::ComputeHeights
std::vector< wxCoord > ComputeHeights(wxCoord totalHeight)
Definition: WaveTrackView.cpp:164
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjustHandle::MinHeight
@ MinHeight
Definition: WaveTrackView.cpp:211
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjuster::mNewPlacements
WaveTrackSubViewPlacements mNewPlacements
Definition: WaveTrackView.cpp:201
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjustHandle::mOrigHeights
std::vector< wxCoord > mOrigHeights
Definition: WaveTrackView.cpp:404
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjustHandle::mOrigHeight
wxCoord mOrigHeight
Definition: WaveTrackView.cpp:412
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjustHandle::mYMin
wxCoord mYMin
Definition: WaveTrackView.cpp:409
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjustHandle::mMySubView
size_t mMySubView
Definition: WaveTrackView.cpp:407
CommonTrackView::HitTest
std::vector< UIHandlePtr > HitTest(const TrackPanelMouseState &, const AudacityProject *pProject) final override
Definition: CommonTrackView.cpp:30
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjustHandle::mTop
bool mTop
Definition: WaveTrackView.cpp:416
UIHandlePtr
std::shared_ptr< UIHandle > UIHandlePtr
Definition: CellularPanel.h:28
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjuster::ModifyPermutation
bool ModifyPermutation(bool top)
Definition: WaveTrackView.cpp:98
min
int min(int a, int b)
Definition: CompareAudioCommand.cpp:106
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjustHandle::mYMax
wxCoord mYMax
Definition: WaveTrackView.cpp:409
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjuster::HotZoneSize
@ HotZoneSize
Definition: WaveTrackView.cpp:49
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjustHandle::mAdjuster
SubViewAdjuster mAdjuster
Definition: WaveTrackView.cpp:403
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjuster::mPermutation
std::vector< size_t > mPermutation
Definition: WaveTrackView.cpp:203
AssignUIHandlePtr
std::shared_ptr< Subclass > AssignUIHandlePtr(std::weak_ptr< Subclass > &holder, const std::shared_ptr< Subclass > &pNew)
Definition: UIHandle.h:145
RefreshCode
Namespace containing an enum 'what to do on a refresh?'.
Definition: RefreshCode.h:16
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjuster::mwView
std::weak_ptr< WaveTrackView > mwView
Definition: WaveTrackView.cpp:199
TrackPanelMouseEvent::event
wxMouseEvent & event
Definition: TrackPanelMouseEvent.h:58
TrackPanelMouseState::state
wxMouseState & state
Definition: TrackPanelMouseEvent.h:38
ProjectHistory::Get
static ProjectHistory & Get(AudacityProject &project)
Definition: ProjectHistory.cpp:26
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjustHandle::mOrigY
wxCoord mOrigY
Definition: WaveTrackView.cpp:413