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

Public Types

enum  { HotZoneWidth = 3 * kTrackInfoBtnSize / 2 }
 
enum  DragChoice_t { Upward, Downward, Neutral }
 
- Public Types inherited from UIHandle
using Result = unsigned
 
using Cell = TrackPanelCell
 

Public Member Functions

 SubViewRearrangeHandle (SubViewAdjuster &&adjuster, size_t subViewIndex, wxCoord viewHeight)
 
Result Click (const TrackPanelMouseEvent &event, AudacityProject *pProject) override
 
bool Clicked () const
 
DragChoice_t DragChoice (const TrackPanelMouseEvent &event) const
 
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 > mHeights
 
wxCoord mTopY
 
size_t mMySubView {}
 
wxCoord mViewHeight {}
 

Additional Inherited Members

- Protected Attributes inherited from UIHandle
Result mChangeHighlight { 0 }
 

Detailed Description

Definition at line 419 of file WaveTrackView.cpp.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
HotZoneWidth 

Definition at line 423 of file WaveTrackView.cpp.

423 { HotZoneWidth = 3 * kTrackInfoBtnSize / 2 };

◆ DragChoice_t

enum anonymous_namespace{WaveTrackView.cpp}::SubViewRearrangeHandle::DragChoice_t
Enumerator
Upward 
Downward 
Neutral 

Definition at line 498 of file WaveTrackView.cpp.

498 { Upward, Downward, Neutral };

Constructor & Destructor Documentation

◆ SubViewRearrangeHandle()

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

Definition at line 466 of file WaveTrackView.cpp.

469  : mAdjuster{ std::move( adjuster ) }
470  , mMySubView{ subViewIndex }
471  , mViewHeight{ viewHeight }
472  {
473  }

Member Function Documentation

◆ Cancel()

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

Implements UIHandle.

Definition at line 590 of file WaveTrackView.cpp.

591  {
592  mAdjuster.UpdateViews( true );
594  }

References RefreshCode::RefreshAll.

◆ Click()

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

Implements UIHandle.

Definition at line 475 of file WaveTrackView.cpp.

477  {
478  using namespace RefreshCode;
479  const auto &permutation = mAdjuster.mPermutation;
480  const auto size = permutation.size();
481  if ( mMySubView >= size )
482  return Cancelled;
483 
485 
486  // Find y coordinate of first sub-view
487  wxCoord heightAbove = 0;
488  for (auto index = mAdjuster.mFirstSubView;
489  index != mMySubView; ++index)
490  heightAbove += mHeights[ index ];
491  mTopY = event.rect.GetTop() - heightAbove;
492 
493  return RefreshNone;
494  }

References Cancelled, and RefreshCode::RefreshNone.

◆ Clicked()

bool anonymous_namespace{WaveTrackView.cpp}::SubViewRearrangeHandle::Clicked ( ) const
inline

Definition at line 496 of file WaveTrackView.cpp.

496 { return !mHeights.empty(); }

◆ Drag()

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

Implements UIHandle.

Definition at line 531 of file WaveTrackView.cpp.

532  {
533  using namespace RefreshCode;
534  auto pView = mAdjuster.mwView.lock();
535  if ( !pView )
536  return Cancelled;
537 
538  switch( DragChoice( event ) ) {
539  case Upward:
540  {
542  std::swap(
544  mAdjuster.mNewPlacements[ mMySubView - 1 ].index
545  );
546  --mMySubView;
547  break;
548  }
549  case Downward:
550  {
552  std::swap(
554  mAdjuster.mNewPlacements[ mMySubView + 1 ].index
555  );
556  ++mMySubView;
557  break;
558  }
559  default:
560  return RefreshNone;
561  }
562 
563  // Save adjustment to the track and request a redraw
564  mAdjuster.UpdateViews( false );
565  return RefreshAll;
566  }

