Commit b72fdbd0 authored by Sebastien Barre's avatar Sebastien Barre

ENH: get rid of LastPos, use interactor's GetLastEventPosition instead, get...

ENH: get rid of LastPos, use interactor's GetLastEventPosition instead, get rid of duplicated internal state vars (CtrlKey, ShiftKey) and UpdateInternalState(): everything is already in the interactor
parent 8ee2ce80
......@@ -24,7 +24,7 @@
#include "vtkOldStyleCallbackCommand.h"
#include "vtkCallbackCommand.h"
vtkCxxRevisionMacro(vtkInteractorStyle, "1.63");
vtkCxxRevisionMacro(vtkInteractorStyle, "1.64");
//----------------------------------------------------------------------------
vtkInteractorStyle *vtkInteractorStyle::New()
......@@ -68,9 +68,6 @@ vtkInteractorStyle::vtkInteractorStyle()
this->State = VTKIS_NONE;
this->AnimState = VTKIS_ANIM_OFF;
this->CtrlKey = 0;
this->ShiftKey = 1;
this->HandleObservers = 1;
this->UseTimers = 1;
......@@ -579,17 +576,6 @@ void vtkInteractorStyle::HighlightActor2D(vtkActor2D *actor2D)
this->PickedActor2D = actor2D;
}
//----------------------------------------------------------------------------
void vtkInteractorStyle::UpdateInternalState(int ctrl,
int shift,
int x,
int y)
{
this->CtrlKey = ctrl;
this->ShiftKey = shift;
this->Interactor->SetEventPosition(x, y);
}
//----------------------------------------------------------------------------
// Implementation of motion state control methods
//----------------------------------------------------------------------------
......@@ -1386,8 +1372,6 @@ void vtkInteractorStyle::ProcessEvents(vtkObject* object,
break;
case vtkCommand::MouseMoveEvent:
self->UpdateInternalState(rwi->GetControlKey(), rwi->GetShiftKey(),
XY[0], XY[1]);
if (self->HandleObservers &&
self->HasObserver(vtkCommand::MouseMoveEvent))
{
......@@ -1401,8 +1385,6 @@ void vtkInteractorStyle::ProcessEvents(vtkObject* object,
break;
case vtkCommand::LeftButtonPressEvent:
self->UpdateInternalState(rwi->GetControlKey(), rwi->GetShiftKey(),
XY[0], XY[1]);
self->FindPokedCamera(XY[0], XY[1]);
if (self->HandleObservers &&
self->HasObserver(vtkCommand::LeftButtonPressEvent))
......@@ -1417,8 +1399,6 @@ void vtkInteractorStyle::ProcessEvents(vtkObject* object,
break;
case vtkCommand::LeftButtonReleaseEvent:
self->UpdateInternalState(rwi->GetControlKey(), rwi->GetShiftKey(),
XY[0], XY[1]);
if (self->HandleObservers &&
self->HasObserver(vtkCommand::LeftButtonReleaseEvent))
{
......@@ -1432,8 +1412,6 @@ void vtkInteractorStyle::ProcessEvents(vtkObject* object,
break;
case vtkCommand::MiddleButtonPressEvent:
self->UpdateInternalState(rwi->GetControlKey(), rwi->GetShiftKey(),
XY[0], XY[1]);
self->FindPokedCamera(XY[0], XY[1]);
if (self->HandleObservers &&
self->HasObserver(vtkCommand::MiddleButtonPressEvent))
......@@ -1448,8 +1426,6 @@ void vtkInteractorStyle::ProcessEvents(vtkObject* object,
break;
case vtkCommand::MiddleButtonReleaseEvent:
self->UpdateInternalState(rwi->GetControlKey(), rwi->GetShiftKey(),
XY[0], XY[1]);
if (self->HandleObservers &&
self->HasObserver(vtkCommand::MiddleButtonReleaseEvent))
{
......@@ -1463,8 +1439,6 @@ void vtkInteractorStyle::ProcessEvents(vtkObject* object,
break;
case vtkCommand::RightButtonPressEvent:
self->UpdateInternalState(rwi->GetControlKey(), rwi->GetShiftKey(),
XY[0], XY[1]);
self->FindPokedCamera(XY[0], XY[1]);
if (self->HandleObservers &&
self->HasObserver(vtkCommand::RightButtonPressEvent))
......@@ -1479,8 +1453,6 @@ void vtkInteractorStyle::ProcessEvents(vtkObject* object,
break;
case vtkCommand::RightButtonReleaseEvent:
self->UpdateInternalState(rwi->GetControlKey(), rwi->GetShiftKey(),
XY[0], XY[1]);
if (self->HandleObservers &&
self->HasObserver(vtkCommand::RightButtonReleaseEvent))
{
......@@ -1494,8 +1466,6 @@ void vtkInteractorStyle::ProcessEvents(vtkObject* object,
break;
case vtkCommand::KeyPressEvent:
self->CtrlKey = rwi->GetControlKey();
self->ShiftKey = rwi->GetShiftKey();
if (self->HandleObservers &&
self->HasObserver(vtkCommand::KeyPressEvent))
{
......@@ -1514,8 +1484,6 @@ void vtkInteractorStyle::ProcessEvents(vtkObject* object,
break;
case vtkCommand::KeyReleaseEvent:
self->CtrlKey = rwi->GetControlKey();
self->ShiftKey = rwi->GetShiftKey();
if (self->HandleObservers &&
self->HasObserver(vtkCommand::KeyReleaseEvent))
{
......@@ -1534,8 +1502,6 @@ void vtkInteractorStyle::ProcessEvents(vtkObject* object,
break;
case vtkCommand::CharEvent:
self->CtrlKey = rwi->GetControlKey();
self->ShiftKey = rwi->GetShiftKey();
if (self->HandleObservers &&
self->HasObserver(vtkCommand::CharEvent))
{
......
......@@ -238,8 +238,6 @@ protected:
int AutoAdjustCameraClippingRange;
void ResetCameraClippingRange();
virtual void UpdateInternalState(int ctrl, int shift, int x, int y);
// These methods for the different interactions in different modes
// are overridden in subclasses to perform the correct motion. Since
// they might be called from OnTimer, they do not have mouse coord parameters
......@@ -284,9 +282,6 @@ protected:
float DeltaAzimuth;
float DeltaElevation;
int CtrlKey;
int ShiftKey;
int State;
int AnimState;
......
......@@ -21,7 +21,7 @@
#include "vtkRenderWindowInteractor.h"
#include "vtkObjectFactory.h"
vtkCxxRevisionMacro(vtkInteractorStyleFlight, "1.19");
vtkCxxRevisionMacro(vtkInteractorStyleFlight, "1.20");
vtkStandardNewMacro(vtkInteractorStyleFlight);
//---------------------------------------------------------------------------
......@@ -380,10 +380,10 @@ void vtkInteractorStyleFlight::AzimuthScan(void)
//---------------------------------------------------------------------------
void vtkInteractorStyleFlight::UpdateMouseSteering(int x, int y)
{
double aspeed = this->AngleStepSize*(this->ShiftKey ? this->AngleAccelerationFactor : 1.0);
vtkRenderWindowInteractor *rwi = this->Interactor;
double aspeed = this->AngleStepSize*(rwi->GetShiftKey() ? this->AngleAccelerationFactor : 1.0);
//
// we want to steer by an amount proportional to window viewangle and size
vtkRenderWindowInteractor *rwi = this->Interactor;
int *size = rwi->GetSize();
double scalefactor = 5.0*this->CurrentCamera->GetViewAngle()/(double)size[0];
double dx = - (x - this->LastPos[0])*scalefactor;
......@@ -454,14 +454,14 @@ void vtkInteractorStyleFlight::FlyByMouse(void)
{
double a_vector[3];
double speed = this->DiagonalLength * this->MotionStepSize * this->MotionUserScale;
speed = speed * ( this->ShiftKey ? this->MotionAccelerationFactor : 1.0);
speed = speed * ( this->Interactor->GetShiftKey() ? this->MotionAccelerationFactor : 1.0);
if (this->DisableMotion)
{
speed = 0;
}
// Sidestep (convert steering angles to left right movement :
// only because I added this after doing the angles earlier
if (this->CtrlKey)
if (this->Interactor->GetControlKey())
{
if (this->YawAngle!=0.0)
{
......@@ -484,7 +484,7 @@ void vtkInteractorStyleFlight::FlyByMouse(void)
this->YawAngle = 0;
this->PitchAngle = 0;
//
if (!this->CtrlKey)
if (!this->Interactor->GetControlKey())
{
this->CurrentCamera->GetViewPlaneNormal(a_vector);
if (this->Flying)
......@@ -503,16 +503,16 @@ void vtkInteractorStyleFlight::FlyByKey(void)
{
double speed = this->DiagonalLength * this->MotionStepSize * this->MotionUserScale;
speed = speed * ( this->ShiftKey ? this->MotionAccelerationFactor : 1.0);
speed = speed * ( this->Interactor->GetShiftKey() ? this->MotionAccelerationFactor : 1.0);
if (this->DisableMotion)
{
speed = 0;
}
//
double aspeed = this->AngleStepSize* (this->ShiftKey ? this->AngleAccelerationFactor : 1.0);
double aspeed = this->AngleStepSize* (this->Interactor->GetShiftKey() ? this->AngleAccelerationFactor : 1.0);
double a_vector[3];
// Left and right
if (this->CtrlKey)
if (this->Interactor->GetControlKey())
{ // Sidestep
this->ComputeLRVector(a_vector);
if (this->KeysDown & 1)
......@@ -537,7 +537,7 @@ void vtkInteractorStyleFlight::FlyByKey(void)
}
// Up and Down
if (this->CtrlKey)
if (this->Interactor->GetControlKey())
{ // Sidestep
this->CurrentCamera->GetViewUp(a_vector);
if (this->KeysDown & 4)
......
......@@ -215,6 +215,8 @@ protected:
int LastPos[2];
int OldPos[2];
int ShiftKey;
int CtrlKey;
int Char;
char *KeySym;
int Button;
......
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