Commit c673ebe4 authored by Will Schroeder's avatar Will Schroeder
Browse files

ENH:Converted widget to use cursor mediator so that it plays well with other widgets

parent 4422bab5
......@@ -29,7 +29,7 @@
#include "vtkRenderWindowInteractor.h"
vtkStandardNewMacro(vtkOrientationMarkerWidget);
vtkCxxRevisionMacro(vtkOrientationMarkerWidget, "1.1");
vtkCxxRevisionMacro(vtkOrientationMarkerWidget, "1.2");
vtkCxxSetObjectMacro(vtkOrientationMarkerWidget, OrientationMarker, vtkProp);
......@@ -55,6 +55,7 @@ public:
vtkOrientationMarkerWidget *OrientationMarkerWidget;
};
//-------------------------------------------------------------------------
vtkOrientationMarkerWidget::vtkOrientationMarkerWidget()
{
this->StartEventObserverId = 0;
......@@ -102,6 +103,7 @@ vtkOrientationMarkerWidget::vtkOrientationMarkerWidget()
tcoord->Delete();
}
//-------------------------------------------------------------------------
vtkOrientationMarkerWidget::~vtkOrientationMarkerWidget()
{
this->Observer->Delete();
......@@ -111,6 +113,7 @@ vtkOrientationMarkerWidget::~vtkOrientationMarkerWidget()
this->Outline->Delete();
}
//-------------------------------------------------------------------------
void vtkOrientationMarkerWidget::SetEnabled(int enabling)
{
if (!this->Interactor)
......@@ -160,6 +163,7 @@ void vtkOrientationMarkerWidget::SetEnabled(int enabling)
if (this->Interactive)
{
vtkRenderWindowInteractor *i = this->Interactor;
this->ObserverMediator = this->Interactor->GetObserverMediator();
if ( this->EventCallbackCommand )
{
i->AddObserver( vtkCommand::MouseMoveEvent,
......@@ -215,6 +219,7 @@ void vtkOrientationMarkerWidget::SetEnabled(int enabling)
}
}
//-------------------------------------------------------------------------
void vtkOrientationMarkerWidget::ExecuteCameraUpdateEvent(vtkObject *vtkNotUsed(o),
unsigned long vtkNotUsed(event),
void *vtkNotUsed(calldata))
......@@ -239,6 +244,7 @@ void vtkOrientationMarkerWidget::ExecuteCameraUpdateEvent(vtkObject *vtkNotUsed(
this->UpdateOutline();
}
//-------------------------------------------------------------------------
int vtkOrientationMarkerWidget::ComputeStateBasedOnPosition(int X, int Y,
int *pos1, int *pos2)
{
......@@ -297,28 +303,30 @@ int vtkOrientationMarkerWidget::ComputeStateBasedOnPosition(int X, int Y,
return result;
}
//-------------------------------------------------------------------------
void vtkOrientationMarkerWidget::SetCursor(int state)
{
switch (state)
{
case vtkOrientationMarkerWidget::AdjustingP1:
this->Interactor->GetRenderWindow()->SetCurrentCursor( VTK_CURSOR_SIZESW );
this->RequestCursorShape( VTK_CURSOR_SIZESW );
break;
case vtkOrientationMarkerWidget::AdjustingP3:
this->Interactor->GetRenderWindow()->SetCurrentCursor( VTK_CURSOR_SIZENE );
this->RequestCursorShape( VTK_CURSOR_SIZENE );
break;
case vtkOrientationMarkerWidget::AdjustingP2:
this->Interactor->GetRenderWindow()->SetCurrentCursor( VTK_CURSOR_SIZESE );
this->RequestCursorShape( VTK_CURSOR_SIZESE );
break;
case vtkOrientationMarkerWidget::AdjustingP4:
this->Interactor->GetRenderWindow()->SetCurrentCursor( VTK_CURSOR_SIZENW );
this->RequestCursorShape( VTK_CURSOR_SIZENW );
break;
case vtkOrientationMarkerWidget::Moving:
this->Interactor->GetRenderWindow()->SetCurrentCursor( VTK_CURSOR_SIZEALL );
this->RequestCursorShape( VTK_CURSOR_SIZEALL );
break;
}
}
//-------------------------------------------------------------------------
void vtkOrientationMarkerWidget::ProcessEvents(vtkObject* vtkNotUsed(object),
unsigned long event,
void *clientdata,
......@@ -346,6 +354,7 @@ void vtkOrientationMarkerWidget::ProcessEvents(vtkObject* vtkNotUsed(object),
}
}
//-------------------------------------------------------------------------
void vtkOrientationMarkerWidget::OnLeftButtonDown()
{
// We're only here if we are enabled
......@@ -380,6 +389,7 @@ void vtkOrientationMarkerWidget::OnLeftButtonDown()
this->InvokeEvent( vtkCommand::StartInteractionEvent, NULL );
}
//-------------------------------------------------------------------------
void vtkOrientationMarkerWidget::OnLeftButtonUp()
{
if (this->State == vtkOrientationMarkerWidget::Outside)
......@@ -393,12 +403,13 @@ void vtkOrientationMarkerWidget::OnLeftButtonUp()
// stop adjusting
this->State = vtkOrientationMarkerWidget::Outside;
this->Interactor->GetRenderWindow()->SetCurrentCursor( VTK_CURSOR_DEFAULT );
this->RequestCursorShape( VTK_CURSOR_DEFAULT );
this->EndInteraction();
this->InvokeEvent( vtkCommand::EndInteractionEvent, NULL );
this->Interactor->Render();
}
//-------------------------------------------------------------------------
void vtkOrientationMarkerWidget::SquareRenderer()
{
int *size = this->Renderer->GetSize();
......@@ -442,6 +453,7 @@ void vtkOrientationMarkerWidget::SquareRenderer()
}
}
//-------------------------------------------------------------------------
void vtkOrientationMarkerWidget::UpdateOutline()
{
double vp[4];
......@@ -458,6 +470,7 @@ void vtkOrientationMarkerWidget::UpdateOutline()
points->SetPoint( 3, vp[0]+1, vp[3]-1, 0 );
}
//-------------------------------------------------------------------------
void vtkOrientationMarkerWidget::SetInteractive(int interact)
{
if (this->Interactor && this->Enabled)
......@@ -493,6 +506,7 @@ void vtkOrientationMarkerWidget::SetInteractive(int interact)
}
}
//-------------------------------------------------------------------------
void vtkOrientationMarkerWidget::OnMouseMove()
{
// compute some info we need for all cases
......@@ -531,7 +545,7 @@ void vtkOrientationMarkerWidget::OnMouseMove()
if (X < pos1[0] || X > pos2[0] || Y < pos1[1] || Y > pos2[1])
{
this->State = vtkOrientationMarkerWidget::Outside;
this->Interactor->GetRenderWindow()->SetCurrentCursor( VTK_CURSOR_DEFAULT );
this->RequestCursorShape( VTK_CURSOR_DEFAULT );
}
else
{
......@@ -575,6 +589,7 @@ void vtkOrientationMarkerWidget::OnMouseMove()
this->Interactor->Render();
}
//-------------------------------------------------------------------------
void vtkOrientationMarkerWidget::MoveWidget(int X, int Y)
{
int dx = X - this->StartPosition[0];
......@@ -625,6 +640,7 @@ void vtkOrientationMarkerWidget::MoveWidget(int X, int Y)
this->Renderer->SetViewport( newPos );
}
//-------------------------------------------------------------------------
void vtkOrientationMarkerWidget::ResizeTopLeft(int X, int Y)
{
int dx = X - this->StartPosition[0];
......@@ -663,6 +679,7 @@ void vtkOrientationMarkerWidget::ResizeTopLeft(int X, int Y)
this->Renderer->SetViewport( newPos );
}
//-------------------------------------------------------------------------
void vtkOrientationMarkerWidget::ResizeTopRight(int X, int Y)
{
int dx = X - this->StartPosition[0];
......@@ -701,6 +718,7 @@ void vtkOrientationMarkerWidget::ResizeTopRight(int X, int Y)
this->Renderer->SetViewport( newPos );
}
//-------------------------------------------------------------------------
void vtkOrientationMarkerWidget::ResizeBottomRight(int X, int Y)
{
int dx = X - this->StartPosition[0];
......@@ -739,6 +757,7 @@ void vtkOrientationMarkerWidget::ResizeBottomRight(int X, int Y)
this->Renderer->SetViewport( newPos );
}
//-------------------------------------------------------------------------
void vtkOrientationMarkerWidget::ResizeBottomLeft(int X, int Y)
{
int dx = X - this->StartPosition[0];
......@@ -777,6 +796,7 @@ void vtkOrientationMarkerWidget::ResizeBottomLeft(int X, int Y)
this->Renderer->SetViewport( newPos );
}
//-------------------------------------------------------------------------
void vtkOrientationMarkerWidget::SetOutlineColor(double r, double g, double b)
{
this->OutlineActor->GetProperty()->SetColor( r, g, b );
......@@ -786,22 +806,26 @@ void vtkOrientationMarkerWidget::SetOutlineColor(double r, double g, double b)
}
}
//-------------------------------------------------------------------------
double* vtkOrientationMarkerWidget::GetOutlineColor()
{
return this->OutlineActor->GetProperty()->GetColor();
}
//-------------------------------------------------------------------------
void vtkOrientationMarkerWidget::SetViewport(double minX, double minY,
double maxX, double maxY)
{
this->Renderer->SetViewport( minX, minY, maxX, maxY );
}
//-------------------------------------------------------------------------
double* vtkOrientationMarkerWidget::GetViewport()
{
return this->Renderer->GetViewport();
}
//-------------------------------------------------------------------------
void vtkOrientationMarkerWidget::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
......
......@@ -21,7 +21,7 @@
#include "vtkRenderWindowInteractor.h"
#include "vtkCoordinate.h"
vtkCxxRevisionMacro(vtkScalarBarWidget, "1.2");
vtkCxxRevisionMacro(vtkScalarBarWidget, "1.3");
vtkStandardNewMacro(vtkScalarBarWidget);
vtkCxxSetObjectMacro(vtkScalarBarWidget, ScalarBarActor, vtkScalarBarActor);
......@@ -324,7 +324,6 @@ void vtkScalarBarWidget::OnMouseMove()
}
// adjust the cursor based on our position
this->SetCursor(this->ComputeStateBasedOnPosition(X,Y,pos1,pos2));
"bad return\n";
return;
}
}
......
......@@ -21,10 +21,11 @@
#include "vtkRenderWindowInteractor.h"
#include "vtkCoordinate.h"
vtkCxxRevisionMacro(vtkXYPlotWidget, "1.1");
vtkCxxRevisionMacro(vtkXYPlotWidget, "1.2");
vtkStandardNewMacro(vtkXYPlotWidget);
vtkCxxSetObjectMacro(vtkXYPlotWidget, XYPlotActor, vtkXYPlotActor);
//-------------------------------------------------------------------------
vtkXYPlotWidget::vtkXYPlotWidget()
{
this->XYPlotActor = vtkXYPlotActor::New();
......@@ -33,6 +34,7 @@ vtkXYPlotWidget::vtkXYPlotWidget()
this->Priority = 0.55;
}
//-------------------------------------------------------------------------
vtkXYPlotWidget::~vtkXYPlotWidget()
{
if (this->XYPlotActor)
......@@ -41,6 +43,7 @@ vtkXYPlotWidget::~vtkXYPlotWidget()
}
}
//-------------------------------------------------------------------------
void vtkXYPlotWidget::SetEnabled(int enabling)
{
if ( ! this->Interactor )
......@@ -79,6 +82,8 @@ void vtkXYPlotWidget::SetEnabled(int enabling)
i->AddObserver(vtkCommand::LeftButtonReleaseEvent,
this->EventCallbackCommand, this->Priority);
this->ObserverMediator = i->GetObserverMediator();
// Add the xy plot
this->CurrentRenderer->AddViewProp(this->XYPlotActor);
this->InvokeEvent(vtkCommand::EnableEvent,NULL);
......@@ -104,6 +109,7 @@ void vtkXYPlotWidget::SetEnabled(int enabling)
this->Interactor->Render();
}
//-------------------------------------------------------------------------
void vtkXYPlotWidget::ProcessEvents(vtkObject* vtkNotUsed(object),
unsigned long event,
void* clientdata,
......@@ -126,7 +132,7 @@ void vtkXYPlotWidget::ProcessEvents(vtkObject* vtkNotUsed(object),
}
}
//-------------------------------------------------------------------------
int vtkXYPlotWidget::ComputeStateBasedOnPosition(int X, int Y,
int *pos1, int *pos2)
{
......@@ -195,37 +201,38 @@ int vtkXYPlotWidget::ComputeStateBasedOnPosition(int X, int Y,
return Result;
}
//-------------------------------------------------------------------------
void vtkXYPlotWidget::SetCursor(int cState)
{
switch (cState)
{
case vtkXYPlotWidget::AdjustingP1:
this->Interactor->GetRenderWindow()->SetCurrentCursor(VTK_CURSOR_SIZESW);
this->RequestCursorShape(VTK_CURSOR_SIZESW);
break;
case vtkXYPlotWidget::AdjustingP3:
this->Interactor->GetRenderWindow()->SetCurrentCursor(VTK_CURSOR_SIZENE);
this->RequestCursorShape(VTK_CURSOR_SIZENE);
break;
case vtkXYPlotWidget::AdjustingP2:
this->Interactor->GetRenderWindow()->SetCurrentCursor(VTK_CURSOR_SIZESE);
this->RequestCursorShape(VTK_CURSOR_SIZESE);
break;
case vtkXYPlotWidget::AdjustingP4:
this->Interactor->GetRenderWindow()->SetCurrentCursor(VTK_CURSOR_SIZENW);
this->RequestCursorShape(VTK_CURSOR_SIZENW);
break;
case vtkXYPlotWidget::AdjustingE1:
case vtkXYPlotWidget::AdjustingE3:
this->Interactor->GetRenderWindow()->SetCurrentCursor(VTK_CURSOR_SIZEWE);
this->RequestCursorShape(VTK_CURSOR_SIZEWE);
break;
case vtkXYPlotWidget::AdjustingE2:
case vtkXYPlotWidget::AdjustingE4:
this->Interactor->GetRenderWindow()->SetCurrentCursor(VTK_CURSOR_SIZENS);
this->RequestCursorShape(VTK_CURSOR_SIZENS);
break;
case vtkXYPlotWidget::Moving:
this->Interactor->GetRenderWindow()->SetCurrentCursor(VTK_CURSOR_SIZEALL);
this->RequestCursorShape(VTK_CURSOR_SIZEALL);
break;
}
}
//-------------------------------------------------------------------------
void vtkXYPlotWidget::OnLeftButtonDown()
{
// We're only here is we are enabled
......@@ -263,6 +270,7 @@ void vtkXYPlotWidget::OnLeftButtonDown()
this->InvokeEvent(vtkCommand::StartInteractionEvent,NULL);
}
//-------------------------------------------------------------------------
void vtkXYPlotWidget::OnMouseMove()
{
// compute some info we need for all cases
......@@ -300,7 +308,7 @@ void vtkXYPlotWidget::OnMouseMove()
Y < pos1[1] || Y > pos2[1])
{
this->State = vtkXYPlotWidget::Outside;
this->Interactor->GetRenderWindow()->SetCurrentCursor(VTK_CURSOR_DEFAULT);
this->RequestCursorShape(VTK_CURSOR_DEFAULT);
return;
}
// adjust the cursor based on our position
......@@ -423,6 +431,7 @@ void vtkXYPlotWidget::OnMouseMove()
this->Interactor->Render();
}
//-------------------------------------------------------------------------
void vtkXYPlotWidget::OnLeftButtonUp()
{
if (this->State == vtkXYPlotWidget::Outside)
......@@ -433,14 +442,13 @@ void vtkXYPlotWidget::OnLeftButtonUp()
// stop adjusting
this->State = vtkXYPlotWidget::Outside;
this->EventCallbackCommand->SetAbortFlag(1);
this->Interactor->GetRenderWindow()->SetCurrentCursor(VTK_CURSOR_DEFAULT);
this->RequestCursorShape(VTK_CURSOR_DEFAULT);
this->EndInteraction();
this->InvokeEvent(vtkCommand::EndInteractionEvent,NULL);
this->Interactor->Render();
}
//-------------------------------------------------------------------------
void vtkXYPlotWidget::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
......
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