References Cancelled, RefreshCode::RefreshAll, RefreshCode::RefreshNone, and anonymous_namespace{NoteTrack.cpp}::swap().

Here is the call graph for this function:

◆ DragChoice()

DragChoice_t anonymous_namespace{WaveTrackView.cpp}::SubViewRearrangeHandle::DragChoice ( const TrackPanelMouseEvent event) const
inline

Definition at line 500 of file WaveTrackView.cpp.

501  {
502  // Disregard x coordinate -- so the mouse need not be in any sub-view,
503  // just in the correct range of y coordinates
504  auto yy = event.event.GetY();
505  auto coord = mTopY;
506  size_t ii = mAdjuster.mFirstSubView;
507  if ( yy < mTopY )
508  return ( mMySubView == ii ) ? Neutral : Upward;
509 
510  for ( auto nn = mHeights.size(); ii < nn; ++ii ) {
511  const auto height = mHeights[ ii ];
512  coord += height;
513  if ( yy < coord )
514  break;
515  }
516 
517  if ( ii < mMySubView ) {
518  if ( yy < coord - mHeights[ ii ] + mHeights[ mMySubView ] )
519  return Upward;
520  }
521 
522  if ( ii > mMySubView ) {
523  if( mMySubView < mHeights.size() - 1 &&
524  yy >= coord - mHeights[ mMySubView ] )
525  return Downward;
526  }
527 
528  return Neutral;
529  }

◆ HitTest()

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

Definition at line 425 of file WaveTrackView.cpp.

428  {
429  if ( !view.GetMultiView() )
430  return {};
431 
432  SubViewAdjuster adjuster{ view };
433  if ( adjuster.NVisible() < 2 )
434  return {};
435 
436  auto relX = state.state.GetX() - state.rect.GetLeft();
437  if ( relX >= HotZoneWidth )
438  return {};
439 
440  auto index = adjuster.FindIndex( subView );
441 
442  // Hit on the rearrange cursor only in the top and bottom thirds of
443  // sub-view height, leaving the rest free to hit the selection cursor
444  // first.
445  // And also exclude the top third of the topmost sub-view and bottom
446  // third of bottommost.
447  auto relY = state.state.GetY() - state.rect.GetTop();
448  auto height = state.rect.GetHeight();
449  bool hit =
450  ( ( 3 * relY < height ) && index > 0 ) // top hit
451  ||
452  ( ( 3 * relY > 2 * height ) &&
453  index < adjuster.mPermutation.size() - 1 ) // bottom
454  ;
455  if ( ! hit )
456  return {};
457 
458  UIHandlePtr result = std::make_shared< SubViewRearrangeHandle >(
459  std::move( adjuster ),
460  index, view.GetLastHeight()
461  );
462  result = AssignUIHandlePtr( holder, result );
463  return result;
464  }

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

Here is the call graph for this function:

◆ Preview()

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

Implements UIHandle.

Definition at line 568 of file WaveTrackView.cpp.

570  {
571  static auto hoverCursor =
572  ::MakeCursor(wxCURSOR_HAND, RearrangeCursorXpm, 16, 16);
573  static auto clickedCursor =
574  ::MakeCursor(wxCURSOR_HAND, RearrangingCursorXpm, 16, 16);
575  return {
576  XO("Click and drag to rearrange sub-views"),
577  Clicked() ? &*clickedCursor : &*hoverCursor,
578  XO("Rearrange sub-views")
579  };
580  }

References MakeCursor(), and XO.

Here is the call graph for this function:

◆ Release()

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

Implements UIHandle.

Definition at line 582 of file WaveTrackView.cpp.

585  {
586  ProjectHistory::Get( *pProject ).ModifyState( false );
588  }

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}::SubViewRearrangeHandle::mAdjuster
private

Definition at line 598 of file WaveTrackView.cpp.

◆ mHeights

std::vector<wxCoord> anonymous_namespace{WaveTrackView.cpp}::SubViewRearrangeHandle::mHeights
private

