Rearrange AudioDisplay::OnMouseEvent a bit to eliminate some duplicated code and separate the code which requires a timing controller from that which doesn't

Originally committed to SVN as r6179.
This commit is contained in:
Thomas Goyne 2011-12-28 21:26:54 +00:00
parent 6953a69cf8
commit 0e17edc561

View file

@ -1104,34 +1104,54 @@ void AudioDisplay::OnMouseEvent(wxMouseEvent& event)
wxPoint mousepos = event.GetPosition();
AudioDisplayInteractionObject *new_obj = 0;
// Check for scrollbar action
if (scrollbar->GetBounds().Contains(mousepos))
{
new_obj = scrollbar.get();
}
// Check for timeline action
else if (timeline->GetBounds().Contains(mousepos))
{
SetCursor(wxCursor(wxCURSOR_SIZEWE));
new_obj = timeline.get();
}
if (new_obj)
{
if (!controller->IsPlaying())
RemoveTrackCursor();
if (scrollbar->OnMouseEvent(event))
SetDraggedObject(scrollbar.get());
if (new_obj->OnMouseEvent(event))
SetDraggedObject(new_obj);
return;
}
// Check for timeline action
if (timeline->GetBounds().Contains(mousepos))
if (event.Leaving() && !controller->IsPlaying())
{
SetCursor(wxCursor(wxCURSOR_SIZEWE));
if (!controller->IsPlaying())
RemoveTrackCursor();
if (timeline->OnMouseEvent(event))
SetDraggedObject(timeline.get());
return;
}
if (event.MiddleIsDown())
{
context->videoController->JumpToTime(
controller->MillisecondsFromSamples(SamplesFromRelativeX(mousepos.x)),
agi::vfr::EXACT);
return;
}
if (event.Moving() && !controller->IsPlaying())
{
SetTrackCursor(scroll_left + mousepos.x, OPT_GET("Audio/Display/Draw/Cursor Time")->GetBool());
}
AudioTimingController *timing = controller->GetTimingController();
if (!timing) return;
int drag_sensitivity = pixel_samples*3; /// @todo Make this depend on configuration
// Not scrollbar, not timeline, no button action
if (event.Moving())
{
if (timing)
{
int64_t samplepos = SamplesFromRelativeX(mousepos.x);
@ -1141,49 +1161,21 @@ void AudioDisplay::OnMouseEvent(wxMouseEvent& event)
SetCursor(wxNullCursor);
}
if (!controller->IsPlaying())
SetTrackCursor(scroll_left + mousepos.x, OPT_GET("Audio/Display/Draw/Cursor Time")->GetBool());
}
if (event.Leaving() && !controller->IsPlaying())
{
RemoveTrackCursor();
}
if (event.LeftDown() && timing)
if (event.ButtonDown(wxMOUSE_BTN_LEFT | wxMOUSE_BTN_RIGHT))
{
int64_t samplepos = SamplesFromRelativeX(mousepos.x);
AudioMarker *marker = timing->OnLeftClick(samplepos, drag_sensitivity);
AudioMarker *marker = event.LeftDown() ?
timing->OnLeftClick(samplepos, drag_sensitivity) :
timing->OnRightClick(samplepos, drag_sensitivity);
if (marker)
{
RemoveTrackCursor();
audio_marker.reset(new AudioMarkerInteractionObject(marker, timing, this, controller, wxMOUSE_BTN_LEFT));
audio_marker.reset(new AudioMarkerInteractionObject(marker, timing, this, controller, (wxMouseButton)event.GetButton()));
SetDraggedObject(audio_marker.get());
return;
}
}
if (event.RightDown() && timing)
{
int64_t samplepos = SamplesFromRelativeX(mousepos.x);
AudioMarker *marker = timing->OnRightClick(samplepos, drag_sensitivity);
if (marker)
{
RemoveTrackCursor();
audio_marker.reset(new AudioMarkerInteractionObject(marker, timing, this, controller, wxMOUSE_BTN_RIGHT));
SetDraggedObject(audio_marker.get());
return;
}
}
if (event.MiddleIsDown())
{
context->videoController->JumpToTime(
controller->MillisecondsFromSamples(SamplesFromRelativeX(mousepos.x)),
agi::vfr::EXACT);
}
}
void AudioDisplay::OnKeyDown(wxKeyEvent& event)