Commit 423daa89 authored by Sebastien Jourdain's avatar Sebastien Jourdain
Browse files

Add support for Scroll event on vtkWeb viewport

Change-Id: I47d91acfe012ffae9ac36780fd33ad93699ace06
parent fd0863d6
......@@ -244,16 +244,30 @@ bool vtkWebApplication::HandleInteractionEvent(
}
int *viewSize = view->GetSize();
int posX = std::floor(viewSize[0] * event->GetX() + 0.5);
int posY = std::floor(viewSize[1] * event->GetY() + 0.5);
int ctrlKey =
(event->GetModifiers() & vtkWebInteractionEvent::CTRL_KEY) != 0? 1: 0;
int shiftKey =
(event->GetModifiers() & vtkWebInteractionEvent::SHIFT_KEY) != 0? 1: 0;
iren->SetEventInformation(posX, posY, ctrlKey, shiftKey, event->GetKeyCode(), event->GetRepeatCount());
// Handle scroll action if any
if(event->GetScroll()) {
iren->SetEventInformation(0, 0, ctrlKey, shiftKey, event->GetKeyCode(), 0);
iren->MouseMoveEvent();
iren->RightButtonPressEvent();
iren->SetEventInformation(0, event->GetScroll()*10, ctrlKey, shiftKey, event->GetKeyCode(), 0);
iren->MouseMoveEvent();
iren->RightButtonReleaseEvent();
this->Internals->ImageCache[view].NeedsRender = true;
return true;
}
int *viewSize = view->GetSize();
int posX = std::floor(viewSize[0] * event->GetX() + 0.5);
int posY = std::floor(viewSize[1] * event->GetY() + 0.5);
iren->SetEventInformation(posX, posY, ctrlKey, shiftKey, event->GetKeyCode(), event->GetRepeatCount());
unsigned int prev_buttons = this->Internals->ButtonStates[view];
unsigned int changed_buttons = (event->GetButtons() ^ prev_buttons);
......
......@@ -24,7 +24,8 @@ vtkWebInteractionEvent::vtkWebInteractionEvent() :
KeyCode(0),
X(0.0),
Y(0.0),
RepeatCount(0)
RepeatCount(0),
Scroll(0.0)
{
}
......@@ -43,4 +44,5 @@ void vtkWebInteractionEvent::PrintSelf(ostream& os, vtkIndent indent)
os << indent << "X: " << this->X << endl;
os << indent << "Y: " << this->Y << endl;
os << indent << "RepeatCount: " << this->RepeatCount << endl;
os << indent << "Scroll: " << this->Scroll << endl;
}
......@@ -65,6 +65,8 @@ public:
vtkGetMacro(X, double);
vtkSetMacro(Y, double);
vtkGetMacro(Y, double);
vtkSetMacro(Scroll, double);
vtkGetMacro(Scroll, double);
// Handle double click
vtkSetMacro(RepeatCount, int);
......@@ -79,6 +81,7 @@ protected:
char KeyCode;
double X;
double Y;
double Scroll;
int RepeatCount;
private:
......
......@@ -106,7 +106,7 @@
/// throttled.
function eatMouseEvent(event) {
var force_event = (button_state.left !== event.buttonLeft || button_state.right !== event.buttonRight || button_state.middle !== event.buttonMiddle);
if (!force_event && !event.buttonLeft && !event.buttonRight && !event.buttonMiddle) {
if (!force_event && !event.buttonLeft && !event.buttonRight && !event.buttonMiddle && !event.scroll) {
return true;
}
if (!force_event && action_pending) {
......@@ -377,7 +377,7 @@
evt.preventDefault();
// Update quality based on the type of the event
if(evt.action === 'up' || evt.action === 'dblclick') {
if(evt.action === 'up' || evt.action === 'dblclick' || evt.action === 'scroll') {
quality = options.stillQuality;
} else {
quality = options.interactiveQuality;
......@@ -416,6 +416,7 @@
* - up
* - move
* - dblclick
* - scroll
*/
action: evt.action,
/**
......@@ -465,8 +466,13 @@
y : (evt.pageY - elem_position.top)
};
vtkWeb_event.x = pointer.x / renderer.width();
vtkWeb_event.y = 1.0 - (pointer.y / renderer.height());
if(evt.action === 'scroll') {
vtkWeb_event.scroll = evt.scroll;
} else {
vtkWeb_event.x = pointer.x / renderer.width();
vtkWeb_event.y = 1.0 - (pointer.y / renderer.height());
}
if (eatMouseEvent(vtkWeb_event)) {
return;
}
......
......@@ -137,13 +137,6 @@
action: 'move',
current_button: current_button
}));
} else if(event.type === 'click' && current_button != null) {
alert("Double click");
renderersContainer.trigger($.extend(event, {
type: 'mouse',
action: 'dblclick',
current_button: event.which
}));
}
}
}
......@@ -158,6 +151,15 @@
current_button: event.which
}));
});
mouseListenerContainer.bind("DOMMouseScroll mousewheel",function(event){
var scrollValue = (event.originalEvent.wheelDeltaY || -event.originalEvent.detail);
renderersContainer.trigger($.extend(event, {
type: 'mouse',
action: 'scroll',
current_button: current_button,
scroll: scrollValue
}));
});
}
// ----------------------------------------------------------------------
......
......@@ -104,10 +104,14 @@ class vtkWebMouseHandler(vtkWebProtocol):
pvevent = vtkWebInteractionEvent()
pvevent.SetButtons(buttons)
pvevent.SetModifiers(modifiers)
pvevent.SetX(event["x"])
pvevent.SetY(event["y"])
if event.has_key("x"):
pvevent.SetX(event["x"])
if event.has_key("y"):
pvevent.SetY(event["y"])
if event.has_key("scroll"):
pvevent.SetScroll(event["scroll"])
if event["action"] == 'dblclick':
pvevent.SetRepeatCount(2)
pvevent.SetRepeatCount(2)
#pvevent.SetKeyCode(event["charCode"])
retVal = self.getApplication().HandleInteractionEvent(view, pvevent)
del pvevent
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment