Audacity 3.2.0
Public Types | Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
SubViewAdjustHandle Class Reference
Inheritance diagram for SubViewAdjustHandle:
[legend]
Collaboration diagram for 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)
 
std::shared_ptr< const TrackFindTrack () const override
 
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 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)
 
virtual std::shared_ptr< const TrackFindTrack () const =0
 
virtual bool IsDragging () const
 
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, WaveChannelView &view, WaveChannelSubView &subView, const TrackPanelMouseState &state)
 
- Static Public Member Functions inherited from UIHandle
static UIHandle::Result NeedChangeHighlight (const UIHandle &, const UIHandle &)
 
static std::shared_ptr< const TrackTrackFromChannel (const std::shared_ptr< const Channel > &pChannel)
 A frequent convenience in the definition of UIHandles. More...
 
- 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 267 of file WaveChannelView.cpp.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
MinHeight 

Definition at line 270 of file WaveChannelView.cpp.

Constructor & Destructor Documentation

◆ SubViewAdjustHandle()

SubViewAdjustHandle::SubViewAdjustHandle ( SubViewAdjuster &&  adjuster,
size_t  subViewIndex,
wxCoord  viewHeight,
bool  top 
)
inline

Definition at line 296 of file WaveChannelView.cpp.

299 : mAdjuster{ std::move( adjuster ) }
300 , mMySubView{ subViewIndex }
301 , mViewHeight{ viewHeight }
302 , mTop{ top }
303 {
304 if ( mAdjuster.ModifyPermutation( top ) )
305 --mMySubView;
306 }
SubViewAdjuster mAdjuster
bool ModifyPermutation(bool top)

References mAdjuster, mMySubView, and SubViewAdjuster::ModifyPermutation().

Here is the call graph for this function:

Member Function Documentation

◆ Cancel()

Result SubViewAdjustHandle::Cancel ( AudacityProject )
inlineoverridevirtual

Implements UIHandle.

Definition at line 462 of file WaveChannelView.cpp.

463 {
464 mAdjuster.UpdateViews( true );
466 }
void UpdateViews(bool rollback)

References mAdjuster, RefreshCode::RefreshAll, and SubViewAdjuster::UpdateViews().

Here is the call graph for this function:

◆ Click()

Result SubViewAdjustHandle::Click ( const TrackPanelMouseEvent event,
AudacityProject pProject 
)
inlineoverridevirtual

Implements UIHandle.

Definition at line 316 of file WaveChannelView.cpp.

318 {
319 using namespace RefreshCode;
320 const auto &permutation = mAdjuster.mPermutation;
321 const auto size = permutation.size();
322 if ( mMySubView >= size )
323 return Cancelled;
324
325 if (event.event.LeftDClick()) {
326 for ( auto &placement : mAdjuster.mNewPlacements ) {
327 if ( placement.index >= 0 )
328 placement.fraction = 1.0f;
329 else
330 placement.fraction = 0.0f;
331 }
332 mAdjuster.UpdateViews( false );
333 ProjectHistory::Get( *pProject ).ModifyState( false );
334
335 // Do not start a drag
336 return Cancelled | RefreshAll;
337 }
338
339 const auto &rect = event.rect;
340 const auto height = rect.GetHeight();
341 mOrigHeight = height;
342
344
345 // Find the total height of the sub-views that may resize
346 mTotalHeight = 0;
347 auto index = ( mTop ? mAdjuster.mFirstSubView : mMySubView );
348 const auto end = ( mTop ? mMySubView + 1 : permutation.size() );
349 for (; index != end; ++index)
350 mTotalHeight += mOrigHeights[ index ];
351
352 wxASSERT( height == mOrigHeights[ mMySubView ] );
353
354 // Compute the maximum and minimum Y coordinates for drag effect
355 if ( mTop ) {
356 mOrigY = rect.GetTop();
357 mYMax = rect.GetBottom();
358 mYMin = mYMax - mTotalHeight + 1;
359 }
360 else {
361 mOrigY = rect.GetBottom();
362 mYMin = rect.GetTop();
363 mYMax = mYMin + mTotalHeight - 1;
364 }
365
366 return RefreshNone;
367 }
void ModifyState(bool bWantsAutoSave)
static ProjectHistory & Get(AudacityProject &project)
std::vector< wxCoord > mOrigHeights
Namespace containing an enum 'what to do on a refresh?'.
Definition: RefreshCode.h:16
const char * end(const char *str) noexcept
Definition: StringUtils.h:106
WaveChannelSubViewPlacements mNewPlacements
std::vector< wxCoord > ComputeHeights(wxCoord totalHeight)
std::vector< size_t > mPermutation

