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

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
MinHeight 

Definition at line 222 of file WaveTrackView.cpp.

Constructor & Destructor Documentation

◆ SubViewAdjustHandle()

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

Definition at line 248 of file WaveTrackView.cpp.

251 : mAdjuster{ std::move( adjuster ) }
252 , mMySubView{ subViewIndex }
253 , mViewHeight{ viewHeight }
254 , mTop{ top }
255 {
256 if ( mAdjuster.ModifyPermutation( top ) )
257 --mMySubView;
258 }
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 406 of file WaveTrackView.cpp.

407 {
408 mAdjuster.UpdateViews( true );
410 }
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 260 of file WaveTrackView.cpp.

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

References RefreshCode::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 313 of file WaveTrackView.cpp.

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

References RefreshCode::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,
WaveTrackView view,
WaveTrackSubView subView,
const TrackPanelMouseState state 
)
inlinestatic

Definition at line 224 of file WaveTrackView.cpp.

228 {
229 if ( !view.GetMultiView() )
230 return {};
231
232 SubViewAdjuster adjuster{ view };
233 auto hit = adjuster.HitTest( subView,
234 state.state.GetY(), state.rect.GetTop(), state.rect.GetHeight() );
235 auto index = hit.first;
236
237 if ( index < adjuster.mPermutation.size() ) {
238 auto result = std::make_shared< SubViewAdjustHandle >(
239 std::move( adjuster ), index, view.GetLastHeight(), hit.second
240 );
241 result = AssignUIHandlePtr( holder, result );
242 return result;
243 }
244 else
245 return {};
246 }
std::shared_ptr< Subclass > AssignUIHandlePtr(std::weak_ptr< Subclass > &holder, const std::shared_ptr< Subclass > &pNew)
Definition: UIHandle.h:151
wxCoord GetLastHeight() const
bool GetMultiView() const
static bool HitTest(const WaveClip &clip, const ZoomInfo &zoomInfo, const wxRect &rect, const wxPoint &pos)

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

Referenced by WaveTrackSubView::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 386 of file WaveTrackView.cpp.

388 {
389 static auto resizeCursor =
390 ::MakeCursor(wxCURSOR_ARROW, SubViewsCursorXpm, 16, 16);
391 return {
392 XO(
393"Click and drag to adjust sizes of sub-views, double-click to split evenly"),
394 &*resizeCursor
395 };
396 }
XO("Cut/Copy/Paste")
std::unique_ptr< wxCursor > MakeCursor(int WXUNUSED(CursorId), const char *const pXpm[36], int HotX, int HotY)
Definition: TrackPanel.cpp:186

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

401 {
402 ProjectHistory::Get( *pProject ).ModifyState( false );
404 }

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

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

◆ mMySubView

size_t SubViewAdjustHandle::mMySubView {}
private

Definition at line 418 of file WaveTrackView.cpp.

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

◆ mOrigHeight

wxCoord SubViewAdjustHandle::mOrigHeight {}
private

Definition at line 423 of file WaveTrackView.cpp.

Referenced by Click(), and Drag().

◆ mOrigHeights

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

Definition at line 415 of file WaveTrackView.cpp.

Referenced by Click(), and Drag().

◆ mOrigY

wxCoord SubViewAdjustHandle::mOrigY {}
private

Definition at line 424 of file WaveTrackView.cpp.

Referenced by Click(), and Drag().

◆ mTop

bool SubViewAdjustHandle::mTop {}
private

Definition at line 427 of file WaveTrackView.cpp.

Referenced by Click(), and Drag().

◆ mTotalHeight

wxCoord SubViewAdjustHandle::mTotalHeight {}
private

Definition at line 422 of file WaveTrackView.cpp.

Referenced by Click(), and Drag().

◆ mViewHeight

wxCoord SubViewAdjustHandle::mViewHeight {}
private

Definition at line 421 of file WaveTrackView.cpp.

Referenced by Click().

◆ mYMax

wxCoord SubViewAdjustHandle::mYMax {}
private

Definition at line 420 of file WaveTrackView.cpp.

Referenced by Click(), and Drag().

◆ mYMin

wxCoord SubViewAdjustHandle::mYMin {}
private

Definition at line 420 of file WaveTrackView.cpp.

Referenced by Click(), and Drag().


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