Move the audio display mouse wheel handling to the audio box so that it can update the horizontal zoom scrollbar

Originally committed to SVN as r5785.
This commit is contained in:
Thomas Goyne 2011-10-25 20:28:30 +00:00
parent b4ace668de
commit 48070be3a3
4 changed files with 43 additions and 39 deletions

View File

@ -86,6 +86,7 @@ AudioBox::AudioBox(wxWindow *parent, agi::Context *context)
, HorizontalZoom(new wxSlider(panel, Audio_Horizontal_Zoom, 0, -50, 30, wxDefaultPosition, wxSize(-1, 20), wxSL_VERTICAL|wxSL_BOTH))
, VerticalZoom(new wxSlider(panel, Audio_Vertical_Zoom, 50, 0, 100, wxDefaultPosition, wxSize(-1, 20), wxSL_VERTICAL|wxSL_BOTH|wxSL_INVERSE))
, VolumeBar(new wxSlider(panel, Audio_Volume, 50, 0, 100, wxDefaultPosition, wxSize(-1, 20), wxSL_VERTICAL|wxSL_BOTH|wxSL_INVERSE))
, mouse_zoom_accum(0)
{
SetSashVisible(wxSASH_BOTTOM, true);
Bind(wxEVT_SASH_DRAGGED, &AudioBox::OnSashDrag, this);
@ -133,6 +134,8 @@ AudioBox::AudioBox(wxWindow *parent, agi::Context *context)
SetSizerAndFit(audioSashSizer);
SetMinSize(wxSize(-1, OPT_GET("Audio/Display Height")->GetInt()));
SetMinimumSizeY(panel->GetSize().GetHeight());
audioDisplay->Bind(wxEVT_MOUSEWHEEL, &AudioBox::OnMouseWheel, this);
}
AudioBox::~AudioBox() { }
@ -143,6 +146,34 @@ BEGIN_EVENT_TABLE(AudioBox,wxSashWindow)
EVT_COMMAND_SCROLL(Audio_Volume, AudioBox::OnVolume)
END_EVENT_TABLE();
void AudioBox::OnMouseWheel(wxMouseEvent &evt) {
if (!ForwardMouseWheelEvent(audioDisplay, evt))
return;
bool zoom = evt.CmdDown() != OPT_GET("Audio/Wheel Default to Zoom")->GetBool();
if (!zoom)
{
int amount = -evt.GetWheelRotation();
// If the user did a horizontal scroll the amount should be inverted
// for it to be natural.
if (evt.GetWheelAxis() == 1) amount = -amount;
// Reset any accumulated zoom
mouse_zoom_accum = 0;
audioDisplay->ScrollBy(amount);
}
else if (evt.GetWheelAxis() == 0)
{
mouse_zoom_accum += evt.GetWheelRotation();
int zoom_delta = mouse_zoom_accum / evt.GetWheelDelta();
mouse_zoom_accum %= evt.GetWheelDelta();
int new_zoom = audioDisplay->GetZoomLevel() + zoom_delta;
audioDisplay->SetZoomLevel(new_zoom);
HorizontalZoom->SetValue(-new_zoom);
}
}
void AudioBox::OnSashDrag(wxSashEvent &event) {
if (event.GetDragStatus() == wxSASH_STATUS_OUT_OF_RANGE)
return;

View File

@ -78,11 +78,15 @@ class AudioBox : public wxSashWindow {
/// DOCME
wxSlider *VolumeBar;
// Mouse wheel zoom accumulator
int mouse_zoom_accum;
void OnHorizontalZoom(wxScrollEvent &event);
void OnVerticalZoom(wxScrollEvent &event);
void OnVolume(wxScrollEvent &event);
void OnVerticalLink(agi::OptionValue const& opt);
void OnSashDrag(wxSashEvent &event);
void OnMouseWheel(wxMouseEvent &evt);
public:
AudioBox(wxWindow *parent, agi::Context *context);

View File

@ -532,6 +532,14 @@ AudioDisplay::AudioDisplay(wxWindow *parent, AudioController *controller, agi::C
SetMinClientSize(wxSize(-1, 70));
SetBackgroundStyle(wxBG_STYLE_PAINT);
SetThemeEnabled(false);
Bind(wxEVT_LEFT_DOWN, &AudioDisplay::OnMouseEvent, this);
Bind(wxEVT_MIDDLE_DOWN, &AudioDisplay::OnMouseEvent, this);
Bind(wxEVT_RIGHT_DOWN, &AudioDisplay::OnMouseEvent, this);
Bind(wxEVT_LEFT_UP, &AudioDisplay::OnMouseEvent, this);
Bind(wxEVT_MIDDLE_UP, &AudioDisplay::OnMouseEvent, this);
Bind(wxEVT_RIGHT_UP, &AudioDisplay::OnMouseEvent, this);
Bind(wxEVT_MOTION, &AudioDisplay::OnMouseEvent, this);
}
@ -751,7 +759,6 @@ void AudioDisplay::ReloadRenderingSettings()
BEGIN_EVENT_TABLE(AudioDisplay, wxWindow)
EVT_MOUSE_EVENTS(AudioDisplay::OnMouseEvent)
EVT_PAINT(AudioDisplay::OnPaint)
EVT_SIZE(AudioDisplay::OnSize)
EVT_SET_FOCUS(AudioDisplay::OnFocus)
@ -1000,41 +1007,6 @@ void AudioDisplay::RemoveTrackCursor()
void AudioDisplay::OnMouseEvent(wxMouseEvent& event)
{
// Check for mouse wheel scrolling
if (event.GetWheelRotation() != 0)
{
if (!ForwardMouseWheelEvent(this, event))
return;
bool zoom = event.CmdDown();
if (OPT_GET("Audio/Wheel Default to Zoom")->GetBool()) zoom = !zoom;
if (!zoom)
{
int amount = -event.GetWheelRotation();
// If the user did a horizontal scroll the amount should be inverted
// for it to be natural.
if (event.GetWheelAxis() == 1) amount = -amount;
// Reset any accumulated zoom
mouse_zoom_accum = 0;
ScrollBy(amount);
}
else if (event.GetWheelAxis() == 0)
{
mouse_zoom_accum += event.GetWheelRotation();
int zoom_delta = mouse_zoom_accum / event.GetWheelDelta();
mouse_zoom_accum %= event.GetWheelDelta();
SetZoomLevel(GetZoomLevel() + zoom_delta);
/// @todo This has to update the trackbar in the audio box... maybe move handling mouse zoom to
/// the audio box instead to avoid messing with friend classes?
}
// Scroll event processed
return;
}
// If we have focus, we get mouse move events on Mac even when the mouse is
// outside our client rectangle, we don't want those.
if (event.Moving() && !GetClientRect().Contains(event.GetPosition()))

View File

@ -149,9 +149,6 @@ private:
/// Zoom level given as a number, see SetZoomLevel for details
int zoom_level;
// Mouse wheel zoom accumulator
int mouse_zoom_accum;
/// Absolute pixel position of the tracking cursor (mouse or playback)
int track_cursor_pos;