Audacity  3.2.0
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 (AudacityProject *pProject) const
 
virtual bool Escape (AudacityProject *pProject)
 
virtual bool HandlesRightClick ()
 Whether the handle has any special right-button handling. More...
 
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< SubViewAdjustHandle > &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 221 of file WaveTrackView.cpp.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
MinHeight 

Definition at line 224 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 250 of file WaveTrackView.cpp.

253  : mAdjuster{ std::move( adjuster ) }
254  , mMySubView{ subViewIndex }
255  , mViewHeight{ viewHeight }
256  , mTop{ top }
257  {
258  if ( mAdjuster.ModifyPermutation( top ) )
259  --mMySubView;
260  }

Member Function Documentation

◆ Cancel()

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

Implements UIHandle.

Definition at line 408 of file WaveTrackView.cpp.

409  {
410  mAdjuster.UpdateViews( true );
412  }

References RefreshCode::RefreshAll.

◆ Click()

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

Implements UIHandle.

Definition at line 262 of file WaveTrackView.cpp.

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

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

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 315 of file WaveTrackView.cpp.

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

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

Here is the call graph for this function:

◆ HitTest()

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

Definition at line 226 of file WaveTrackView.cpp.

230  {
231  if ( !view.GetMultiView() )
232  return {};
233 
234  SubViewAdjuster adjuster{ view };
235  auto hit = adjuster.HitTest( subView,
236  state.state.GetY(), state.rect.GetTop(), state.rect.GetHeight() );
237  auto index = hit.first;
238 
239  if ( index < adjuster.mPermutation.size() ) {
240  auto result = std::make_shared< SubViewAdjustHandle >(
241  std::move( adjuster ), index, view.GetLastHeight(), hit.second
242  );
243  result = AssignUIHandlePtr( holder, result );
244  return result;
245  }
246  else
247  return {};
248  }

References AssignUIHandlePtr(), WaveTrackView::GetLastHeight(), WaveTrackView::GetMultiView(), WaveTrackView::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 388 of file WaveTrackView.cpp.

390  {
391  static auto resizeCursor =
392  ::MakeCursor(wxCURSOR_ARROW, SubViewsCursorXpm, 16, 16);
393  return {
394  XO(
395 "Click and drag to adjust sizes of sub-views, double-click to split evenly"),
396  &*resizeCursor
397  };
398  }

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 400 of file WaveTrackView.cpp.

403  {
404  ProjectHistory::Get( *pProject ).ModifyState( false );
406  }

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 416 of file WaveTrackView.cpp.

◆ mMySubView

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

Definition at line 420 of file WaveTrackView.cpp.

◆ mOrigHeight

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

Definition at line 425 of file WaveTrackView.cpp.

◆ mOrigHeights

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

Definition at line 417 of file WaveTrackView.cpp.

◆ mOrigY

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

Definition at line 426 of file WaveTrackView.cpp.

◆ mTop

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

Definition at line 429 of file WaveTrackView.cpp.

◆ mTotalHeight

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

Definition at line 424 of file WaveTrackView.cpp.

◆ mViewHeight

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

Definition at line 423 of file WaveTrackView.cpp.

◆ mYMax

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

Definition at line 422 of file WaveTrackView.cpp.

◆ mYMin

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

Definition at line 422 of file WaveTrackView.cpp.


The documentation for this class was generated from the following file:
size
size_t size
Definition: ffmpeg-2.3.6-single-header.h:412
ProjectHistory::ModifyState
void ModifyState(bool bWantsAutoSave)
Definition: ProjectHistory.cpp:124
WaveTrackView::HitTest
static bool HitTest(const WaveClip &clip, const ZoomInfo &zoomInfo, const wxRect &rect, const wxPoint &pos)
Definition: WaveTrackView.cpp:1380
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjustHandle::mTotalHeight
wxCoord mTotalHeight
Definition: WaveTrackView.cpp:424
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:423
MakeCursor
std::unique_ptr< wxCursor > MakeCursor(int WXUNUSED(CursorId), const char *const pXpm[36], int HotX, int HotY)
Definition: TrackPanel.cpp:182
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjuster::UpdateViews
void UpdateViews(bool rollback)
Definition: WaveTrackView.cpp:201
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjuster::mFirstSubView
size_t mFirstSubView
Definition: WaveTrackView.cpp:218
RefreshCode::Cancelled
@ Cancelled
Definition: RefreshCode.h:23
XO
#define XO(s)
Definition: Internat.h:31
WaveTrackView::GetMultiView
bool GetMultiView() const
Definition: WaveTrackView.h:154
WaveTrackView::GetLastHeight
wxCoord GetLastHeight() const
Definition: WaveTrackView.h:152
TrackPanelMouseState::rect
const wxRect & rect
Definition: TrackPanelMouseEvent.h:39
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjuster::ComputeHeights
std::vector< wxCoord > ComputeHeights(wxCoord totalHeight)
Definition: WaveTrackView.cpp:177
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjustHandle::MinHeight
@ MinHeight
Definition: WaveTrackView.cpp:224
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjuster::mNewPlacements
WaveTrackSubViewPlacements mNewPlacements
Definition: WaveTrackView.cpp:214
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjustHandle::mOrigHeights
std::vector< wxCoord > mOrigHeights
Definition: WaveTrackView.cpp:417
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjustHandle::mOrigHeight
wxCoord mOrigHeight
Definition: WaveTrackView.cpp:425
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjustHandle::mYMin
wxCoord mYMin
Definition: WaveTrackView.cpp:422
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjustHandle::mMySubView
size_t mMySubView
Definition: WaveTrackView.cpp:420
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjustHandle::mTop
bool mTop
Definition: WaveTrackView.cpp:429
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjuster::ModifyPermutation
bool ModifyPermutation(bool top)
Definition: WaveTrackView.cpp:111
min
int min(int a, int b)
Definition: CompareAudioCommand.cpp:106
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjustHandle::mYMax
wxCoord mYMax
Definition: WaveTrackView.cpp:422
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjuster::HotZoneSize
@ HotZoneSize
Definition: WaveTrackView.cpp:62
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjustHandle::mAdjuster
SubViewAdjuster mAdjuster
Definition: WaveTrackView.cpp:416
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjuster::mPermutation
std::vector< size_t > mPermutation
Definition: WaveTrackView.cpp:216
AssignUIHandlePtr
std::shared_ptr< Subclass > AssignUIHandlePtr(std::weak_ptr< Subclass > &holder, const std::shared_ptr< Subclass > &pNew)
Definition: UIHandle.h:151
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:212
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:426