Skip to content

Support wheel events in vtkInteractorStyleUser

This patch adds support for wheel events to vtkInteractorStyleUser.

Running the following minimal test case

#include <iostream>

#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkInteractorStyleUser.h>
#include <vtkCommand.h>
#include <vtkCallbackCommand.h>
#include <vtkSmartPointer.h>
 
static void onWheelForward(vtkObject *, long unsigned int, void *, void *) {
        std::cout << "mouse wheel forward" << std::endl;
}

static void onWheelBackward(vtkObject *, long unsigned int, void *, void *) {
        std::cout << "mouse wheel backward" << std::endl;
}

int main() {
    auto style = vtkSmartPointer<vtkInteractorStyleUser>::New();

    auto onWheelForwardCallback = vtkSmartPointer<vtkCallbackCommand>::New();
    onWheelForwardCallback->SetCallback(onWheelForward);
    style->AddObserver(vtkCommand::MouseWheelForwardEvent, onWheelForwardCallback);

    auto onWheelBackwardCallback = vtkSmartPointer<vtkCallbackCommand>::New();
    onWheelBackwardCallback->SetCallback(onWheelBackward);
    style->AddObserver(vtkCommand::MouseWheelBackwardEvent, onWheelBackwardCallback);

    auto renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
 
    auto interactor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
    interactor->SetRenderWindow(renderWindow);
    interactor->SetInteractorStyle(style);
 
    interactor->Start();
 
    return 0;
}

will print nothing without the patch when the mouse wheel is turned over the window, but will print "mouse wheel forward" and "mouse wheel backward" as expected when the patch is applied.

Merge request reports