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.
This commit is contained in:
Thomas Goyne 2011-10-25 19:40:45 +00:00
parent be75262f73
commit 1741ce93f6
5 changed files with 31 additions and 28 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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 <typename T> T tabs(T x) { return x < 0 ? -x : x; }

View File

@ -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&) {