1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-07-31 07:59:27 +02:00

Move note track control panel click handling out of TrackPanel.cpp

This commit is contained in:
Paul Licameli 2015-08-04 18:20:37 -04:00 committed by Paul Licameli
parent e4627b1668
commit 46b97084eb
2 changed files with 130 additions and 25 deletions

View File

@ -3083,30 +3083,6 @@ void TrackPanel::HandleLabelClick(wxMouseEvent & event)
auto &t = foundCell.pTrack;
auto &rect = foundCell.rect;
{
#ifdef USE_MIDI
// DM: If it's a NoteTrack, it has special controls
if (t->GetKind() == Track::Note)
{
#ifdef EXPERIMENTAL_MIDI_OUT
wxRect midiRect;
mTrackInfo.GetMidiControlsRect(rect, midiRect);
bool isright = event.Button(wxMOUSE_BTN_RIGHT);
if ( !TrackInfo::HideTopItem( rect, midiRect ) &&
(isleft || isright) && midiRect.Contains(event.m_x, event.m_y) &&
static_cast<NoteTrack *>(t)->LabelClick(midiRect, event.m_x, event.m_y, isright)) {
MakeParentModifyState(false);
Refresh(false);
return;
}
#endif
}
#endif // USE_MIDI
}
if (!isleft) {
return;
}

View File

@ -23,7 +23,133 @@ Paul Licameli split from TrackPanel.cpp
#include "../../../../widgets/PopupMenuTable.h"
#include "../../../../Project.h"
#include "../../../../RefreshCode.h"
#include "../../../../TrackPanel.h"
#include "../../../../TrackPanelMouseEvent.h"
#include "../../../../UIHandle.h"
///////////////////////////////////////////////////////////////////////////////
// TODO: do appearance changes as in ButtonHandle, or even, inherit from that
class NoteTrackClickHandle : public UIHandle
{
NoteTrackClickHandle(const NoteTrackClickHandle&);
NoteTrackClickHandle &operator=(const NoteTrackClickHandle&);
NoteTrackClickHandle();
virtual ~NoteTrackClickHandle();
static NoteTrackClickHandle& Instance();
public:
static HitTestResult HitTest
(const wxMouseEvent &event, const wxRect &rect, Track *pTrack);
protected:
virtual Result Click
(const TrackPanelMouseEvent &event, AudacityProject *pProject);
virtual Result Drag
(const TrackPanelMouseEvent &event, AudacityProject *pProject);
virtual HitTestPreview Preview
(const TrackPanelMouseEvent &event, const AudacityProject *pProject);
virtual Result Release
(const TrackPanelMouseEvent &event, AudacityProject *pProject,
wxWindow *pParent);
virtual Result Cancel(AudacityProject *pProject);
void OnProjectChange(AudacityProject *pProject) override;
NoteTrack *mpTrack{};
wxRect mRect{};
};
NoteTrackClickHandle::NoteTrackClickHandle()
{
}
NoteTrackClickHandle::~NoteTrackClickHandle()
{
}
NoteTrackClickHandle &NoteTrackClickHandle::Instance()
{
static NoteTrackClickHandle instance;
return instance;
}
HitTestResult NoteTrackClickHandle::HitTest
(const wxMouseEvent &event, const wxRect &rect, Track *pTrack)
{
wxRect midiRect;
TrackInfo::GetMidiControlsRect(rect, midiRect);
if ( TrackInfo::HideTopItem( rect, midiRect ) )
return {};
if (pTrack->GetKind() == Track::Note &&
midiRect.Contains(event.m_x, event.m_y)) {
Instance().mpTrack = static_cast<NoteTrack*>(pTrack);
Instance().mRect = midiRect;
return {
HitTestPreview(),
&Instance()
};
}
else
return {};
}
UIHandle::Result NoteTrackClickHandle::Click
(const TrackPanelMouseEvent &, AudacityProject *)
{
return RefreshCode::RefreshNone;
}
UIHandle::Result NoteTrackClickHandle::Drag
(const TrackPanelMouseEvent &, AudacityProject *)
{
return RefreshCode::RefreshNone;
}
HitTestPreview NoteTrackClickHandle::Preview
(const TrackPanelMouseEvent &, const AudacityProject *)
{
// No special message or cursor
return {};
}
UIHandle::Result NoteTrackClickHandle::Release
(const TrackPanelMouseEvent &evt, AudacityProject *pProject, wxWindow *)
{
using namespace RefreshCode;
if (!mpTrack)
return RefreshNone;
const wxMouseEvent &event = evt.event;
if (mpTrack->LabelClick(mRect, event.m_x, event.m_y,
event.Button(wxMOUSE_BTN_RIGHT))) {
// No undo items needed??
pProject->ModifyState(false);
return RefreshAll;
}
return RefreshNone;
}
UIHandle::Result NoteTrackClickHandle::Cancel(AudacityProject *)
{
return RefreshCode::RefreshNone;
}
void NoteTrackClickHandle::OnProjectChange(AudacityProject *pProject)
{
if (! pProject->GetTracks()->Contains(mpTrack)) {
mpTrack = nullptr;
mRect = {};
}
UIHandle::OnProjectChange(pProject);
}
///////////////////////////////////////////////////////////////////////////////
NoteTrackControls::NoteTrackControls()
{
}
@ -44,7 +170,7 @@ HitTestResult NoteTrackControls::HitTest
{
const wxMouseEvent &event = evt.event;
const wxRect &rect = evt.rect;
if (event.Button(wxMOUSE_BTN_LEFT)) {
if (event.ButtonDown() || event.ButtonDClick()) {
if (mpTrack->GetKind() == Track::Note) {
auto track = GetTrack();
HitTestResult result;
@ -61,6 +187,9 @@ HitTestResult NoteTrackControls::HitTest
if (NULL != (result =
VelocitySliderHandle::HitTest(event, rect, pProject, mpTrack)).handle)
return result;
if (NULL != (result =
NoteTrackClickHandle::HitTest(event, rect, GetTrack())).handle)
return result;
#endif
}
}