diff --git a/aegisub/src/audio_box.cpp b/aegisub/src/audio_box.cpp index c314f3935..f706374e1 100644 --- a/aegisub/src/audio_box.cpp +++ b/aegisub/src/audio_box.cpp @@ -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; diff --git a/aegisub/src/audio_box.h b/aegisub/src/audio_box.h index ff91209fd..3f77418b3 100644 --- a/aegisub/src/audio_box.h +++ b/aegisub/src/audio_box.h @@ -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); diff --git a/aegisub/src/audio_display.cpp b/aegisub/src/audio_display.cpp index e7f1b9f17..0fb365f5c 100644 --- a/aegisub/src/audio_display.cpp +++ b/aegisub/src/audio_display.cpp @@ -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())) diff --git a/aegisub/src/audio_display.h b/aegisub/src/audio_display.h index 723a6add4..34afe0fd9 100644 --- a/aegisub/src/audio_display.h +++ b/aegisub/src/audio_display.h @@ -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;