Audacity 3.2.0
Public Member Functions | Private Member Functions | Private Attributes | List of all members
anonymous_namespace{RealtimeEffectPanel.cpp}::MovableControl Class Reference
Inheritance diagram for anonymous_namespace{RealtimeEffectPanel.cpp}::MovableControl:
[legend]
Collaboration diagram for anonymous_namespace{RealtimeEffectPanel.cpp}::MovableControl:
[legend]

Public Member Functions

 MovableControl ()=default
 
 MovableControl (wxWindow *parent, wxWindowID id, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0, const wxString &name=wxPanelNameStr)
 
void Create (wxWindow *parent, wxWindowID id, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0, const wxString &name=wxPanelNameStr)
 
void ProcessDragEvent (wxWindow *target, wxEventType eventType)
 
int FindIndexInParent () const
 

Private Member Functions

void OnKeyDown (wxKeyEvent &evt)
 
void OnMouseCaptureLost (wxMouseCaptureLostEvent &event)
 
void DragFinished ()
 
void OnMouseDown (wxMouseEvent &evt)
 
void OnMouseUp (wxMouseEvent &evt)
 
void OnMove (wxMouseEvent &evt)
 

Private Attributes

bool mDragging { false }
 
wxPoint mInitialPosition
 
int mTargetIndex { -1 }
 
int mSourceIndex { -1 }
 

Detailed Description

Definition at line 338 of file RealtimeEffectPanel.cpp.

Constructor & Destructor Documentation

◆ MovableControl() [1/2]

anonymous_namespace{RealtimeEffectPanel.cpp}::MovableControl::MovableControl ( )
default

◆ MovableControl() [2/2]

anonymous_namespace{RealtimeEffectPanel.cpp}::MovableControl::MovableControl ( wxWindow *  parent,
wxWindowID  id,
const wxPoint &  pos = wxDefaultPosition,
const wxSize &  size = wxDefaultSize,
long  style = 0,
const wxString &  name = wxPanelNameStr 
)
inline

Definition at line 349 of file RealtimeEffectPanel.cpp.

355 {
356 Create(parent, id, pos, size, style, name);
357 }
const TranslatableString name
Definition: Distortion.cpp:75
void Create(wxWindow *parent, wxWindowID id, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0, const wxString &name=wxPanelNameStr)

References name, and size.

Member Function Documentation

◆ Create()

void anonymous_namespace{RealtimeEffectPanel.cpp}::MovableControl::Create ( wxWindow *  parent,
wxWindowID  id,
const wxPoint &  pos = wxDefaultPosition,
const wxSize &  size = wxDefaultSize,
long  style = 0,
const wxString &  name = wxPanelNameStr 
)
inline

Definition at line 359 of file RealtimeEffectPanel.cpp.

365 {
366 wxWindow::Create(parent, id, pos, size, style, name);
367 Bind(wxEVT_LEFT_DOWN, &MovableControl::OnMouseDown, this);
368 Bind(wxEVT_LEFT_UP, &MovableControl::OnMouseUp, this);
369 Bind(wxEVT_MOTION, &MovableControl::OnMove, this);
370 Bind(wxEVT_KEY_DOWN, &MovableControl::OnKeyDown, this);
371 Bind(wxEVT_MOUSE_CAPTURE_LOST, &MovableControl::OnMouseCaptureLost, this);
372 }

References name, and size.

◆ DragFinished()

void anonymous_namespace{RealtimeEffectPanel.cpp}::MovableControl::DragFinished ( )
inlineprivate

Definition at line 444 of file RealtimeEffectPanel.cpp.

445 {
446 if(auto parent = GetParent())
447 {
448 wxWindowUpdateLocker freeze(this);
449 ProcessDragEvent(parent, EVT_MOVABLE_CONTROL_DRAG_FINISHED);
450 }
451 mDragging = false;
452 }
void ProcessDragEvent(wxWindow *target, wxEventType eventType)

◆ FindIndexInParent()

int anonymous_namespace{RealtimeEffectPanel.cpp}::MovableControl::FindIndexInParent ( ) const
inline

Definition at line 383 of file RealtimeEffectPanel.cpp.

384 {
385 auto parent = GetParent();
386 if(!parent)
387 return -1;
388
389 if(auto sizer = parent->GetSizer())
390 {
391 for(size_t i = 0, count = sizer->GetItemCount(); i < count; ++i)
392 {
393 if(sizer->GetItem(i)->GetWindow() == this)
394 return static_cast<int>(i);
395 }
396 }
397 return -1;
398 }

◆ OnKeyDown()

void anonymous_namespace{RealtimeEffectPanel.cpp}::MovableControl::OnKeyDown ( wxKeyEvent &  evt)
inlineprivate

Definition at line 402 of file RealtimeEffectPanel.cpp.