References Cancelled, SubViewAdjuster::ComputeHeights(), details::end(), TrackPanelMouseEvent::event, ProjectHistory::Get(), mAdjuster, SubViewAdjuster::mFirstSubView, mMySubView, SubViewAdjuster::mNewPlacements, ProjectHistory::ModifyState(), mOrigHeight, mOrigHeights, mOrigY, SubViewAdjuster::mPermutation, mTop, mTotalHeight, mViewHeight, mYMax, mYMin, RefreshCode::RefreshAll, RefreshCode::RefreshNone, size, and SubViewAdjuster::UpdateViews().

Here is the call graph for this function:

◆ Drag()

Result SubViewAdjustHandle::Drag ( const TrackPanelMouseEvent event,
AudacityProject  
)
inlineoverridevirtual

Implements UIHandle.

Definition at line 369 of file WaveChannelView.cpp.

370 {
371 using namespace RefreshCode;
372 auto pView = mAdjuster.mwView.lock();
373 if ( !pView )
374 return Cancelled;
375
376 // Find new height for the dragged sub-view
377 auto newY = std::max( mYMin, std::min( mYMax, event.event.GetY() ) );
378 const auto delta = newY - mOrigY;
379 wxCoord newHeight = mTop
380 ? mOrigHeight - delta
381 : mOrigHeight + delta
382 ;
383 wxASSERT( newHeight >= 0 && newHeight <= mTotalHeight );
384 if ( newHeight < MinHeight )
385 // Snap the dragged sub-view to nothing
386 newHeight = 0;
387
388 // Reassign height for the dragged sub-view
389 auto &myPlacement =
391 myPlacement.fraction = newHeight;
392
393 // Grow or shrink other sub-views
394 auto excess = newHeight - mOrigHeight; // maybe negative
395 const auto adjustHeight = [&](size_t ii) {
396 if (excess == 0)
397 return true;
398
399 const auto oldFraction = mOrigHeights[ ii ];
400
401 auto index = mAdjuster.mPermutation[ ii ];
402 auto &placement = mAdjuster.mNewPlacements[ index ];
403 auto &fraction = placement.fraction;
404
405 if (excess > oldFraction) {
406 excess -= oldFraction, fraction = 0;
407 return false;
408 }
409 else {
410 auto newFraction = oldFraction - excess;
411 if ( newFraction < MinHeight ) {
412 // This snaps very short sub-views to nothing
413 myPlacement.fraction += newFraction;
414 fraction = 0;
415 }
416 else
417 fraction = newFraction;
418 return true;
419 }
420 };
421 if ( mTop ) {
422 for ( size_t ii = mMySubView; ii > 0; ) {
423 --ii;
424 if ( adjustHeight( ii ) )
425 break;
426 }
427 }
428 else {
429 for ( size_t ii = mMySubView + 1, size = mAdjuster.mPermutation.size();
430 ii < size; ++ii
431 ) {
432 if ( adjustHeight( ii ) )
433 break;
434 }
435 }
436
437 // Save adjustment to the track and request a redraw
438 mAdjuster.UpdateViews( false );
439 return RefreshAll;
440 }
int min(int a, int b)
std::weak_ptr< WaveChannelView > mwView

References Cancelled, TrackPanelMouseEvent::event, mAdjuster, min(), MinHeight, mMySubView, SubViewAdjuster::mNewPlacements, mOrigHeight, mOrigHeights, mOrigY, SubViewAdjuster::mPermutation, mTop, mTotalHeight, SubViewAdjuster::mwView, mYMax, mYMin, RefreshCode::RefreshAll, size, and SubViewAdjuster::UpdateViews().

Here is the call graph for this function:

◆ FindTrack()

std::shared_ptr< const Track > SubViewAdjustHandle::FindTrack ( ) const
inlineoverridevirtual
Returns
pointer to associated track, if any

Implements UIHandle.

Definition at line 308 of file WaveChannelView.cpp.

309 {
310 auto pView = mAdjuster.mwView.lock();
311 if (pView)
312 return TrackFromChannel(pView->FindChannel());
313 return nullptr;
314 }
static std::shared_ptr< const Track > TrackFromChannel(const std::shared_ptr< const Channel > &pChannel)
A frequent convenience in the definition of UIHandles.
Definition: UIHandle.cpp:63

References mAdjuster, SubViewAdjuster::mwView, and UIHandle::TrackFromChannel().

Here is the call graph for this function:

◆ HitTest()

