From 1741ce93f638c5cd7c3f87b20fb782dbfccb25cf Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Tue, 25 Oct 2011 19:40:45 +0000 Subject: [PATCH] Factor out the mouse wheel forwarding code in the audio display to a function used by the audio display, video display and subtitles grid, and make it actually work Originally committed to SVN as r5781. --- aegisub/src/audio_display.cpp | 26 ++------------------------ aegisub/src/base_grid.cpp | 6 ++++-- aegisub/src/utils.cpp | 14 ++++++++++++++ aegisub/src/utils.h | 6 ++++++ aegisub/src/video_display.cpp | 7 +++++-- 5 files changed, 31 insertions(+), 28 deletions(-) diff --git a/aegisub/src/audio_display.cpp b/aegisub/src/audio_display.cpp index 7663a6fb2..84445573c 100644 --- a/aegisub/src/audio_display.cpp +++ b/aegisub/src/audio_display.cpp @@ -1003,30 +1003,8 @@ void AudioDisplay::OnMouseEvent(wxMouseEvent& event) // Check for mouse wheel scrolling if (event.GetWheelRotation() != 0) { - // First check if the cursor is inside or outside the display. - // If it's outside, we want to send the event to the control it's over instead. - /// @todo Factor this into a reusable function - { - wxWindow *targetwindow = wxFindWindowAtPoint(event.GetPosition()); - if (targetwindow && targetwindow != this) - { - wxWindow *parent = GetParent(); - while (parent && parent != targetwindow) - { - parent = parent->GetParent(); - } - - // Don't forward scroll wheel events to parents of this as the - // target is sometimes reported as a parent even when the mouse - // is over the audio display - if (!parent) - { - targetwindow->GetEventHandler()->ProcessEvent(event); - event.Skip(false); - return; - } - } - } + if (!ForwardMouseWheelEvent(this, event)) + return; bool zoom = event.CmdDown(); if (OPT_GET("Audio/Wheel Default to Zoom")->GetBool()) zoom = !zoom; diff --git a/aegisub/src/base_grid.cpp b/aegisub/src/base_grid.cpp index 9018c2032..165b77115 100644 --- a/aegisub/src/base_grid.cpp +++ b/aegisub/src/base_grid.cpp @@ -714,8 +714,10 @@ void BaseGrid::OnMouseEvent(wxMouseEvent &event) { // Mouse wheel if (event.GetWheelRotation() != 0) { - int step = 3 * event.GetWheelRotation() / event.GetWheelDelta(); - ScrollTo(yPos - step); + if (ForwardMouseWheelEvent(this, event)) { + int step = 3 * event.GetWheelRotation() / event.GetWheelDelta(); + ScrollTo(yPos - step); + } return; } diff --git a/aegisub/src/utils.cpp b/aegisub/src/utils.cpp index 206d6bb6e..2639634c3 100644 --- a/aegisub/src/utils.cpp +++ b/aegisub/src/utils.cpp @@ -448,4 +448,18 @@ void RestartAegisub() { #endif } +bool ForwardMouseWheelEvent(wxWindow *source, wxMouseEvent &evt) { + wxWindow *target = wxFindWindowAtPoint(wxGetMousePosition()); + if (!target || target == source) return true; + // If the mouse is over a parent of the source window just pretend it's + // over the source window, so that the mouse wheel works on borders and such + wxWindow *parent = source->GetParent(); + while (parent && parent != target) parent = parent->GetParent(); + if (parent == target) return true; + + // Otherwise send it to the new target + target->GetEventHandler()->ProcessEvent(evt); + evt.Skip(false); + return false; +} diff --git a/aegisub/src/utils.h b/aegisub/src/utils.h index 67e6b02bd..0b1b4e1f8 100644 --- a/aegisub/src/utils.h +++ b/aegisub/src/utils.h @@ -69,6 +69,12 @@ int AegiStringToFix(const wxString &str,size_t decimalPlaces,int start=0,int end wxIcon BitmapToIcon(wxBitmap bmp); void RestartAegisub(); +/// Forward a mouse wheel event to the window under the mouse if needed +/// @param source The initial target of the wheel event +/// @param evt The event +/// @return Should the calling code process the event? +bool ForwardMouseWheelEvent(wxWindow *source, wxMouseEvent &evt); + /// @brief Templated abs() function template T tabs(T x) { return x < 0 ? -x : x; } diff --git a/aegisub/src/video_display.cpp b/aegisub/src/video_display.cpp index b5c6bd463..3be8866b1 100644 --- a/aegisub/src/video_display.cpp +++ b/aegisub/src/video_display.cpp @@ -65,6 +65,7 @@ #include "ass_file.h" #include "main.h" #include "threaded_frame_source.h" +#include "utils.h" #include "video_out_gl.h" #include "video_box.h" #include "video_context.h" @@ -420,8 +421,10 @@ void VideoDisplay::OnMouseLeave(wxMouseEvent& event) { } void VideoDisplay::OnMouseWheel(wxMouseEvent& event) { - if (int wheel = event.GetWheelRotation()) - SetZoom (zoomValue + .125 * (wheel / event.GetWheelDelta())); + if (int wheel = event.GetWheelRotation()) { + if (ForwardMouseWheelEvent(this, event)) + SetZoom (zoomValue + .125 * (wheel / event.GetWheelDelta())); + } } void VideoDisplay::OnContextMenu(wxContextMenuEvent&) {