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(); wxPoint mousepos = event.GetPosition();
AudioDisplayInteractionObject *new_obj = 0;
// Check for scrollbar action // Check for scrollbar action
if (scrollbar->GetBounds().Contains(mousepos)) 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()) if (!controller->IsPlaying())
RemoveTrackCursor(); RemoveTrackCursor();
if (scrollbar->OnMouseEvent(event)) if (new_obj->OnMouseEvent(event))
SetDraggedObject(scrollbar.get()); SetDraggedObject(new_obj);
return; return;
} }
// Check for timeline action if (event.Leaving() && !controller->IsPlaying())
if (timeline->GetBounds().Contains(mousepos))
{ {
SetCursor(wxCursor(wxCURSOR_SIZEWE));
if (!controller->IsPlaying())
RemoveTrackCursor(); RemoveTrackCursor();
if (timeline->OnMouseEvent(event))
SetDraggedObject(timeline.get());
return; 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(); AudioTimingController *timing = controller->GetTimingController();
if (!timing) return;
int drag_sensitivity = pixel_samples*3; /// @todo Make this depend on configuration int drag_sensitivity = pixel_samples*3; /// @todo Make this depend on configuration
// Not scrollbar, not timeline, no button action // Not scrollbar, not timeline, no button action
if (event.Moving()) if (event.Moving())
{
if (timing)
{ {
int64_t samplepos = SamplesFromRelativeX(mousepos.x); int64_t samplepos = SamplesFromRelativeX(mousepos.x);
@ -1141,49 +1161,21 @@ void AudioDisplay::OnMouseEvent(wxMouseEvent& event)
SetCursor(wxNullCursor); SetCursor(wxNullCursor);
} }
if (!controller->IsPlaying()) if (event.ButtonDown(wxMOUSE_BTN_LEFT | wxMOUSE_BTN_RIGHT))
SetTrackCursor(scroll_left + mousepos.x, OPT_GET("Audio/Display/Draw/Cursor Time")->GetBool());
}
if (event.Leaving() && !controller->IsPlaying())
{
RemoveTrackCursor();
}
if (event.LeftDown() && timing)
{ {
int64_t samplepos = SamplesFromRelativeX(mousepos.x); 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) if (marker)
{ {
RemoveTrackCursor(); 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()); SetDraggedObject(audio_marker.get());
return; 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) void AudioDisplay::OnKeyDown(wxKeyEvent& event)