static UIHandlePtr SubViewAdjustHandle::HitTest ( std::weak_ptr< SubViewAdjustHandle > &  holder,
WaveChannelView view,
WaveChannelSubView subView,
const TrackPanelMouseState state 
)
inlinestatic

Definition at line 272 of file WaveChannelView.cpp.

276 {
277 if ( !view.GetMultiView() )
278 return {};
279
280 SubViewAdjuster adjuster{ view };
281 auto hit = adjuster.HitTest( subView,
282 state.state.GetY(), state.rect.GetTop(), state.rect.GetHeight() );
283 auto index = hit.first;
284
285 if ( index < adjuster.mPermutation.size() ) {
286 auto result = std::make_shared< SubViewAdjustHandle >(
287 std::move( adjuster ), index, view.GetLastHeight(), hit.second
288 );
289 result = AssignUIHandlePtr( holder, result );
290 return result;
291 }
292 else
293 return {};
294 }
std::shared_ptr< Subclass > AssignUIHandlePtr(std::weak_ptr< Subclass > &holder, const std::shared_ptr< Subclass > &pNew)
Definition: UIHandle.h:164
bool GetMultiView() const
static bool HitTest(const ClipTimes &clip, const ZoomInfo &zoomInfo, const wxRect &rect, const wxPoint &pos)
wxCoord GetLastHeight() const

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

Referenced by WaveChannelSubView::DoDetailedHitTest().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Preview()

HitTestPreview SubViewAdjustHandle::Preview ( const TrackPanelMouseState state,
AudacityProject  
)
inlineoverridevirtual

Implements UIHandle.

Definition at line 442 of file WaveChannelView.cpp.

444 {
445 static auto resizeCursor =
446 ::MakeCursor(wxCURSOR_ARROW, SubViewsCursorXpm, 16, 16);
447 return {
448 XO(
449"Click and drag to adjust sizes of sub-views, double-click to split evenly"),
450 &*resizeCursor
451 };
452 }
XO("Cut/Copy/Paste")
std::unique_ptr< wxCursor > MakeCursor(int WXUNUSED(CursorId), const char *const pXpm[36], int HotX, int HotY)
Definition: TrackPanel.cpp:189

References MakeCursor(), and XO().

Here is the call graph for this function:

◆ Release()

Result SubViewAdjustHandle::Release ( const TrackPanelMouseEvent event,
AudacityProject pProject,
wxWindow *  pParent 
)
inlineoverridevirtual

Implements UIHandle.

Definition at line 454 of file WaveChannelView.cpp.

457 {
458 ProjectHistory::Get( *pProject ).ModifyState( false );
460 }

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

Here is the call graph for this function:

Member Data Documentation

◆ mAdjuster

SubViewAdjuster SubViewAdjustHandle::mAdjuster
private

Definition at line 470 of file WaveChannelView.cpp.

Referenced by Cancel(), Click(), Drag(), FindTrack(), and SubViewAdjustHandle().

◆ mMySubView

size_t SubViewAdjustHandle::mMySubView {}
private

Definition at line 474 of file WaveChannelView.cpp.

Referenced by Click(), Drag(), and SubViewAdjustHandle().

◆ mOrigHeight

wxCoord SubViewAdjustHandle::mOrigHeight {}
private

Definition at line 479 of file WaveChannelView.cpp.

Referenced by Click(), and Drag().

◆ mOrigHeights

std::vector<wxCoord> SubViewAdjustHandle::mOrigHeights
private

Definition at line 471 of file WaveChannelView.cpp.

Referenced by Click(), and Drag().

◆ mOrigY

wxCoord SubViewAdjustHandle::mOrigY {}
private

Definition at line 480 of file WaveChannelView.cpp.

Referenced by Click(), and Drag().

◆ mTop

bool SubViewAdjustHandle::mTop {}
private

Definition at line 483 of file WaveChannelView.cpp.

Referenced by Click(), and Drag().

◆ mTotalHeight

wxCoord SubViewAdjustHandle::mTotalHeight {}
private

Definition at line 478 of file WaveChannelView.cpp.

Referenced by Click(), and Drag().

◆ mViewHeight

wxCoord SubViewAdjustHandle::mViewHeight {}
private

Definition at line 477 of file WaveChannelView.cpp.

Referenced by Click().

◆ mYMax

wxCoord SubViewAdjustHandle::mYMax {}
private

Definition at line 476 of file WaveChannelView.cpp.

Referenced by Click(), and Drag().

◆ mYMin

wxCoord SubViewAdjustHandle::mYMin {}
private

Definition at line 476 of file WaveChannelView.cpp.

Referenced by Click(), and Drag().


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