403 {
404 const auto keyCode = evt.GetKeyCode();
405 if(evt.AltDown() && (keyCode == WXK_DOWN || keyCode == WXK_UP))
406 {
407#ifdef __WXOSX__
408 {//don't allow auto-repeats
409 static long lastEventTimestamp = 0;
410 if(lastEventTimestamp == evt.GetTimestamp())
411 return;//don't skip
412 lastEventTimestamp = evt.GetTimestamp();
413 }
414#endif
415 const auto sourceIndex = FindIndexInParent();
416 if(sourceIndex == -1)
417 {
418 evt.Skip();
419 return;
420 }
421
422 const auto targetIndex = std::clamp(
423 keyCode == WXK_DOWN ? sourceIndex + 1 : sourceIndex - 1,
424 0,
425 static_cast<int>(GetParent()->GetSizer()->GetItemCount()) - 1
426 );
427 if(sourceIndex != targetIndex)
428 {
429 mSourceIndex = sourceIndex;
430 mTargetIndex = targetIndex;
431 ProcessDragEvent(GetParent(), EVT_MOVABLE_CONTROL_DRAG_FINISHED);
432 }
433 }
434 else
435 evt.Skip();
436 }

◆ OnMouseCaptureLost()

void anonymous_namespace{RealtimeEffectPanel.cpp}::MovableControl::OnMouseCaptureLost ( wxMouseCaptureLostEvent &  event)
inlineprivate

◆ OnMouseDown()

void anonymous_namespace{RealtimeEffectPanel.cpp}::MovableControl::OnMouseDown ( wxMouseEvent &  evt)
inlineprivate

Definition at line 454 of file RealtimeEffectPanel.cpp.

455 {
456 if(mDragging)
457 {
458 DragFinished();
459 return;
460 }
461
463 if(mSourceIndex != -1)
464 {
465 CaptureMouse();
466 ProcessDragEvent(GetParent(), EVT_MOVABLE_CONTROL_DRAG_STARTED);
467
468 mInitialPosition = evt.GetPosition();
469 mDragging=true;
470 }
471 }

◆ OnMouseUp()

void anonymous_namespace{RealtimeEffectPanel.cpp}::MovableControl::OnMouseUp ( wxMouseEvent &  evt)
inlineprivate

Definition at line 473 of file RealtimeEffectPanel.cpp.

474 {
475 if(!mDragging)
476 return;
477
478 ReleaseMouse();
479
480 DragFinished();
481 }

◆ OnMove()

void anonymous_namespace{RealtimeEffectPanel.cpp}::MovableControl::OnMove ( wxMouseEvent &  evt)
inlineprivate

Definition at line 483 of file RealtimeEffectPanel.cpp.

484 {
485 if(!mDragging)
486 return;
487
488 auto parent = GetParent();
489 if(!parent)
490 return;
491
492 wxPoint newPosition = wxGetMousePosition() - mInitialPosition;
493 Move(GetParent()->ScreenToClient(newPosition));
494
495 if(auto boxSizer = dynamic_cast<wxBoxSizer*>(parent->GetSizer()))
496 {
497 if(boxSizer->GetOrientation() == wxVERTICAL)
498 {
499 auto targetIndex = mSourceIndex;
500
501 //assuming that items are ordered from top to bottom (i > j <=> y(i) > y(j))
502 //compare wxSizerItem position with the current MovableControl position!
503 if(GetPosition().y < boxSizer->GetItem(mSourceIndex)->GetPosition().y)
504 {
505 //moving up
506 for(int i = 0; i < mSourceIndex; ++i)
507 {
508 const auto item = boxSizer->GetItem(i);
509
510 if(GetRect().GetTop() <= item->GetPosition().y + item->GetSize().y / 2)
511 {
512 targetIndex = i;
513 break;
514 }
515 }
516 }
517 else
518 {
519 //moving down
520 for(int i = static_cast<int>(boxSizer->GetItemCount()) - 1; i > mSourceIndex; --i)
521 {
522 const auto item = boxSizer->GetItem(i);
523 if(GetRect().GetBottom() >= item->GetPosition().y + item->GetSize().y / 2)
524 {
525 targetIndex = i;
526 break;
527 }
528 }
529 }
530
531 if(targetIndex != mTargetIndex)
532 {
533 mTargetIndex = targetIndex;
534 ProcessDragEvent(parent, EVT_MOVABLE_CONTROL_DRAG_POSITION);
535 }
536 }
537 }
538 }

◆ ProcessDragEvent()

void anonymous_namespace{RealtimeEffectPanel.cpp}::MovableControl::ProcessDragEvent ( wxWindow *  target,
wxEventType  eventType 
)
inline

Definition at line 374 of file RealtimeEffectPanel.cpp.

375 {
376 MovableControlEvent event(eventType);
377 event.SetSourceIndex(mSourceIndex);
378 event.SetTargetIndex(mTargetIndex);
379 event.SetEventObject(this);
380 target->GetEventHandler()->ProcessEvent(event);
381 }

Member Data Documentation

◆ mDragging

bool anonymous_namespace{RealtimeEffectPanel.cpp}::MovableControl::mDragging { false }
private

Definition at line 340 of file RealtimeEffectPanel.cpp.

◆ mInitialPosition

wxPoint anonymous_namespace{RealtimeEffectPanel.cpp}::MovableControl::mInitialPosition
private

Definition at line 341 of file RealtimeEffectPanel.cpp.

◆ mSourceIndex

int anonymous_namespace{RealtimeEffectPanel.cpp}::MovableControl::mSourceIndex { -1 }
private

Definition at line 344 of file RealtimeEffectPanel.cpp.

◆ mTargetIndex

int anonymous_namespace{RealtimeEffectPanel.cpp}::MovableControl::mTargetIndex { -1 }
private

Definition at line 343 of file RealtimeEffectPanel.cpp.


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