Updates will be applied April 15th at 12pm EDT (UTC-0400). GitLab could be a little slow between 12 - 12:45pm EDT.

Commit 8e970f44 authored by Sankhesh Jhaveri's avatar Sankhesh Jhaveri 💬

Fix button widget when used with multiple viewports

vtkTexturedButtonRepresentation2D is a composite representation that
uses vtkBalloonRepresentation internally. The representation would need
to compensate the active viewport origin when deciding whether the
button was clicked.
parent 782d7edf
......@@ -426,10 +426,21 @@ ComputeInteractionState(int X, int Y, int)
{
// Is it in the text region or the image region?
double x0[3], x2[3];
int origin[2] = {0, 0};
if (this->Renderer)
{
origin[0] = (this->Renderer->GetOrigin())[0];
origin[1] = (this->Renderer->GetOrigin())[1];
}
if ( this->ImageVisible )
{
this->TexturePoints->GetPoint(0,x0);
this->TexturePoints->GetPoint(2,x2);
for (int i = 0; i < 2; ++i)
{
x0[i] += origin[i];
x2[i] += origin[i];
}
if ( (x0[0] <= X && X <= x2[0]) && (x0[1] <= Y && Y <= x2[1]) )
{
return vtkBalloonRepresentation::OnImage;
......@@ -440,6 +451,11 @@ ComputeInteractionState(int X, int Y, int)
{
this->FramePoints->GetPoint(0,x0);
this->FramePoints->GetPoint(2,x2);
for (int i = 0; i < 2; ++i)
{
x0[i] += origin[i];
x2[i] += origin[i];
}
if ( (x0[0] <= X && X <= x2[0]) && (x0[1] <= Y && Y <= x2[1]) )
{
return vtkBalloonRepresentation::OnText;
......
......@@ -55,6 +55,29 @@ void vtkButtonWidget::CreateDefaultRepresentation()
}
}
//----------------------------------------------------------------------
void vtkButtonWidget::SetEnabled(int enabling)
{
if ( enabling ) //----------------
{
if (this->Interactor)
{
if (!this->CurrentRenderer)
{
int X=this->Interactor->GetEventPosition()[0];
int Y=this->Interactor->GetEventPosition()[1];
this->SetCurrentRenderer(this->Interactor->FindPokedRenderer(X,Y));
}
this->CreateDefaultRepresentation();
this->WidgetRep->SetRenderer(this->CurrentRenderer);
}
}
else
{
this->SetCurrentRenderer(nullptr);
}
Superclass::SetEnabled(enabling);
}
//----------------------------------------------------------------------------------
void vtkButtonWidget::MoveAction(vtkAbstractWidget *w)
......
......@@ -96,6 +96,15 @@ public:
*/
void CreateDefaultRepresentation() VTK_OVERRIDE;
/**
* The method for activating and deactivating this widget. This method
* must be overridden because it is a composite widget and does more than
* its superclasses' vtkAbstractWidget::SetEnabled() method. The
* method finds and sets the active viewport on the internal balloon
* representation.
*/
void SetEnabled(int) VTK_OVERRIDE;
protected:
vtkButtonWidget();
~vtkButtonWidget() VTK_OVERRIDE {}
......
......@@ -204,6 +204,7 @@ void vtkTexturedButtonRepresentation2D::PlaceWidget(double anchor[3], int size[2
int vtkTexturedButtonRepresentation2D
::ComputeInteractionState(int X, int Y, int vtkNotUsed(modify))
{
this->Balloon->SetRenderer(this->GetRenderer());
if ( this->Balloon->ComputeInteractionState(X,Y) == vtkBalloonRepresentation::OnImage )
{
this->InteractionState = vtkButtonRepresentation::Inside;
......
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