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)
 
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)
 
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 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 454 of file WaveChannelView.cpp.

455 {
456 mAdjuster.UpdateViews( true );
458 }
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 308 of file WaveChannelView.cpp.

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

References Cancelled, SubViewAdjuster::ComputeHeights(), PackedArray::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 361 of file WaveChannelView.cpp.

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

◆ 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:151
bool GetMultiView() const
static bool HitTest(const WaveClip &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 434 of file WaveChannelView.cpp.

436 {
437 static auto resizeCursor =
438 ::MakeCursor(wxCURSOR_ARROW, SubViewsCursorXpm, 16, 16);
439 return {
440 XO(
441"Click and drag to adjust sizes of sub-views, double-click to split evenly"),
442 &*resizeCursor
443 };
444 }
XO("Cut/Copy/Paste")
std::unique_ptr< wxCursor > MakeCursor(int WXUNUSED(CursorId), const char *const pXpm[36], int HotX, int HotY)
Definition: TrackPanel.cpp:187

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 446 of file WaveChannelView.cpp.

449 {
450 ProjectHistory::Get( *pProject ).ModifyState( false );
452 }

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 462 of file WaveChannelView.cpp.

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

◆ mMySubView

size_t SubViewAdjustHandle::mMySubView {}
private

Definition at line 466 of file WaveChannelView.cpp.

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

◆ mOrigHeight

wxCoord SubViewAdjustHandle::mOrigHeight {}
private

Definition at line 471 of file WaveChannelView.cpp.

Referenced by Click(), and Drag().

◆ mOrigHeights

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

Definition at line 463 of file WaveChannelView.cpp.

Referenced by Click(), and Drag().

◆ mOrigY

wxCoord SubViewAdjustHandle::mOrigY {}
private

Definition at line 472 of file WaveChannelView.cpp.

Referenced by Click(), and Drag().

◆ mTop

bool SubViewAdjustHandle::mTop {}
private

Definition at line 475 of file WaveChannelView.cpp.

Referenced by Click(), and Drag().

◆ mTotalHeight

wxCoord SubViewAdjustHandle::mTotalHeight {}
private

Definition at line 470 of file WaveChannelView.cpp.

Referenced by Click(), and Drag().

◆ mViewHeight

wxCoord SubViewAdjustHandle::mViewHeight {}
private

Definition at line 469 of file WaveChannelView.cpp.

Referenced by Click().

◆ mYMax

wxCoord SubViewAdjustHandle::mYMax {}
private

Definition at line 468 of file WaveChannelView.cpp.

Referenced by Click(), and Drag().

◆ mYMin

wxCoord SubViewAdjustHandle::mYMin {}
private

Definition at line 468 of file WaveChannelView.cpp.

Referenced by Click(), and Drag().


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