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 334 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 345 of file RealtimeEffectPanel.cpp.

351 {
352 Create(parent, id, pos, size, style, name);
353 }
const TranslatableString name
Definition: Distortion.cpp:82
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 355 of file RealtimeEffectPanel.cpp.

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

References name, and size.

◆ DragFinished()

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

Definition at line 440 of file RealtimeEffectPanel.cpp.

441 {
442 if(auto parent = GetParent())
443 {
444 wxWindowUpdateLocker freeze(this);
445 ProcessDragEvent(parent, EVT_MOVABLE_CONTROL_DRAG_FINISHED);
446 }
447 mDragging = false;
448 }
void ProcessDragEvent(wxWindow *target, wxEventType eventType)

◆ FindIndexInParent()

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

Definition at line 379 of file RealtimeEffectPanel.cpp.

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

◆ OnKeyDown()

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

Definition at line 398 of file RealtimeEffectPanel.cpp.

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

◆ 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 450 of file RealtimeEffectPanel.cpp.

451 {
452 if(mDragging)
453 {
454 DragFinished();
455 return;
456 }
457
459 if(mSourceIndex != -1)
460 {
461 CaptureMouse();
462 ProcessDragEvent(GetParent(), EVT_MOVABLE_CONTROL_DRAG_STARTED);
463
464 mInitialPosition = evt.GetPosition();
465 mDragging=true;
466 }
467 }

◆ OnMouseUp()

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

Definition at line 469 of file RealtimeEffectPanel.cpp.

470 {
471 if(!mDragging)
472 return;
473
474 ReleaseMouse();
475
476 DragFinished();
477 }

◆ OnMove()

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

Definition at line 479 of file RealtimeEffectPanel.cpp.

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

◆ ProcessDragEvent()

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

Definition at line 370 of file RealtimeEffectPanel.cpp.

371 {
372 MovableControlEvent event(eventType);
373 event.SetSourceIndex(mSourceIndex);
374 event.SetTargetIndex(mTargetIndex);
375 event.SetEventObject(this);
376 target->GetEventHandler()->ProcessEvent(event);
377 }

Member Data Documentation

◆ mDragging

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

Definition at line 336 of file RealtimeEffectPanel.cpp.

◆ mInitialPosition

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

Definition at line 337 of file RealtimeEffectPanel.cpp.

◆ mSourceIndex

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

Definition at line 340 of file RealtimeEffectPanel.cpp.

◆ mTargetIndex

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

Definition at line 339 of file RealtimeEffectPanel.cpp.


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