Definition at line 599 of file WaveTrackView.cpp.

◆ mMySubView

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

Definition at line 603 of file WaveTrackView.cpp.

◆ mTopY

wxCoord anonymous_namespace{WaveTrackView.cpp}::SubViewRearrangeHandle::mTopY
private

Definition at line 600 of file WaveTrackView.cpp.

◆ mViewHeight

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

Definition at line 605 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}::SubViewRearrangeHandle::Clicked
bool Clicked() const
Definition: WaveTrackView.cpp:496
RefreshCode::RefreshAll
@ RefreshAll
Definition: RefreshCode.h:26
RefreshCode::RefreshNone
@ RefreshNone
Definition: RefreshCode.h:21
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}::SubViewRearrangeHandle::mMySubView
size_t mMySubView
Definition: WaveTrackView.cpp:603
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
anonymous_namespace{WaveTrackView.cpp}::SubViewRearrangeHandle::mAdjuster
SubViewAdjuster mAdjuster
Definition: WaveTrackView.cpp:598
RefreshCode::Cancelled
@ Cancelled
Definition: RefreshCode.h:23
XO
#define XO(s)
Definition: Internat.h:31
WaveTrackView::GetMultiView
bool GetMultiView() const
Definition: WaveTrackView.h:122
kTrackInfoBtnSize
@ kTrackInfoBtnSize
Definition: ViewInfo.h:111
WaveTrackView::GetLastHeight
wxCoord GetLastHeight() const
Definition: WaveTrackView.h:120
TrackPanelMouseState::rect
const wxRect & rect
Definition: TrackPanelMouseEvent.h:39
anonymous_namespace{WaveTrackView.cpp}::SubViewRearrangeHandle::Neutral
@ Neutral
Definition: WaveTrackView.cpp:498
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjuster::ComputeHeights
std::vector< wxCoord > ComputeHeights(wxCoord totalHeight)
Definition: WaveTrackView.cpp:164
anonymous_namespace{WaveTrackView.cpp}::SubViewRearrangeHandle::HotZoneWidth
@ HotZoneWidth
Definition: WaveTrackView.cpp:423
anonymous_namespace{WaveTrackView.cpp}::SubViewRearrangeHandle::Downward
@ Downward
Definition: WaveTrackView.cpp:498
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjuster::mNewPlacements
WaveTrackSubViewPlacements mNewPlacements
Definition: WaveTrackView.cpp:201
UIHandlePtr
std::shared_ptr< UIHandle > UIHandlePtr
Definition: CellularPanel.h:28
anonymous_namespace{NoteTrack.cpp}::swap
void swap(std::unique_ptr< Alg_seq > &a, std::unique_ptr< Alg_seq > &b)
Definition: NoteTrack.cpp:735
anonymous_namespace{WaveTrackView.cpp}::SubViewRearrangeHandle::DragChoice
DragChoice_t DragChoice(const TrackPanelMouseEvent &event) const
Definition: WaveTrackView.cpp:500
anonymous_namespace{WaveTrackView.cpp}::SubViewRearrangeHandle::mViewHeight
wxCoord mViewHeight
Definition: WaveTrackView.cpp:605
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
anonymous_namespace{WaveTrackView.cpp}::SubViewRearrangeHandle::mHeights
std::vector< wxCoord > mHeights
Definition: WaveTrackView.cpp:599
anonymous_namespace{WaveTrackView.cpp}::SubViewRearrangeHandle::Upward
@ Upward
Definition: WaveTrackView.cpp:498
TrackPanelMouseState::state
wxMouseState & state
Definition: TrackPanelMouseEvent.h:38
ProjectHistory::Get
static ProjectHistory & Get(AudacityProject &project)
Definition: ProjectHistory.cpp:26
anonymous_namespace{WaveTrackView.cpp}::SubViewRearrangeHandle::mTopY
wxCoord mTopY
Definition: WaveTrackView.cpp:600